mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-05-25 09:03:59 +02:00
Make sure errorneous calls are handled and forwarded to the LLM
This commit is contained in:
parent
beff6adeb1
commit
91c6ab8392
@ -253,23 +253,32 @@ async fn non_streamed_chat(
|
|||||||
);
|
);
|
||||||
|
|
||||||
for call in meili_calls {
|
for call in meili_calls {
|
||||||
let SearchInIndexParameters { index_uid, q } =
|
let result = match serde_json::from_str(&call.function.arguments) {
|
||||||
serde_json::from_str(&call.function.arguments).unwrap();
|
Ok(SearchInIndexParameters { index_uid, q }) => process_search_request(
|
||||||
|
&index_scheduler,
|
||||||
|
auth_ctrl.clone(),
|
||||||
|
&search_queue,
|
||||||
|
&auth_token,
|
||||||
|
index_uid,
|
||||||
|
q,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map_err(|e| e.to_string()),
|
||||||
|
Err(err) => Err(err.to_string()),
|
||||||
|
};
|
||||||
|
|
||||||
let (_, text) = process_search_request(
|
let text = match result {
|
||||||
&index_scheduler,
|
Ok((_, text)) => text,
|
||||||
auth_ctrl.clone(),
|
Err(err) => err,
|
||||||
&search_queue,
|
};
|
||||||
auth_token,
|
|
||||||
index_uid,
|
|
||||||
q,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
chat_completion.messages.push(ChatCompletionRequestMessage::Tool(
|
chat_completion.messages.push(ChatCompletionRequestMessage::Tool(
|
||||||
ChatCompletionRequestToolMessage {
|
ChatCompletionRequestToolMessage {
|
||||||
tool_call_id: call.id,
|
tool_call_id: call.id.clone(),
|
||||||
content: ChatCompletionRequestToolMessageContent::Text(text),
|
content: ChatCompletionRequestToolMessageContent::Text(format!(
|
||||||
|
"{}\n\n{text}",
|
||||||
|
chat_settings.prompts.pre_query
|
||||||
|
)),
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -413,7 +422,7 @@ async fn streamed_chat(
|
|||||||
let is_error = result.is_err();
|
let is_error = result.is_err();
|
||||||
let text = match result {
|
let text = match result {
|
||||||
Ok((_, text)) => text,
|
Ok((_, text)) => text,
|
||||||
Err(err) => err.to_string(),
|
Err(err) => err,
|
||||||
};
|
};
|
||||||
|
|
||||||
let tool = ChatCompletionRequestToolMessage {
|
let tool = ChatCompletionRequestToolMessage {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user