From 78728e61ed06b5e7b2fd623c61d13d1811200d6a Mon Sep 17 00:00:00 2001 From: Yige Date: Wed, 13 May 2026 18:54:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(i18n):=20GPT-5=20/=20o-series=20=E4=B8=8D?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A=E4=B9=89=20temperature=20(?= =?UTF-8?q?#11)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 接 PR #8 的进一步根因 本地用 personal PAT 端到端验证时发现:付费 quota 已生效、`gpt-5-mini` 可访问、`max_completion_tokens` 修复正确,但 translate.py 仍 400: ``` "message": "Unsupported value: 'temperature' does not support 0.1 with this model. Only the default (1) value is supported." "param": "temperature" "code": "unsupported_value" ``` GPT-5 系列和 o-series(o1 / o3 / o4)作为 reasoning models 强制 `temperature=1`,不允许自定义。 ## 改动 `call_github_models` 基于 model id 条件设置 `temperature`: - `gpt-5*` / `*o1*` / `*o3*` / `*o4*` → 不发该字段(用默认 1) - 其他 model(gpt-4 系列、Anthropic Claude)→ 保持 `temperature=0.1`(翻译任务偏好 deterministic) ## 验证 本地实际跑通:`GITHUB_TOKEN=$(gh auth token) uv run --quiet scripts/i18n/translate.py skills/markdown` ``` skills/markdown → en-US: - calling github/openai/gpt-5-mini for en-US translation ... - wrote root SKILL.md with translated body (3838 chars) ``` gpt-5-mini 返回 HTTP 200,3838 字符英文 body 正确写入,Markdown 结构保留。 --- scripts/i18n/translate.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/i18n/translate.py b/scripts/i18n/translate.py index a5837af..c2f8fd9 100755 --- a/scripts/i18n/translate.py +++ b/scripts/i18n/translate.py @@ -191,15 +191,22 @@ def call_github_models(system_prompt: str, user_payload: str, model: str, endpoi # GPT-5 series rejects the legacy `max_tokens` field and requires # `max_completion_tokens` instead (OpenAI Chat Completions 2024+ contract). # GPT-4 and earlier accept either, so always use the new name. - payload = { + payload: dict[str, Any] = { "model": model, "messages": [ {"role": "system", "content": system_prompt}, {"role": "user", "content": user_payload}, ], - "temperature": 0.1, "max_completion_tokens": 8192, } + # GPT-5 / o-series only allow the default temperature (1); sending any other + # value returns 400 `unsupported_value`. Older models accept custom values, + # where 0.1 is preferred for deterministic translation output. + is_gpt5_or_o_series = any( + tag in model.lower() for tag in ("gpt-5", "/o1", "/o3", "/o4") + ) + if not is_gpt5_or_o_series: + payload["temperature"] = 0.1 headers = { "Authorization": f"Bearer {token}", "Content-Type": "application/json",