feat: implement support for thinking blocks in Gemini API and enable thinking by default for supported models

This commit is contained in:
CJACK
2026-05-03 01:00:06 +08:00
parent a901250de7
commit 7c0bc9ec0f
10 changed files with 177 additions and 33 deletions

4
API.md
View File

@@ -561,7 +561,7 @@ data: {"type":"message_stop"}
**说明**
- 默认模型会按各 surface 的既有规则输出 thinking / reasoning 相关增量
- 默认支持 thinking 的模型会输出 `thinking` block / `thinking_delta`;请求显式关闭 thinking 或使用 `-nothinking` 模型时不会输出
-`-nothinking` 后缀的模型会强制关闭 thinking即使请求显式传了 `thinking` / `reasoning` / `reasoning_effort` 也不会输出 `thinking_delta`
- 不会输出 `signature_delta`(上游 DeepSeek 未提供可验证签名)
- `tools` 场景优先避免泄露原始工具 JSON不强制发送 `input_json_delta`
@@ -608,6 +608,7 @@ data: {"type":"message_stop"}
响应为 Gemini 兼容结构,核心字段包括:
- `candidates[].content.parts[].text`
- `candidates[].content.parts[].thought=true`thinking 输出)
- `candidates[].content.parts[].functionCall`(工具调用时)
- `usageMetadata``promptTokenCount` / `candidatesTokenCount` / `totalTokenCount`
@@ -616,6 +617,7 @@ data: {"type":"message_stop"}
返回 SSE`text/event-stream`),每个 chunk 为一条 `data: <json>`
- 常规文本:持续返回增量文本 chunk
- thinking持续返回 `parts[].thought=true` 的增量 chunk
- `tools` 场景:会缓冲并在结束时输出 `functionCall` 结构
- 结束 chunk包含 `finishReason: "STOP"``usageMetadata`
- token 计数优先透传上游 DeepSeek SSE`accumulated_token_usage` / `token_usage`);仅在上游缺失时回退本地估算