Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix DeepSeek Reasoner tool-call handling and add reasoning_content support (#44301)
Peter König5dd8561b06c8
diff --git a/crates/deepseek/src/deepseek.rs b/crates/deepseek/src/deepseek.rsindex 64a1cbe5d96..e978aa08048 100644--- a/crates/deepseek/src/deepseek.rs+++ b/crates/deepseek/src/deepseek.rs@@ -155,6 +155,8 @@ pub enum RequestMessage {content: Option<String>,#[serde(default, skip_serializing_if = "Vec::is_empty")]tool_calls: Vec<ToolCall>,+ #[serde(default, skip_serializing_if = "Option::is_none")]+ reasoning_content: Option<String>,},User {content: String,diff --git a/crates/language_models/src/provider/deepseek.rs b/crates/language_models/src/provider/deepseek.rsindex 4bc7164f421..91b83bb9f1d 100644--- a/crates/language_models/src/provider/deepseek.rs+++ b/crates/language_models/src/provider/deepseek.rs@@ -332,9 +332,11 @@ pub fn into_deepseek(model: &deepseek::Model,max_output_tokens: Option<u64>,) -> deepseek::Request {- let is_reasoner = *model == deepseek::Model::Reasoner;+ let is_reasoner = model == &deepseek::Model::Reasoner;let mut messages = Vec::new();+ let mut current_reasoning: Option<String> = None;+for message in request.messages {for content in message.content {match content {@@ -343,10 +345,14 @@ pub fn into_deepseek(Role::Assistant => deepseek::RequestMessage::Assistant {content: Some(text),tool_calls: Vec::new(),+ reasoning_content: current_reasoning.take(),},Role::System => deepseek::RequestMessage::System { content: text },}),- MessageContent::Thinking { .. } => {}+ MessageContent::Thinking { text, .. } => {+ // Accumulate reasoning content for next assistant message+ current_reasoning.get_or_insert_default().push_str(&text);+ }MessageContent::RedactedThinking(_) => {}MessageContent::Image(_) => {}MessageContent::ToolUse(tool_use) => {@@ -369,6 +375,7 @@ pub fn into_deepseek(messages.push(deepseek::RequestMessage::Assistant {content: None,tool_calls: vec![tool_call],+ reasoning_content: current_reasoning.take(),});}}