Skip to content

Commit cbe12eb

Browse files
committed
feat: enhance thinking budget calculation and rename variables for clarity
1 parent 7f8187b commit cbe12eb

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/routes/messages/non-stream-translation.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ function getThinkingBudget(
6565
(model.capabilities.limits.max_output_tokens ?? 0) - 1,
6666
)
6767
if (maxThinkingBudget > 0 && thinking.budget_tokens !== undefined) {
68-
return Math.min(thinking.budget_tokens, maxThinkingBudget)
68+
const budgetTokens = Math.min(thinking.budget_tokens, maxThinkingBudget)
69+
return Math.max(
70+
budgetTokens,
71+
model.capabilities.supports.min_thinking_budget ?? 1024,
72+
)
6973
}
7074
}
7175
return undefined
@@ -322,13 +326,13 @@ export function translateToAnthropic(
322326
// Process all choices to extract text and tool use blocks
323327
for (const choice of response.choices) {
324328
const textBlocks = getAnthropicTextBlocks(choice.message.content)
325-
const thingBlocks = getAnthropicThinkBlocks(
329+
const thinkBlocks = getAnthropicThinkBlocks(
326330
choice.message.reasoning_text,
327331
choice.message.reasoning_opaque,
328332
)
329333
const toolUseBlocks = getAnthropicToolUseBlocks(choice.message.tool_calls)
330334

331-
assistantContentBlocks.push(...thingBlocks, ...textBlocks, ...toolUseBlocks)
335+
assistantContentBlocks.push(...thinkBlocks, ...textBlocks, ...toolUseBlocks)
332336

333337
// Use the finish_reason from the first choice, or prioritize tool_calls
334338
if (choice.finish_reason === "tool_calls" || stopReason === "stop") {

0 commit comments

Comments
 (0)