fix(deepseek): preserve reasoning_content in history for R1
DeepSeek R1 (deepseek-reasoner) requires that assistant messages in the history containing tool_calls must also include their reasoning_content field.
This commit is contained in:
@@ -60,6 +60,11 @@ pub async fn messages_to_openai_json(messages: &[UnifiedMessage]) -> Result<Vec<
|
||||
|
||||
let mut msg = serde_json::json!({ "role": m.role });
|
||||
|
||||
// Include reasoning_content if present (DeepSeek R1/reasoner requires this in history)
|
||||
if let Some(reasoning) = &m.reasoning_content {
|
||||
msg["reasoning_content"] = serde_json::json!(reasoning);
|
||||
}
|
||||
|
||||
// For assistant messages with tool_calls, content can be null
|
||||
if let Some(tool_calls) = &m.tool_calls {
|
||||
if parts.is_empty() {
|
||||
@@ -133,6 +138,11 @@ pub async fn messages_to_openai_json_text_only(
|
||||
|
||||
let mut msg = serde_json::json!({ "role": m.role });
|
||||
|
||||
// Include reasoning_content if present (DeepSeek R1/reasoner requires this in history)
|
||||
if let Some(reasoning) = &m.reasoning_content {
|
||||
msg["reasoning_content"] = serde_json::json!(reasoning);
|
||||
}
|
||||
|
||||
// For assistant messages with tool_calls, content can be null
|
||||
if let Some(tool_calls) = &m.tool_calls {
|
||||
if parts.is_empty() {
|
||||
|
||||
Reference in New Issue
Block a user