feat: set default reasoning effort to low for all AI requests
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
"provider": "compatible",
|
"provider": "compatible",
|
||||||
"endpoint": "https://codex.slcydia.fun/v1/responses",
|
"endpoint": "https://codex.slcydia.fun/v1/responses",
|
||||||
"model": "gemini-3.7-flash-high",
|
"model": "gemini-3.7-flash-high",
|
||||||
|
"reasoningEffort": "low",
|
||||||
"apiKey": "***REMOVED***",
|
"apiKey": "***REMOVED***",
|
||||||
"description": "默认 AI 对话服务配置。provider 可选: compatible (OpenAI 兼容/CLIProxyAPI/OneAPI), openAi, gemini, mock"
|
"description": "默认 AI 对话服务配置。provider 可选: compatible (OpenAI 兼容/CLIProxyAPI/OneAPI), openAi, gemini, mock"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ class AiConfigFile {
|
|||||||
required this.provider,
|
required this.provider,
|
||||||
required this.endpoint,
|
required this.endpoint,
|
||||||
required this.model,
|
required this.model,
|
||||||
|
this.reasoningEffort = 'low',
|
||||||
this.apiKey,
|
this.apiKey,
|
||||||
this.description,
|
this.description,
|
||||||
});
|
});
|
||||||
@@ -14,6 +15,7 @@ class AiConfigFile {
|
|||||||
final AiProviderType provider;
|
final AiProviderType provider;
|
||||||
final String endpoint;
|
final String endpoint;
|
||||||
final String model;
|
final String model;
|
||||||
|
final String reasoningEffort;
|
||||||
final String? apiKey;
|
final String? apiKey;
|
||||||
final String? description;
|
final String? description;
|
||||||
|
|
||||||
@@ -25,10 +27,15 @@ class AiConfigFile {
|
|||||||
(p) => p.name.toLowerCase() == providerStr.toLowerCase(),
|
(p) => p.name.toLowerCase() == providerStr.toLowerCase(),
|
||||||
orElse: () => AiProviderType.compatible,
|
orElse: () => AiProviderType.compatible,
|
||||||
);
|
);
|
||||||
|
final effort = (json['reasoningEffort'] as String? ??
|
||||||
|
json['reasoning_effort'] as String? ??
|
||||||
|
'low')
|
||||||
|
.trim();
|
||||||
return AiConfigFile(
|
return AiConfigFile(
|
||||||
provider: provider,
|
provider: provider,
|
||||||
endpoint: (json['endpoint'] as String? ?? '').trim(),
|
endpoint: (json['endpoint'] as String? ?? '').trim(),
|
||||||
model: (json['model'] as String? ?? '').trim(),
|
model: (json['model'] as String? ?? '').trim(),
|
||||||
|
reasoningEffort: effort.isEmpty ? 'low' : effort,
|
||||||
apiKey: json['apiKey'] as String?,
|
apiKey: json['apiKey'] as String?,
|
||||||
description: json['description'] as String?,
|
description: json['description'] as String?,
|
||||||
);
|
);
|
||||||
@@ -43,6 +50,7 @@ class AiConfigFile {
|
|||||||
'provider': provider.name,
|
'provider': provider.name,
|
||||||
'endpoint': endpoint,
|
'endpoint': endpoint,
|
||||||
'model': model,
|
'model': model,
|
||||||
|
'reasoningEffort': reasoningEffort,
|
||||||
if (apiKey != null) 'apiKey': apiKey,
|
if (apiKey != null) 'apiKey': apiKey,
|
||||||
if (description != null) 'description': description,
|
if (description != null) 'description': description,
|
||||||
};
|
};
|
||||||
@@ -62,12 +70,14 @@ class AiConfigFile {
|
|||||||
AiProviderType? provider,
|
AiProviderType? provider,
|
||||||
String? endpoint,
|
String? endpoint,
|
||||||
String? model,
|
String? model,
|
||||||
|
String? reasoningEffort,
|
||||||
String? apiKey,
|
String? apiKey,
|
||||||
String? description,
|
String? description,
|
||||||
}) => AiConfigFile(
|
}) => AiConfigFile(
|
||||||
provider: provider ?? this.provider,
|
provider: provider ?? this.provider,
|
||||||
endpoint: endpoint ?? this.endpoint,
|
endpoint: endpoint ?? this.endpoint,
|
||||||
model: model ?? this.model,
|
model: model ?? this.model,
|
||||||
|
reasoningEffort: reasoningEffort ?? this.reasoningEffort,
|
||||||
apiKey: apiKey ?? this.apiKey,
|
apiKey: apiKey ?? this.apiKey,
|
||||||
description: description ?? this.description,
|
description: description ?? this.description,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -157,7 +157,12 @@ class AiService {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
'generationConfig': {
|
||||||
|
'thinkingConfig': {
|
||||||
|
'thinkingBudget': 1024,
|
||||||
|
},
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
).timeout(const Duration(seconds: 25));
|
).timeout(const Duration(seconds: 25));
|
||||||
if (response.statusCode < 200 || response.statusCode >= 300) return null;
|
if (response.statusCode < 200 || response.statusCode >= 300) return null;
|
||||||
@@ -189,6 +194,7 @@ class AiService {
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
'reasoning_effort': 'low',
|
||||||
'temperature': 0.1,
|
'temperature': 0.1,
|
||||||
}),
|
}),
|
||||||
).timeout(const Duration(seconds: 25));
|
).timeout(const Duration(seconds: 25));
|
||||||
@@ -212,12 +218,15 @@ class AiService {
|
|||||||
required List<Map<String, String>> messages,
|
required List<Map<String, String>> messages,
|
||||||
double? temperature,
|
double? temperature,
|
||||||
int? maxTokens,
|
int? maxTokens,
|
||||||
|
String reasoningEffort = 'low',
|
||||||
}) {
|
}) {
|
||||||
final isResponses = uri.path.endsWith('/responses');
|
final isResponses = uri.path.endsWith('/responses');
|
||||||
if (isResponses) {
|
if (isResponses) {
|
||||||
return {
|
return {
|
||||||
'model': model,
|
'model': model,
|
||||||
'input': messages,
|
'input': messages,
|
||||||
|
'reasoning': {'effort': reasoningEffort},
|
||||||
|
'reasoning_effort': reasoningEffort,
|
||||||
if (temperature != null) 'temperature': temperature,
|
if (temperature != null) 'temperature': temperature,
|
||||||
if (maxTokens != null) 'max_output_tokens': maxTokens,
|
if (maxTokens != null) 'max_output_tokens': maxTokens,
|
||||||
};
|
};
|
||||||
@@ -225,11 +234,28 @@ class AiService {
|
|||||||
return {
|
return {
|
||||||
'model': model,
|
'model': model,
|
||||||
'messages': messages,
|
'messages': messages,
|
||||||
|
'reasoning_effort': reasoningEffort,
|
||||||
if (temperature != null) 'temperature': temperature,
|
if (temperature != null) 'temperature': temperature,
|
||||||
if (maxTokens != null) 'max_tokens': maxTokens,
|
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.
|
/// Returns a display-only Chinese gloss for an unknown word or phrase.
|
||||||
/// This is deliberately not a LexiconEntry and cannot affect review/mastery.
|
/// This is deliberately not a LexiconEntry and cannot affect review/mastery.
|
||||||
Future<String?> temporaryDefinition({
|
Future<String?> temporaryDefinition({
|
||||||
@@ -278,10 +304,10 @@ class AiService {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'generationConfig': {
|
'generationConfig': _buildGeminiGenerationConfig(
|
||||||
'maxOutputTokens': 200,
|
maxOutputTokens: 200,
|
||||||
'responseMimeType': 'application/json',
|
responseMimeType: 'application/json',
|
||||||
},
|
),
|
||||||
}
|
}
|
||||||
: _buildOpenAiPayload(
|
: _buildOpenAiPayload(
|
||||||
uri: uri,
|
uri: uri,
|
||||||
@@ -365,11 +391,11 @@ class AiService {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'generationConfig': {
|
'generationConfig': _buildGeminiGenerationConfig(
|
||||||
'temperature': 0,
|
temperature: 0,
|
||||||
'maxOutputTokens': 200,
|
maxOutputTokens: 200,
|
||||||
'responseMimeType': 'application/json',
|
responseMimeType: 'application/json',
|
||||||
},
|
),
|
||||||
}
|
}
|
||||||
: _buildOpenAiPayload(
|
: _buildOpenAiPayload(
|
||||||
uri: uri,
|
uri: uri,
|
||||||
@@ -483,11 +509,11 @@ class AiService {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
'generationConfig': {
|
'generationConfig': _buildGeminiGenerationConfig(
|
||||||
'temperature': 0.3,
|
temperature: 0.3,
|
||||||
'maxOutputTokens': 300,
|
maxOutputTokens: 300,
|
||||||
'responseMimeType': 'application/json',
|
responseMimeType: 'application/json',
|
||||||
},
|
),
|
||||||
}
|
}
|
||||||
: _buildOpenAiPayload(
|
: _buildOpenAiPayload(
|
||||||
uri: uri,
|
uri: uri,
|
||||||
@@ -559,11 +585,11 @@ class AiService {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'generationConfig': {
|
'generationConfig': _buildGeminiGenerationConfig(
|
||||||
'temperature': 0.2,
|
temperature: 0.2,
|
||||||
'maxOutputTokens': 300,
|
maxOutputTokens: 300,
|
||||||
'responseMimeType': 'application/json',
|
responseMimeType: 'application/json',
|
||||||
},
|
),
|
||||||
}
|
}
|
||||||
: _buildOpenAiPayload(
|
: _buildOpenAiPayload(
|
||||||
uri: uri,
|
uri: uri,
|
||||||
@@ -652,11 +678,11 @@ Learner wrote: $answer''';
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'generationConfig': {
|
'generationConfig': _buildGeminiGenerationConfig(
|
||||||
'temperature': 0,
|
temperature: 0,
|
||||||
'maxOutputTokens': 300,
|
maxOutputTokens: 300,
|
||||||
'responseMimeType': 'application/json',
|
responseMimeType: 'application/json',
|
||||||
},
|
),
|
||||||
}
|
}
|
||||||
: _buildOpenAiPayload(
|
: _buildOpenAiPayload(
|
||||||
uri: uri,
|
uri: uri,
|
||||||
@@ -730,11 +756,11 @@ Learner wrote: $answer''';
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'generationConfig': {
|
'generationConfig': _buildGeminiGenerationConfig(
|
||||||
'temperature': 0.1,
|
temperature: 0.1,
|
||||||
'maxOutputTokens': 850,
|
maxOutputTokens: 850,
|
||||||
'responseMimeType': 'application/json',
|
responseMimeType: 'application/json',
|
||||||
},
|
),
|
||||||
}
|
}
|
||||||
: _buildOpenAiPayload(
|
: _buildOpenAiPayload(
|
||||||
uri: uri,
|
uri: uri,
|
||||||
@@ -838,11 +864,11 @@ Learner wrote: $answer''';
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'generationConfig': {
|
'generationConfig': _buildGeminiGenerationConfig(
|
||||||
'temperature': 0,
|
temperature: 0,
|
||||||
'maxOutputTokens': 200,
|
maxOutputTokens: 200,
|
||||||
'responseMimeType': 'application/json',
|
responseMimeType: 'application/json',
|
||||||
},
|
),
|
||||||
}
|
}
|
||||||
: _buildOpenAiPayload(
|
: _buildOpenAiPayload(
|
||||||
uri: uri,
|
uri: uri,
|
||||||
|
|||||||
Reference in New Issue
Block a user