Merge branch 'main'
This commit is contained in:
+5
-13
@@ -214,12 +214,8 @@ pub async fn claude_chat_completions_streaming(
|
|||||||
if let Some(text) = data["delta"]["text"].as_str() {
|
if let Some(text) = data["delta"]["text"].as_str() {
|
||||||
handler.text(text)?;
|
handler.text(text)?;
|
||||||
} else if let Some(text) = data["delta"]["thinking"].as_str() {
|
} else if let Some(text) = data["delta"]["thinking"].as_str() {
|
||||||
if reasoning_state == 0 {
|
reasoning_state = 1;
|
||||||
handler.text("<think>\n")?;
|
|
||||||
reasoning_state = 1;
|
|
||||||
}
|
|
||||||
thinking_text.push_str(text);
|
thinking_text.push_str(text);
|
||||||
handler.text(text)?;
|
|
||||||
} else if let Some(signature) = data["delta"]["signature"].as_str() {
|
} else if let Some(signature) = data["delta"]["signature"].as_str() {
|
||||||
thinking_signature.push_str(signature);
|
thinking_signature.push_str(signature);
|
||||||
} else if let (true, Some(partial_json)) = (
|
} else if let (true, Some(partial_json)) = (
|
||||||
@@ -231,7 +227,6 @@ pub async fn claude_chat_completions_streaming(
|
|||||||
}
|
}
|
||||||
"content_block_stop" => {
|
"content_block_stop" => {
|
||||||
if reasoning_state == 1 {
|
if reasoning_state == 1 {
|
||||||
handler.text("\n</think>\n\n")?;
|
|
||||||
reasoning_state = 0;
|
reasoning_state = 0;
|
||||||
handler.thinking_block(ThinkingBlock::Thinking {
|
handler.thinking_block(ThinkingBlock::Thinking {
|
||||||
thinking: mem::take(&mut thinking_text),
|
thinking: mem::take(&mut thinking_text),
|
||||||
@@ -481,7 +476,6 @@ pub fn claude_build_chat_completions_body(
|
|||||||
|
|
||||||
pub fn claude_extract_chat_completions(data: &Value) -> Result<ChatCompletionsOutput> {
|
pub fn claude_extract_chat_completions(data: &Value) -> Result<ChatCompletionsOutput> {
|
||||||
let mut text = String::new();
|
let mut text = String::new();
|
||||||
let mut reasoning = None;
|
|
||||||
let mut tool_calls = vec![];
|
let mut tool_calls = vec![];
|
||||||
let mut thinking = vec![];
|
let mut thinking = vec![];
|
||||||
if let Some(list) = data["content"].as_array() {
|
if let Some(list) = data["content"].as_array() {
|
||||||
@@ -489,10 +483,12 @@ pub fn claude_extract_chat_completions(data: &Value) -> Result<ChatCompletionsOu
|
|||||||
match item["type"].as_str() {
|
match item["type"].as_str() {
|
||||||
Some("thinking") => {
|
Some("thinking") => {
|
||||||
if let Some(v) = item["thinking"].as_str() {
|
if let Some(v) = item["thinking"].as_str() {
|
||||||
reasoning = Some(v.to_string());
|
|
||||||
thinking.push(ThinkingBlock::Thinking {
|
thinking.push(ThinkingBlock::Thinking {
|
||||||
thinking: v.to_string(),
|
thinking: v.to_string(),
|
||||||
signature: item["signature"].as_str().unwrap_or_default().to_string(),
|
signature: item["signature"]
|
||||||
|
.as_str()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.to_string(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -528,10 +524,6 @@ pub fn claude_extract_chat_completions(data: &Value) -> Result<ChatCompletionsOu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(reasoning) = reasoning {
|
|
||||||
text = format!("<think>\n{reasoning}\n</think>\n\n{text}")
|
|
||||||
}
|
|
||||||
|
|
||||||
if text.is_empty() && tool_calls.is_empty() {
|
if text.is_empty() && tool_calls.is_empty() {
|
||||||
bail!("Invalid response data: {data}");
|
bail!("Invalid response data: {data}");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user