style: 格式化代码并优化导入顺序
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use super::thinking::ThinkingStateManager;
|
||||
use super::{create_http_client, LlmProvider};
|
||||
use anyhow::{bail, Context, Result};
|
||||
use super::{LlmProvider, create_http_client};
|
||||
use anyhow::{Context, Result, bail};
|
||||
use async_trait::async_trait;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
@@ -459,34 +459,39 @@ impl DeepSeekClient {
|
||||
for choice in &chunk.choices {
|
||||
// 处理 reasoning_content
|
||||
if let Some(ref reasoning) = choice.delta.reasoning_content
|
||||
&& !reasoning.is_empty() {
|
||||
if !has_reasoning {
|
||||
has_reasoning = true;
|
||||
if let Some(state) = thinking_state {
|
||||
state.start_thinking();
|
||||
}
|
||||
&& !reasoning.is_empty()
|
||||
{
|
||||
if !has_reasoning {
|
||||
has_reasoning = true;
|
||||
if let Some(state) = thinking_state {
|
||||
state.start_thinking();
|
||||
}
|
||||
// reasoning_content 不对外输出,仅用于内部状态判断
|
||||
continue;
|
||||
}
|
||||
// reasoning_content 不对外输出,仅用于内部状态判断
|
||||
continue;
|
||||
}
|
||||
|
||||
// 处理 content
|
||||
if let Some(ref content) = choice.delta.content
|
||||
&& !content.is_empty() {
|
||||
// reasoning 结束,content 开始出现时移除 thinking 标识
|
||||
if has_reasoning && !has_content
|
||||
&& let Some(state) = thinking_state {
|
||||
state.end_thinking();
|
||||
}
|
||||
has_content = true;
|
||||
content_buffer.push_str(content);
|
||||
&& !content.is_empty()
|
||||
{
|
||||
// reasoning 结束,content 开始出现时移除 thinking 标识
|
||||
if has_reasoning
|
||||
&& !has_content
|
||||
&& let Some(state) = thinking_state
|
||||
{
|
||||
state.end_thinking();
|
||||
}
|
||||
has_content = true;
|
||||
content_buffer.push_str(content);
|
||||
}
|
||||
|
||||
// 检查 finish_reason
|
||||
if let Some(ref reason) = choice.finish_reason
|
||||
&& reason == "stop" {
|
||||
stream_ended = true;
|
||||
}
|
||||
&& reason == "stop"
|
||||
{
|
||||
stream_ended = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
@@ -612,9 +617,6 @@ mod tests {
|
||||
let json = r#"{"content":null,"reasoning_content":"Let me think..."}"#;
|
||||
let delta: StreamDelta = serde_json::from_str(json).unwrap();
|
||||
assert!(delta.content.is_none());
|
||||
assert_eq!(
|
||||
delta.reasoning_content,
|
||||
Some("Let me think...".to_string())
|
||||
);
|
||||
assert_eq!(delta.reasoning_content, Some("Let me think...".to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user