fix: Claude tool calls work incorrectly when tool doesn't require any arguments or flags; would provide an empty JSON object or error on no args
This commit is contained in:
@@ -93,10 +93,13 @@ pub async fn claude_chat_completions_streaming(
|
|||||||
data["content_block"]["id"].as_str(),
|
data["content_block"]["id"].as_str(),
|
||||||
) {
|
) {
|
||||||
if !function_name.is_empty() {
|
if !function_name.is_empty() {
|
||||||
let arguments: Value =
|
let arguments: Value = if function_arguments.is_empty() {
|
||||||
|
json!({})
|
||||||
|
} else {
|
||||||
function_arguments.parse().with_context(|| {
|
function_arguments.parse().with_context(|| {
|
||||||
format!("Tool call '{function_name}' has non-JSON arguments '{function_arguments}'")
|
format!("Tool call '{function_name}' has non-JSON arguments '{function_arguments}'")
|
||||||
})?;
|
})?
|
||||||
|
};
|
||||||
handler.tool_call(ToolCall::new(
|
handler.tool_call(ToolCall::new(
|
||||||
function_name.clone(),
|
function_name.clone(),
|
||||||
arguments,
|
arguments,
|
||||||
@@ -286,7 +289,7 @@ pub fn claude_build_chat_completions_body(
|
|||||||
body["tools"] = functions
|
body["tools"] = functions
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| {
|
.map(|v| {
|
||||||
if v.parameters.type_value.is_none() {
|
if v.parameters.is_empty_properties() {
|
||||||
json!({
|
json!({
|
||||||
"name": v.name,
|
"name": v.name,
|
||||||
"description": v.description,
|
"description": v.description,
|
||||||
|
|||||||
Reference in New Issue
Block a user