Skip to content

feat(gateway): llm.disableThinking — inject thinking={type:disabled} into chat-completions bodies - #899

Open
francialisomlimoeiro wants to merge 1 commit into
TencentCloud:feat/serverfrom
francialisomlimoeiro:pr/llm-disable-thinking
Open

feat(gateway): llm.disableThinking — inject thinking={type:disabled} into chat-completions bodies#899
francialisomlimoeiro wants to merge 1 commit into
TencentCloud:feat/serverfrom
francialisomlimoeiro:pr/llm-disable-thinking

Conversation

@francialisomlimoeiro

Copy link
Copy Markdown

What it does

Some reasoning models served via OpenAI-compatible endpoints spend the entire max_tokens budget on reasoning tokens unless thinking is explicitly disabled; the gateway's structured (JSON) extraction then gets truncated to nothing. @ai-sdk/openai does not forward providerOptions into the OpenAI-compatible request body (AI SDK v6), so injection happens at fetch level.

  • src/adapters/standalone/llm-runner.ts: opt-in disableThinking → fetch wrapper injects thinking: {type:"disabled"} into every JSON body carrying a messages array; non-chat/non-JSON bodies pass through.
  • src/gateway/config.ts: yaml llm.disableThinking / env TDAI_LLM_DISABLE_THINKING.
  • src/gateway/server.ts: same injection on the gateway offload LLM path.

Tests

New src/adapters/standalone/thinking-disabled-fetch.test.ts (4 tests). vitest run3 files, 19 passed (incl. repo's existing suites). esbuild transpile check clean.

…into chat-completions bodies

Some reasoning models served via OpenAI-compatible endpoints spend the
entire max_tokens budget on reasoning tokens unless thinking is
explicitly disabled; the gateway's structured (JSON) extraction then
gets truncated to nothing.

Add an opt-in disableThinking flag:

- standalone adapter (llm-runner): when set, chat-completions requests
  go through a fetch wrapper that injects thinking={type:disabled} into
  every JSON body carrying a messages array. This is needed because
  @ai-sdk/openai does not forward providerOptions into the
  OpenAI-compatible request body.
- gateway config: yaml llm.disableThinking / env TDAI_LLM_DISABLE_THINKING.
- gateway offload LLM path: same injection for consistency.

Config:
  llm:
    disableThinking: true

Adds src/adapters/standalone/thinking-disabled-fetch.test.ts (4 tests:
chat-body injection, non-chat and non-JSON bodies pass through, bodyless
requests untouched).
@Maxwell-Code07

Copy link
Copy Markdown
Collaborator

Thanks for your contribution and attention! We will review this PR and get back to you as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants