diff options
| author | sigoden <sigoden@gmail.com> | 2024-06-22 14:07:58 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-22 14:07:58 +0800 |
| commit | 0ec370b48c951a69459f9232b56df882765ccb52 (patch) | |
| tree | c12bab3bd72acc97adcd835b8d5aea82d1b96cd3 /src/client/openai.rs | |
| parent | 250e0eb7fee0d180b08b7d38d10c530e9a6a120d (diff) | |
| download | aichat-0ec370b48c951a69459f9232b56df882765ccb52.tar.gz | |
refactor: improve clients (#632)
Diffstat (limited to 'src/client/openai.rs')
| -rw-r--r-- | src/client/openai.rs | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/client/openai.rs b/src/client/openai.rs index 40058e6..bfe896f 100644 --- a/src/client/openai.rs +++ b/src/client/openai.rs @@ -177,26 +177,26 @@ pub fn openai_build_chat_completions_body(data: ChatCompletionsData, model: &Mod .flat_map(|message| { let Message { role, content } = message; match content { - MessageContent::ToolResults((tool_call_results, text)) => { - let tool_calls: Vec<_> = tool_call_results.iter().map(|tool_call_result| { + MessageContent::ToolResults((tool_results, text)) => { + let tool_calls: Vec<_> = tool_results.iter().map(|tool_result| { json!({ - "id": tool_call_result.call.id, + "id": tool_result.call.id, "type": "function", "function": { - "name": tool_call_result.call.name, - "arguments": tool_call_result.call.arguments, + "name": tool_result.call.name, + "arguments": tool_result.call.arguments, }, }) }).collect(); let mut messages = vec![ json!({ "role": MessageRole::Assistant, "content": text, "tool_calls": tool_calls }) ]; - for tool_call_result in tool_call_results { + for tool_result in tool_results { messages.push( json!({ "role": "tool", - "content": tool_call_result.output.to_string(), - "tool_call_id": tool_call_result.call.id, + "content": tool_result.output.to_string(), + "tool_call_id": tool_result.call.id, }) ); } @@ -251,8 +251,8 @@ pub fn openai_extract_chat_completions(data: &Value) -> Result<ChatCompletionsOu .unwrap_or_default(); let mut tool_calls = vec![]; - if let Some(tools_call) = data["choices"][0]["message"]["tool_calls"].as_array() { - tool_calls = tools_call + if let Some(calls) = data["choices"][0]["message"]["tool_calls"].as_array() { + tool_calls = calls .iter() .filter_map(|call| { if let (Some(name), Some(arguments), Some(id)) = ( |
