WeKnora/internal/models/provider
wizardchen 9e08ab7302 fix(chat): map MaxTokens to MaxCompletionTokens for GPT-5/o-series
OpenAI's GPT-5 series and o-series reasoning models (o1/o3/o4-mini) no
longer accept `max_tokens` and reject non-default sampling params
(`temperature`, `top_p`, `frequency_penalty`, `presence_penalty`).
Azure OpenAI propagates the same constraint, returning HTTP 400 with
"this model is not supported MaxTokens, please use MaxCompletionTokens".

Lower the compatibility shim into `RemoteAPIChat.BuildChatCompletionRequest`
(the single OpenAI-protocol egress) so every internal caller keeps using
`MaxTokens` uniformly:

- Add `provider.IsOpenAIReasoningOrGPT5Model` with precise prefix matching
  (covers `gpt-5*`, `o1`/`o1-*`, `o3`/`o3-*`, `o4`/`o4-*`; rejects
  `olympus-1`, `openai-*`, `o3xtra`, etc.).
- When the provider is `openai`/`azure_openai` and the model matches, map
  `MaxTokens` to `MaxCompletionTokens` (explicit `MaxCompletionTokens`
  wins) and skip the unsupported sampling fields; `omitempty` keeps them
  off the wire.
- Behavior is unchanged for gpt-4o, gpt-4, and all other providers.

Add unit tests for the matcher and for the request-building path
(Azure gpt-5.2, OpenAI gpt-5/o1-mini/o3/o4-mini, plus negative cases).

Fixes #1283
2026-05-13 00:40:35 +08:00
..
aliyun.go feat(asr): add ASR model connection check and update related components 2026-04-02 21:27:27 +08:00
anthropic.go feat: support Anthropic chat provider 2026-05-12 17:33:16 +08:00
azure_openai.go feat: add Azure OpenAI provider registration with metadata 2026-04-09 19:19:25 +08:00
deepseek.go feat: 新增对多家平台的模型适配 2025-12-29 12:18:42 +08:00
gemini.go feat: 新增对多家平台的模型适配 2025-12-29 12:18:42 +08:00
generic.go feat(asr): integrate Automatic Speech Recognition (ASR) support 2026-04-02 21:27:27 +08:00
gpustack.go feat(asr): integrate Automatic Speech Recognition (ASR) support 2026-04-02 21:27:27 +08:00
hunyuan.go feat: 新增对多家平台的模型适配 2025-12-29 12:18:42 +08:00
jina.go feat: 新增对多家平台的模型适配 2025-12-29 12:18:42 +08:00
lkeap.go feat: add thinking mode support for agents 2026-01-20 18:19:44 +08:00
longcat.go feat:add several mainstream model providers 2026-01-09 11:08:57 +08:00
mimo.go feat:修改小米模型域名 2025-12-30 18:13:08 +08:00
minimax.go feat: upgrade MiniMax models from M2.1 to M2.7 2026-03-26 18:51:25 +08:00
modelscope.go feat:add several mainstream model providers 2026-01-09 11:08:57 +08:00
moonshot.go feat:add several mainstream model providers 2026-01-09 11:08:57 +08:00
novita.go feat: upgrade MiniMax models from M2.1 to M2.7 2026-03-26 18:51:25 +08:00
nvidia.go refactor: use unified NVIDIA API for both chat and VLM 2026-03-30 10:38:50 +08:00
openai.go fix(chat): map MaxTokens to MaxCompletionTokens for GPT-5/o-series 2026-05-13 00:40:35 +08:00
openai_test.go fix(chat): map MaxTokens to MaxCompletionTokens for GPT-5/o-series 2026-05-13 00:40:35 +08:00
openrouter.go fix: add OpenRouter embedding provider support 2026-03-20 15:50:42 +08:00
provider.go feat: support Anthropic chat provider 2026-05-12 17:33:16 +08:00
provider_test.go feat: support Anthropic chat provider 2026-05-12 17:33:16 +08:00
qianfan.go feat:add several mainstream model providers 2026-01-09 11:08:57 +08:00
qiniu.go feat:add several mainstream model providers 2026-01-09 11:08:57 +08:00
siliconflow.go feat(asr): integrate Automatic Speech Recognition (ASR) support 2026-04-02 21:27:27 +08:00
volcengine.go feat: 新增对多家平台的模型适配 2025-12-29 12:18:42 +08:00
weknoracloud.go feat(weknoracloud): implement credential management and status checks 2026-04-14 17:36:01 +08:00
zhipu.go fix(zhipu): correct Embedding BaseURL to match API structure 2026-01-25 16:53:49 +08:00