Skip to content

Commit

Permalink
fix: openai does not like empty tools
Browse files Browse the repository at this point in the history
  • Loading branch information
valaises committed Nov 21, 2024
1 parent b63e74a commit 44935fa
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/scratchpads/chat_passthrough.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,15 @@ impl ScratchpadAbstract for ChatPassthrough {
let tools_desc_list = tool_description_list_from_yaml(at_tools, &tools_enabled, allow_experimental).await?;
let tools_filtered = tools_desc_list.iter().filter(|t|tools_enabled.contains(&t.name)).cloned().collect::<Vec<_>>();

if self.endpoint_style == "anthropic" {
big_json["tools"] = serde_json::json!(tools_filtered.iter().map(|t|t.clone().into_anthropic_style()).collect::<Vec<_>>());
} else {
big_json["tools"] = serde_json::json!(tools_filtered.iter().map(|t|t.clone().into_openai_style(false)).collect::<Vec<_>>());
if !tools_filtered.is_empty() {
if self.endpoint_style == "anthropic" {
big_json["tools"] = serde_json::json!(tools_filtered.iter().map(|t|t.clone().into_anthropic_style()).collect::<Vec<_>>());
} else {
big_json["tools"] = serde_json::json!(tools_filtered.iter().map(|t|t.clone().into_openai_style(false)).collect::<Vec<_>>());
big_json["tool_choice"] = serde_json::json!(self.post.tool_choice);
}
}

big_json["tool_choice"] = serde_json::json!(self.post.tool_choice);
if DEBUG {
info!("PASSTHROUGH TOOLS ENABLED CNT: {:?}", tools.unwrap_or(&vec![]).len());
}
Expand Down

0 comments on commit 44935fa

Please sign in to comment.