NagaAgent icon indicating copy to clipboard operation
NagaAgent copied to clipboard

[Bug]GPT-5 走 NagaModel 网关或自定义 API 时,每次对话都报 temperature 错误

Open swf1996120 opened this issue 1 month ago • 1 comments

在测试 agent 框架的 LLM provider 集成时发现:自动化工具先标记候选问题,每个问题都先复现后再提交。复现于 c2caa90,LiteLLM 1.80.5(uv.lock 锁定的版本)。

登录后在设置里把模型选成 GPT-5(网关默认开启),或者用自定义 API 地址配 gpt-5,保持默认的 temperature 0.7,发任何消息都只会收到这一句:

流式调用出错: litellm.UnsupportedParamsError: gpt-5 models (including gpt-5-codex) don't support temperature=0.7. Only temperature=1 is supported. To drop unsupported params set `litellm.drop_params = True`

这个错误是 LiteLLM 在本地抛的,请求没有发出去,所以和网关本身无关。

复现:

import asyncio
from apiserver import naga_auth
from apiserver.llm_service import LLMService
from system.config import get_config

cfg = get_config()
cfg.api.model, cfg.api.use_gateway, cfg.api.api_key = "gpt-5", True, "fake-key"
naga_auth._access_token = "any-token"  # 相当于已登录

async def main():
    svc = LLMService()
    print(svc._get_model_name(), svc._normalize_temperature(svc._get_model_name(), 0.7))
    async for chunk in svc.stream_chat_with_context([{"role": "user", "content": "你好"}], cfg.api.temperature):
        print(chunk)

asyncio.run(main())

第一行输出 openai/gpt-5 0.7,temperature 没有被改成 1,后面就是上面的报错。预期是和 provider 选 OpenAI 时一样,自动调整成 1 后正常请求。

原因在 _normalize_temperature:它用 startswith("gpt-5") 判断,但传进来的是 _get_model_name() 的结果。网关和自定义地址都会加 openai/ 前缀,所以匹配不上。#312 修这个错误时覆盖的是不带前缀的情况。

同一张约束表还缺了别的固定 temperature 的模型:

  • o3、o4-mini 等 o 系列不带前缀也一样在本地报错。
  • Claude Opus 4.7、4.8 和 5 系列用 api_format: anthropic 时,0.7 会原样发出去,Anthropic 文档写明这些模型的非默认 temperature 每次请求都返回 400。
  • kimi-k2.6 及之后的模型走自定义地址时也是 0.7 原样发出去,Kimi 文档写明 temperature 固定,其他值报错。

后两条是用本地假接口看到请求内容后对照文档得出的,没有调用真实接口。

修复思路:匹配前先去掉路由前缀,(model_name or "").lower().rsplit("/", 1)[-1],表里补上 o 系列;Claude 和 Kimi 这些模型让 _normalize_temperature 返回 None,不发送 temperature。临时绕过可以在 config.json 里把 api.temperature 改成 1,但设置页没有这一项,而且会影响所有模型。

swf1996120 avatar Oct 30 '26 23:10 swf1996120

修复了喵

69gg avatar Nov 01 '26 09:11 69gg