Fix error when Copilot calls tools without arguments (#30371)
Fixes https://github.com/zed-industries/zed/issues/30346 The model can output an empty string to indicate the absence of arguments, which can't be parsed as a `serde_json::Value`. When that happens, we now create an empty object instead on behalf of the model. Release Notes: - Fixed a bug that prevented Copilot models from calling the `diagnostic` tool.
This commit is contained in:
parent
f248da5921
commit
25ced2e3c2
1 changed files with 28 additions and 19 deletions
|
@ -368,9 +368,17 @@ pub fn map_to_language_model_completion_events(
|
|||
}
|
||||
Some("tool_calls") => {
|
||||
events.extend(state.tool_calls_by_index.drain().map(
|
||||
|(_, tool_call)| match serde_json::Value::from_str(
|
||||
&tool_call.arguments,
|
||||
) {
|
||||
|(_, tool_call)| {
|
||||
// The model can output an empty string
|
||||
// to indicate the absence of arguments.
|
||||
// When that happens, create an empty
|
||||
// object instead.
|
||||
let arguments = if tool_call.arguments.is_empty() {
|
||||
Ok(serde_json::Value::Object(Default::default()))
|
||||
} else {
|
||||
serde_json::Value::from_str(&tool_call.arguments)
|
||||
};
|
||||
match arguments {
|
||||
Ok(input) => Ok(LanguageModelCompletionEvent::ToolUse(
|
||||
LanguageModelToolUse {
|
||||
id: tool_call.id.clone().into(),
|
||||
|
@ -388,6 +396,7 @@ pub fn map_to_language_model_completion_events(
|
|||
json_parse_error: error.to_string(),
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue