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