mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-09-05 10:19:15 +00:00
fix(openai): use max_completion_tokens and skip temperature for GPT-5/o-series models (#213)
GPT-5 and o-series models reject the legacy max_tokens parameter and require max_completion_tokens instead. Additionally, gpt-5-mini, gpt-5-nano, and o-series models only support the default temperature (1). This patch adds model-aware branching in buildRequestBody() to: - Send max_completion_tokens instead of max_tokens for gpt-5*/o1/o3/o4 - Skip temperature parameter for gpt-5-mini/gpt-5-nano/o-series Co-authored-by: Marcelo Emmerich <marcelo@agenticsystems.de>
This commit is contained in:
co-authored by
Marcelo Emmerich
parent
3cfe31523c
commit
e5f8a2a7da
@@ -313,10 +313,18 @@ func (p *OpenAIProvider) buildRequestBody(model string, req ChatRequest, stream
|
||||
|
||||
// Merge options
|
||||
if v, ok := req.Options[OptMaxTokens]; ok {
|
||||
body["max_tokens"] = v
|
||||
if strings.HasPrefix(model, "gpt-5") || strings.HasPrefix(model, "o1") || strings.HasPrefix(model, "o3") || strings.HasPrefix(model, "o4") {
|
||||
body["max_completion_tokens"] = v
|
||||
} else {
|
||||
body["max_tokens"] = v
|
||||
}
|
||||
}
|
||||
if v, ok := req.Options[OptTemperature]; ok {
|
||||
body["temperature"] = v
|
||||
// GPT-5 mini/nano and o-series models only support default temperature
|
||||
skipTemp := strings.HasPrefix(model, "gpt-5-mini") || strings.HasPrefix(model, "gpt-5-nano") || strings.HasPrefix(model, "o1") || strings.HasPrefix(model, "o3") || strings.HasPrefix(model, "o4")
|
||||
if !skipTemp {
|
||||
body["temperature"] = v
|
||||
}
|
||||
}
|
||||
|
||||
// Inject reasoning_effort for o-series models (ignored by models that don't support it)
|
||||
|
||||
Reference in New Issue
Block a user