From 3da4d91ec08be1ade9a9eab436182612aefe5a3b Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 8 Dec 2025 01:07:57 +0000 Subject: [PATCH] fix: add pnpm patch for pi-ai to support LiteLLM providerType MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- patches/@mariozechner__pi-ai.patch | 40 ++++++++++++++++++++++++++++++ pnpm-workspace.yaml | 3 +++ 2 files changed, 43 insertions(+) create mode 100644 patches/@mariozechner__pi-ai.patch diff --git a/patches/@mariozechner__pi-ai.patch b/patches/@mariozechner__pi-ai.patch new file mode 100644 index 000000000..2f69654bb --- /dev/null +++ b/patches/@mariozechner__pi-ai.patch @@ -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) { diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 3518716ae..9182f4149 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -2,3 +2,6 @@ onlyBuiltDependencies: - '@whiskeysockets/baileys' - esbuild - sharp + +patchedDependencies: + '@mariozechner/pi-ai': patches/@mariozechner__pi-ai.patch