From e24499841347ba617ee07aeb811500ef9336f0eb Mon Sep 17 00:00:00 2001 From: Ankur Goyal Date: Tue, 3 Jun 2025 23:39:56 -0400 Subject: [PATCH 1/3] block out tool choice --- packages/proxy/src/proxy.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/proxy/src/proxy.ts b/packages/proxy/src/proxy.ts index bc0aba3d..2df95dbe 100644 --- a/packages/proxy/src/proxy.ts +++ b/packages/proxy/src/proxy.ts @@ -2206,7 +2206,25 @@ async function fetchAnthropicChatCompletions({ input_schema: parsed.data.json_schema.schema, }, ]; - params.tool_choice = { type: "tool", name: "json" }; + + const thinkingParamsParsed = z + .object({ + thinking: z.object({ + type: z.literal("enabled"), + }), + }) + .safeParse(params); + + // Claude hack: if thinking is enabled, tool_choice cannot be specified. So + // we just omit tool_choice in that case. + if ( + thinkingParamsParsed.success && + thinkingParamsParsed.data.thinking.type === "enabled" + ) { + delete params.tool_choice; + } else { + params.tool_choice = { type: "tool", name: "json" }; + } } if (secret.type === "bedrock") { From 98c887d7ccbb1ec3dad2a4caa4d8356b885d9a9e Mon Sep 17 00:00:00 2001 From: edenh Date: Tue, 10 Jun 2025 08:48:49 -0700 Subject: [PATCH 2/3] provider error message --- packages/proxy/src/proxy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/proxy/src/proxy.ts b/packages/proxy/src/proxy.ts index 2df95dbe..98ecf06d 100644 --- a/packages/proxy/src/proxy.ts +++ b/packages/proxy/src/proxy.ts @@ -1139,7 +1139,7 @@ async function fetchModelLoop( headersString.push(`${key}: ${value}`); }); const errorText = - `AI provider returned ${httpCode} error.\n\nHeaders:\n` + + `The AI provider returned ${httpCode} error. This is likely not a problem with Braintrust, but rather with the model provider. Please check the model provider's status page or adjust max concurrency.\n\nHeaders:\n` + headersString.join("\n"); proxyResponse = { response: new Response(null, { status: httpCode }), From 0ab312405e5e76850a88cb79e70f0b876c6d8c78 Mon Sep 17 00:00:00 2001 From: edenh Date: Tue, 10 Jun 2025 09:01:37 -0700 Subject: [PATCH 3/3] tweak --- packages/proxy/src/proxy.ts | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/packages/proxy/src/proxy.ts b/packages/proxy/src/proxy.ts index 98ecf06d..05db0420 100644 --- a/packages/proxy/src/proxy.ts +++ b/packages/proxy/src/proxy.ts @@ -1139,7 +1139,7 @@ async function fetchModelLoop( headersString.push(`${key}: ${value}`); }); const errorText = - `The AI provider returned ${httpCode} error. This is likely not a problem with Braintrust, but rather with the model provider. Please check the model provider's status page or adjust max concurrency.\n\nHeaders:\n` + + `The AI provider returned ${httpCode} error. This is likely not an issue with Braintrust, but rather with the model provider.${httpCode === 500 ? " Please check the model provider's status page." : httpCode === 429 ? " Please adjust max concurrency." : ""}\n\nHeaders:\n` + headersString.join("\n"); proxyResponse = { response: new Response(null, { status: httpCode }), @@ -2206,25 +2206,7 @@ async function fetchAnthropicChatCompletions({ input_schema: parsed.data.json_schema.schema, }, ]; - - const thinkingParamsParsed = z - .object({ - thinking: z.object({ - type: z.literal("enabled"), - }), - }) - .safeParse(params); - - // Claude hack: if thinking is enabled, tool_choice cannot be specified. So - // we just omit tool_choice in that case. - if ( - thinkingParamsParsed.success && - thinkingParamsParsed.data.thinking.type === "enabled" - ) { - delete params.tool_choice; - } else { - params.tool_choice = { type: "tool", name: "json" }; - } + params.tool_choice = { type: "tool", name: "json" }; } if (secret.type === "bedrock") {