Make sure to send the tool response before the error message

This commit is contained in:
Louis Dureuil 2025-06-11 10:49:21 +02:00
parent 77cc3678b5
commit 7533a11143
No known key found for this signature in database

View File

@ -645,6 +645,8 @@ async fn handle_meili_tools(
.await?;
}
let mut error = None;
let result = match serde_json::from_str(&call.function.arguments) {
Ok(SearchInIndexParameters { index_uid, q }) => match process_search_request(
index_scheduler,
@ -658,8 +660,8 @@ async fn handle_meili_tools(
{
Ok(output) => Ok(output),
Err(err) => {
let error_text = err.to_string();
tx.send_error(&StreamErrorEvent::from_response_error(err)).await?;
let error_text = format!("the search tool call failed with {err}");
error = Some(err);
Err(error_text)
}
},
@ -686,6 +688,10 @@ async fn handle_meili_tools(
}
chat_completion.messages.push(tool);
if let Some(error) = error {
tx.send_error(&StreamErrorEvent::from_response_error(error)).await?;
}
}
Ok(())