MCPcopy
hub / github.com/nashsu/llm_wiki / buildAnthropicBodyWithReasoning

Function buildAnthropicBodyWithReasoning

src/lib/llm-providers.ts:544–570  ·  view source on GitHub ↗
(
  config: LlmConfig,
  messages: ChatMessage[],
  overrides?: RequestOverrides,
)

Source from the content-addressed store, hash-verified

542}
543
544function buildAnthropicBodyWithReasoning(
545 config: LlmConfig,
546 messages: ChatMessage[],
547 overrides?: RequestOverrides,
548): Record<string, unknown> {
549 const body = buildAnthropicBody(messages, overrides)
550 const reasoning = effectiveReasoning(config, overrides)
551 if (reasoning.mode === "auto" || reasoning.mode === "off") return body
552
553 const budget =
554 reasoning.mode === "custom" && reasoning.budgetTokens !== undefined
555 ? reasoning.budgetTokens
556 : reasoning.mode === "low"
557 ? 1024
558 : reasoning.mode === "medium"
559 ? 4096
560 : 8192
561 const budgetTokens = Math.max(1024, budget)
562 if ((body.max_tokens as number) <= budgetTokens) {
563 body.max_tokens = budgetTokens + 1
564 }
565 body.thinking = { type: "enabled", budget_tokens: budgetTokens }
566 delete body.temperature
567 delete body.top_p
568 delete body.top_k
569 return body
570}
571
572function hasImageContent(messages: ChatMessage[]): boolean {
573 return messages.some((m) =>

Callers 1

getProviderConfigFunction · 0.85

Calls 2

buildAnthropicBodyFunction · 0.85
effectiveReasoningFunction · 0.85

Tested by

no test coverage detected