fix(deepseek): sanitize requests for deepseek-reasoner

deepseek-reasoner (R1) does not support tools, temperature, or top_p.
These fields are now stripped to avoid 400 Bad Request errors.
This commit is contained in:
2026-03-05 17:59:31 +00:00
parent 6440e8cc13
commit 7efb36029c

View File

@@ -57,7 +57,17 @@ impl super::Provider for DeepSeekProvider {
async fn chat_completion(&self, request: UnifiedRequest) -> Result<ProviderResponse, AppError> {
let messages_json = helpers::messages_to_openai_json(&request.messages).await?;
let body = helpers::build_openai_body(&request, messages_json, false);
let mut body = helpers::build_openai_body(&request, messages_json, false);
// Sanitize for deepseek-reasoner
if request.model == "deepseek-reasoner" {
if let Some(obj) = body.as_object_mut() {
obj.remove("tools");
obj.remove("tool_choice");
obj.remove("temperature");
obj.remove("top_p");
}
}
let response = self
.client
@@ -114,7 +124,23 @@ impl super::Provider for DeepSeekProvider {
// DeepSeek doesn't support images in streaming, use text-only
let messages_json = helpers::messages_to_openai_json_text_only(&request.messages).await?;
let mut body = helpers::build_openai_body(&request, messages_json, true);
body.as_object_mut().expect("body is object").remove("stream_options");
// DeepSeek reasoning model doesn't support stream_options
if request.model == "deepseek-reasoner" {
if let Some(obj) = body.as_object_mut() {
obj.remove("stream_options");
// Also does not support tools/temperature/top_p
obj.remove("tools");
obj.remove("tool_choice");
obj.remove("temperature");
obj.remove("top_p");
}
} else {
// For standard deepseek-chat, keep it clean
if let Some(obj) = body.as_object_mut() {
obj.remove("stream_options");
}
}
let es = reqwest_eventsource::EventSource::new(
self.client