fix: add pnpm patch for pi-ai to support LiteLLM providerType
When using Claude models via LiteLLM proxy, the bundled pi-ai sends OpenAI-specific parameters (store, max_completion_tokens) that cause errors with non-OpenAI backends like AWS Bedrock. This patch adds providerType support to openai-completions.js: - Check model.providerType to determine if model is OpenAI-native - Only send OpenAI-specific params to actual OpenAI models - Use max_tokens instead of max_completion_tokens for proxy models Users can now configure custom models in ~/.pi/agent/models.json with providerType: "anthropic" (or "google", etc.) to properly route requests through LiteLLM to Claude and other non-OpenAI models. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
2112fa919a
commit
3da4d91ec0
40
patches/@mariozechner__pi-ai.patch
Normal file
40
patches/@mariozechner__pi-ai.patch
Normal file
@ -0,0 +1,40 @@
|
||||
diff --git a/dist/providers/openai-completions.js b/dist/providers/openai-completions.js
|
||||
index a430c2240a37bcc7d05fb8e551c18964e7636c59..869eb60f0724c31b08aba2e2ee37da63d82696b2 100644
|
||||
--- a/dist/providers/openai-completions.js
|
||||
+++ b/dist/providers/openai-completions.js
|
||||
@@ -231,20 +231,26 @@ function buildParams(model, context, options) {
|
||||
stream: true,
|
||||
stream_options: { include_usage: true },
|
||||
};
|
||||
- // Cerebras/xAI/Mistral dont like the "store" field
|
||||
- if (!model.baseUrl.includes("cerebras.ai") &&
|
||||
- !model.baseUrl.includes("api.x.ai") &&
|
||||
- !model.baseUrl.includes("mistral.ai") &&
|
||||
- !model.baseUrl.includes("chutes.ai")) {
|
||||
+ // Only send OpenAI-specific params (like "store") to actual OpenAI models.
|
||||
+ // For custom models via proxies like LiteLLM, check providerType.
|
||||
+ // Fall back to baseUrl detection for known providers.
|
||||
+ const isOpenAIModel = model.providerType === "openai" ||
|
||||
+ (!model.providerType &&
|
||||
+ !model.baseUrl.includes("cerebras.ai") &&
|
||||
+ !model.baseUrl.includes("api.x.ai") &&
|
||||
+ !model.baseUrl.includes("mistral.ai") &&
|
||||
+ !model.baseUrl.includes("chutes.ai") &&
|
||||
+ (model.baseUrl.includes("api.openai.com") || model.provider === "openai"));
|
||||
+ if (isOpenAIModel) {
|
||||
params.store = false;
|
||||
}
|
||||
if (options?.maxTokens) {
|
||||
- // Mistral/Chutes uses max_tokens instead of max_completion_tokens
|
||||
- if (model.baseUrl.includes("mistral.ai") || model.baseUrl.includes("chutes.ai")) {
|
||||
- params.max_tokens = options?.maxTokens;
|
||||
+ // Only OpenAI uses max_completion_tokens. Others (Mistral/Chutes/Anthropic via proxy) use max_tokens
|
||||
+ if (isOpenAIModel) {
|
||||
+ params.max_completion_tokens = options?.maxTokens;
|
||||
}
|
||||
else {
|
||||
- params.max_completion_tokens = options?.maxTokens;
|
||||
+ params.max_tokens = options?.maxTokens;
|
||||
}
|
||||
}
|
||||
if (options?.temperature !== undefined) {
|
||||
@ -2,3 +2,6 @@ onlyBuiltDependencies:
|
||||
- '@whiskeysockets/baileys'
|
||||
- esbuild
|
||||
- sharp
|
||||
|
||||
patchedDependencies:
|
||||
'@mariozechner/pi-ai': patches/@mariozechner__pi-ai.patch
|
||||
|
||||
Loading…
Reference in New Issue
Block a user