feat: 调用 DeepSeek 时关闭思考模式

DeepSeek 默认开启思考,思考 token 按输出计费,且可能耗尽较小的
max_tokens 导致 JSON 截断。对 deepseek.com 地址:chat/completions
发送 thinking.type=disabled,Responses 发送 reasoning.effort=none;
其他服务商请求体保持不变。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-09-17 14:32:25 +09:00
co-authored by Claude Opus 5
parent d72959df70
commit 202bb64ece
2 changed files with 90 additions and 0 deletions
+26
View File
@@ -221,6 +221,11 @@ class AiService {
static bool _isHttpUri(Uri uri) => uri.scheme == 'https' || uri.scheme == 'http';
static bool _isDeepSeek(Uri uri) {
final host = uri.host.toLowerCase();
return host == 'deepseek.com' || host.endsWith('.deepseek.com');
}
static bool _isSuccess(http.Response response) =>
response.statusCode >= 200 && response.statusCode < 300;
@@ -373,6 +378,27 @@ class AiService {
String reasoningEffort = 'low',
}) {
final isResponses = uri.path.endsWith('/responses');
// DeepSeek thinks by default. Every request here is a short JSON answer
// with a small token cap, so reasoning only adds cost and can exhaust the
// cap before the JSON is written. Other providers may reject these
// DeepSeek-specific switches, so they keep the original payload.
if (_isDeepSeek(uri)) {
return isResponses
? {
'model': model,
'input': messages,
'reasoning': {'effort': 'none'},
'temperature': ?temperature,
'max_output_tokens': ?maxTokens,
}
: {
'model': model,
'messages': messages,
'thinking': {'type': 'disabled'},
'temperature': ?temperature,
'max_tokens': ?maxTokens,
};
}
if (isResponses) {
return {
'model': model,