fix(i18n): GPT-5 / o-series 不支持自定义 temperature (#11)

## 接 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 结构保留。
This commit is contained in:
2026-05-13 18:54:42 +08:00
committed by GitHub
parent 94652d293c
commit 78728e61ed

View File

@@ -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",