feat: unroll notify_error if no tool is choosen

This commit is contained in:
drbh 2024-09-30 15:34:43 +02:00
parent d1f257ac56
commit dfc4559017

View File

@ -1246,17 +1246,33 @@ async fn chat_completions(
if let Value::Object(ref mut props) = arguments { if let Value::Object(ref mut props) = arguments {
props.remove("_name"); props.remove("_name");
} }
match name.as_str() {
let tool_calls = vec![ToolCall { "notify_error" => {
id: "0".to_string(), // parse the error message
r#type: "function".to_string(), let error_message = arguments
function: FunctionDefinition { .get("error")
description: None, .and_then(Value::as_str)
name, .ok_or_else(|| {
arguments, InferError::ToolError(
}, "No error message found in generated text".to_string(),
}]; )
(Some(tool_calls), None) })?
.to_string();
(None, Some(error_message))
}
_ => {
let tool_calls = vec![ToolCall {
id: "0".to_string(),
r#type: "function".to_string(),
function: FunctionDefinition {
description: None,
name,
arguments,
},
}];
(Some(tool_calls), None)
}
}
} else { } else {
(None, Some(generation.generated_text)) (None, Some(generation.generated_text))
}; };