feat(llm): 统一思考模式配置,支持显式禁用状态
This commit is contained in:
@@ -46,7 +46,8 @@ struct SystemContent {
|
||||
struct ThinkingConfig {
|
||||
#[serde(rename = "type")]
|
||||
thinking_type: String,
|
||||
budget_tokens: u32,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
budget_tokens: Option<u32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
@@ -354,7 +355,10 @@ impl AnthropicClient {
|
||||
top_p: self.top_p,
|
||||
messages,
|
||||
system,
|
||||
thinking: None,
|
||||
thinking: Some(ThinkingConfig {
|
||||
thinking_type: "disabled".to_string(),
|
||||
budget_tokens: None,
|
||||
}),
|
||||
stream: false,
|
||||
};
|
||||
|
||||
@@ -409,7 +413,7 @@ impl AnthropicClient {
|
||||
|
||||
let thinking = ThinkingConfig {
|
||||
thinking_type: "enabled".to_string(),
|
||||
budget_tokens: self.thinking_budget_tokens,
|
||||
budget_tokens: Some(self.thinking_budget_tokens),
|
||||
};
|
||||
|
||||
// max_tokens must exceed budget_tokens
|
||||
@@ -596,13 +600,23 @@ mod tests {
|
||||
fn test_thinking_config_serialization() {
|
||||
let config = ThinkingConfig {
|
||||
thinking_type: "enabled".to_string(),
|
||||
budget_tokens: 2048,
|
||||
budget_tokens: Some(2048),
|
||||
};
|
||||
let json = serde_json::to_string(&config).unwrap();
|
||||
assert!(json.contains(r#""type":"enabled""#));
|
||||
assert!(json.contains(r#""budget_tokens":2048"#));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_thinking_config_disabled_serialization() {
|
||||
let config = ThinkingConfig {
|
||||
thinking_type: "disabled".to_string(),
|
||||
budget_tokens: None,
|
||||
};
|
||||
let json = serde_json::to_string(&config).unwrap();
|
||||
assert_eq!(json, r#"{"type":"disabled"}"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_system_content_serialization() {
|
||||
let content = SystemContent {
|
||||
|
||||
Reference in New Issue
Block a user