diff options
| author | sigoden <sigoden@gmail.com> | 2024-06-17 09:31:17 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-17 09:31:17 +0800 |
| commit | 72e689fab0b414ea943c300c3eb92901c77ce775 (patch) | |
| tree | e6e929fd262d162a860200c208f65584090009ab /src | |
| parent | 638bf3276613265da761b4d74f269fa77c8f4bb1 (diff) | |
| download | aichat-72e689fab0b414ea943c300c3eb92901c77ce775.tar.gz | |
fix: cohere tool use (#605)
cohere cannot specify both message and tool_results in multistep mode
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/cohere.rs | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/src/client/cohere.rs b/src/client/cohere.rs index 9954a61..8745347 100644 --- a/src/client/cohere.rs +++ b/src/client/cohere.rs @@ -207,25 +207,6 @@ fn build_chat_completions_body(data: ChatCompletionsData, model: &Model) -> Resu "message": message, }); - if let Some(tool_results) = tool_results { - let tool_results: Vec<_> = tool_results - .into_iter() - .map(|tool_call_result| { - json!({ - "call": { - "name": tool_call_result.call.name, - "parameters": tool_call_result.call.arguments, - }, - "outputs": [ - tool_call_result.output, - ] - - }) - }) - .collect(); - body["tool_results"] = json!(tool_results); - } - if let Some(v) = system_message { body["preamble"] = v.into(); } @@ -247,6 +228,29 @@ fn build_chat_completions_body(data: ChatCompletionsData, model: &Model) -> Resu body["stream"] = true.into(); } + if let Some(tool_results) = tool_results { + let tool_results: Vec<_> = tool_results + .into_iter() + .map(|tool_call_result| { + json!({ + "call": { + "name": tool_call_result.call.name, + "parameters": tool_call_result.call.arguments, + }, + "outputs": [ + tool_call_result.output, + ] + + }) + }) + .collect(); + body["tool_results"] = json!(tool_results); + if let Some(object) = body.as_object_mut() { + object.remove("chat_history"); + object.remove("message"); + } + } + if let Some(functions) = functions { body["tools"] = functions .iter() |
