Display pre-query prompt in search tool response

This commit is contained in:
Clément Renault 2025-05-15 18:10:09 +02:00 committed by Kerollmops
parent 81ea8933c1
commit d5d30ed4f2
No known key found for this signature in database
GPG Key ID: F250A4C4E3AE5F5F

View File

@ -27,6 +27,7 @@ use meilisearch_types::{Document, Index};
use serde::{Deserialize, Serialize};
use serde_json::json;
use tokio::runtime::Handle;
use tracing::error;
use super::settings::chat::{ChatPrompts, ChatSettings};
use crate::extractors::authentication::policies::ActionPolicy;
@ -361,32 +362,40 @@ async fn streamed_chat(
)
.await;
// Handle potential errors more explicitly
if let Err(err) = &result {
// Log the error or handle it as needed
eprintln!("Error processing search request: {:?}", err);
continue;
}
let (_, text) = result.unwrap();
let text = match result {
Ok((_, text)) => text,
Err(err) => {
error!("Error processing search request: {err:?}");
continue;
}
};
let tool = ChatCompletionRequestMessage::Tool(
ChatCompletionRequestToolMessage {
tool_call_id: call.id,
tool_call_id: call.id.clone(),
content: ChatCompletionRequestToolMessageContent::Text(
text,
format!("{}\n\n{text}", chat_settings.prompts.pre_query),
),
},
);
tx.send(Event::Data(
sse::Data::new_json(&json!({
"object": "chat.completion.tool.output",
"tool": tool,
"tool": ChatCompletionRequestMessage::Tool(
ChatCompletionRequestToolMessage {
tool_call_id: call.id,
content: ChatCompletionRequestToolMessageContent::Text(
text,
),
},
),
}))
.unwrap(),
))
.await
.unwrap();
chat_completion.messages.push(tool);
}
}