feat: set default reasoning effort to low for all AI requests

This commit is contained in:
shen
2026-09-15 22:06:52 +08:00
parent 35b493e652
commit 82b1ecdf84
3 changed files with 72 additions and 35 deletions
+61 -35
View File
@@ -157,7 +157,12 @@ class AiService {
}
]
}
]
],
'generationConfig': {
'thinkingConfig': {
'thinkingBudget': 1024,
},
},
}),
).timeout(const Duration(seconds: 25));
if (response.statusCode < 200 || response.statusCode >= 300) return null;
@@ -189,6 +194,7 @@ class AiService {
],
}
],
'reasoning_effort': 'low',
'temperature': 0.1,
}),
).timeout(const Duration(seconds: 25));
@@ -212,12 +218,15 @@ class AiService {
required List<Map<String, String>> messages,
double? temperature,
int? maxTokens,
String reasoningEffort = 'low',
}) {
final isResponses = uri.path.endsWith('/responses');
if (isResponses) {
return {
'model': model,
'input': messages,
'reasoning': {'effort': reasoningEffort},
'reasoning_effort': reasoningEffort,
if (temperature != null) 'temperature': temperature,
if (maxTokens != null) 'max_output_tokens': maxTokens,
};
@@ -225,11 +234,28 @@ class AiService {
return {
'model': model,
'messages': messages,
'reasoning_effort': reasoningEffort,
if (temperature != null) 'temperature': temperature,
if (maxTokens != null) 'max_tokens': maxTokens,
};
}
static Map<String, dynamic> _buildGeminiGenerationConfig({
double? temperature,
int? maxOutputTokens,
String? responseMimeType,
int thinkingBudget = 1024,
}) {
return {
if (temperature != null) 'temperature': temperature,
if (maxOutputTokens != null) 'maxOutputTokens': maxOutputTokens,
if (responseMimeType != null) 'responseMimeType': responseMimeType,
'thinkingConfig': {
'thinkingBudget': thinkingBudget,
},
};
}
/// Returns a display-only Chinese gloss for an unknown word or phrase.
/// This is deliberately not a LexiconEntry and cannot affect review/mastery.
Future<String?> temporaryDefinition({
@@ -278,10 +304,10 @@ class AiService {
],
},
],
'generationConfig': {
'maxOutputTokens': 200,
'responseMimeType': 'application/json',
},
'generationConfig': _buildGeminiGenerationConfig(
maxOutputTokens: 200,
responseMimeType: 'application/json',
),
}
: _buildOpenAiPayload(
uri: uri,
@@ -365,11 +391,11 @@ class AiService {
],
},
],
'generationConfig': {
'temperature': 0,
'maxOutputTokens': 200,
'responseMimeType': 'application/json',
},
'generationConfig': _buildGeminiGenerationConfig(
temperature: 0,
maxOutputTokens: 200,
responseMimeType: 'application/json',
),
}
: _buildOpenAiPayload(
uri: uri,
@@ -483,11 +509,11 @@ class AiService {
},
)
.toList(),
'generationConfig': {
'temperature': 0.3,
'maxOutputTokens': 300,
'responseMimeType': 'application/json',
},
'generationConfig': _buildGeminiGenerationConfig(
temperature: 0.3,
maxOutputTokens: 300,
responseMimeType: 'application/json',
),
}
: _buildOpenAiPayload(
uri: uri,
@@ -559,11 +585,11 @@ class AiService {
],
},
],
'generationConfig': {
'temperature': 0.2,
'maxOutputTokens': 300,
'responseMimeType': 'application/json',
},
'generationConfig': _buildGeminiGenerationConfig(
temperature: 0.2,
maxOutputTokens: 300,
responseMimeType: 'application/json',
),
}
: _buildOpenAiPayload(
uri: uri,
@@ -652,11 +678,11 @@ Learner wrote: $answer''';
],
},
],
'generationConfig': {
'temperature': 0,
'maxOutputTokens': 300,
'responseMimeType': 'application/json',
},
'generationConfig': _buildGeminiGenerationConfig(
temperature: 0,
maxOutputTokens: 300,
responseMimeType: 'application/json',
),
}
: _buildOpenAiPayload(
uri: uri,
@@ -730,11 +756,11 @@ Learner wrote: $answer''';
],
},
],
'generationConfig': {
'temperature': 0.1,
'maxOutputTokens': 850,
'responseMimeType': 'application/json',
},
'generationConfig': _buildGeminiGenerationConfig(
temperature: 0.1,
maxOutputTokens: 850,
responseMimeType: 'application/json',
),
}
: _buildOpenAiPayload(
uri: uri,
@@ -838,11 +864,11 @@ Learner wrote: $answer''';
],
},
],
'generationConfig': {
'temperature': 0,
'maxOutputTokens': 200,
'responseMimeType': 'application/json',
},
'generationConfig': _buildGeminiGenerationConfig(
temperature: 0,
maxOutputTokens: 200,
responseMimeType: 'application/json',
),
}
: _buildOpenAiPayload(
uri: uri,