refactor: extract stream parsing helper and enable deepseek error probing
This commit is contained in:
@@ -58,22 +58,7 @@ 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 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");
|
||||
obj.remove("presence_penalty");
|
||||
obj.remove("frequency_penalty");
|
||||
obj.remove("logit_bias");
|
||||
obj.remove("logprobs");
|
||||
obj.remove("top_logprobs");
|
||||
}
|
||||
}
|
||||
let body = helpers::build_openai_body(&request, messages_json, false);
|
||||
|
||||
let response = self
|
||||
.client
|
||||
@@ -85,8 +70,10 @@ impl super::Provider for DeepSeekProvider {
|
||||
.map_err(|e| AppError::ProviderError(e.to_string()))?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
let status = response.status();
|
||||
let error_text = response.text().await.unwrap_or_default();
|
||||
return Err(AppError::ProviderError(format!("DeepSeek API error: {}", error_text)));
|
||||
tracing::error!("DeepSeek API error ({}): {}", status, error_text);
|
||||
return Err(AppError::ProviderError(format!("DeepSeek API error ({}): {}", status, error_text)));
|
||||
}
|
||||
|
||||
let resp_json: serde_json::Value = response
|
||||
@@ -131,26 +118,9 @@ impl super::Provider for DeepSeekProvider {
|
||||
let messages_json = helpers::messages_to_openai_json_text_only(&request.messages).await?;
|
||||
let mut body = helpers::build_openai_body(&request, messages_json, true);
|
||||
|
||||
// Sanitize for deepseek-reasoner or general deepseek-chat
|
||||
if request.model == "deepseek-reasoner" {
|
||||
if let Some(obj) = body.as_object_mut() {
|
||||
obj.remove("stream_options");
|
||||
// Also does not support these parameters
|
||||
obj.remove("tools");
|
||||
obj.remove("tool_choice");
|
||||
obj.remove("temperature");
|
||||
obj.remove("top_p");
|
||||
obj.remove("presence_penalty");
|
||||
obj.remove("frequency_penalty");
|
||||
obj.remove("logit_bias");
|
||||
obj.remove("logprobs");
|
||||
obj.remove("top_logprobs");
|
||||
}
|
||||
} else {
|
||||
// For standard deepseek-chat, keep it clean
|
||||
if let Some(obj) = body.as_object_mut() {
|
||||
obj.remove("stream_options");
|
||||
}
|
||||
// Standard OpenAI cleanup
|
||||
if let Some(obj) = body.as_object_mut() {
|
||||
obj.remove("stream_options");
|
||||
}
|
||||
|
||||
let url = format!("{}/chat/completions", self.config.base_url);
|
||||
|
||||
Reference in New Issue
Block a user