Repository navigation
fix(ai): retry OpenAI requests without unsupported max_tokens/temperature - #114
Conversation
…ture OpenAI's newer models (for example gpt-5.4-mini and gpt-6.2-sol) reject `max_tokens` with a 400 `unsupported_parameter` error and ask for `max_completion_tokens`; some of them also reject a non-default `temperature` with `unsupported_value`. The OpenAI-compatible provider always sends both, so every AI chat with these models failed. The first request is still sent exactly as before, so other OpenAI-compatible providers see no change. When the response is a 400 whose error names `max_tokens` with code `unsupported_parameter`, the request is resent with `max_completion_tokens`; when it names `temperature` with `unsupported_value` or `unsupported_parameter`, it is resent without `temperature`. Each adjustment happens at most once (max three attempts) and any other error is returned unchanged. Both `chat_once` and `chat_stream` share the new request path; streaming never retries after the response starts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Problem
With the official OpenAI API and newer models such as
gpt-5.4-miniorgpt-6.2-sol, every AI chat fails:OpenAICompatProvideralways sendsmax_tokensandtemperature(0.1). These models requiremax_completion_tokens, and some of them (e.g.gpt-6.2-sol) also reject any non-default temperature:Fix
The provider now adapts to the error instead of keeping a list of model names (which would go stale with every release):
param: "max_tokens"withcode: "unsupported_parameter", the request is resent with the same value asmax_completion_tokens.param: "temperature"withcode: "unsupported_value"or"unsupported_parameter", the request is resent withouttemperature.max_tokenssuch ascontext_length_exceeded, is returned unchanged after a single request, in the sameAI provider returned {status}: {body}format.chat_onceandchat_streamnow share one request path. Streaming only retries on the error status, before any stream data is read.Matching on
error.param+error.coderather than the base URL means OpenAI-compatible proxies that forward OpenAI's errors (LiteLLM, OpenRouter, Azure, etc.) also benefit.Only
src-tauri/src/ai/openai_compat.rschanges; no new dependencies.Testing
max_completion_tokensand no-temperature variants), for the error classifier (using the two real OpenAI error bodies above, plus negative cases), and loopback HTTP tests forchat_onceandchat_stream:max_tokens→temperature→ success, the same parameter rejected twice, and an unrelated 400 producing exactly one request. Each loopback test has a timeout so a regression cannot hang the suite.cargo test(26 passed),cargo check --all-targetsandcargo fmt --checkwere run for theaimodule in an isolated crate with the same dependencies. I could not build the full Tauri crate locally (no GTK/WebKit dev libraries), so the fullcargo check/cargo test --librelies on CI here.gpt-5.4-minirejectsmax_tokensonly;gpt-6.2-solrejectsmax_tokensand thentemperature: 0.1. Withmax_completion_tokens: 2048and no temperature, both return normal answers, streaming and non-streaming.🤖 Generated with Claude Code
Summary by CodeRabbit