mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-06-07 12:45:40 +00:00
Display pre-query prompt in search tool response
This commit is contained in:
parent
81ea8933c1
commit
d5d30ed4f2
@ -27,6 +27,7 @@ use meilisearch_types::{Document, Index};
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use tokio::runtime::Handle;
|
use tokio::runtime::Handle;
|
||||||
|
use tracing::error;
|
||||||
|
|
||||||
use super::settings::chat::{ChatPrompts, ChatSettings};
|
use super::settings::chat::{ChatPrompts, ChatSettings};
|
||||||
use crate::extractors::authentication::policies::ActionPolicy;
|
use crate::extractors::authentication::policies::ActionPolicy;
|
||||||
@ -361,32 +362,40 @@ async fn streamed_chat(
|
|||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
// Handle potential errors more explicitly
|
let text = match result {
|
||||||
if let Err(err) = &result {
|
Ok((_, text)) => text,
|
||||||
// Log the error or handle it as needed
|
Err(err) => {
|
||||||
eprintln!("Error processing search request: {:?}", err);
|
error!("Error processing search request: {err:?}");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
let (_, text) = result.unwrap();
|
|
||||||
|
|
||||||
let tool = ChatCompletionRequestMessage::Tool(
|
let tool = ChatCompletionRequestMessage::Tool(
|
||||||
|
ChatCompletionRequestToolMessage {
|
||||||
|
tool_call_id: call.id.clone(),
|
||||||
|
content: ChatCompletionRequestToolMessageContent::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": ChatCompletionRequestMessage::Tool(
|
||||||
ChatCompletionRequestToolMessage {
|
ChatCompletionRequestToolMessage {
|
||||||
tool_call_id: call.id,
|
tool_call_id: call.id,
|
||||||
content: ChatCompletionRequestToolMessageContent::Text(
|
content: ChatCompletionRequestToolMessageContent::Text(
|
||||||
text,
|
text,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
);
|
),
|
||||||
tx.send(Event::Data(
|
|
||||||
sse::Data::new_json(&json!({
|
|
||||||
"object": "chat.completion.tool.output",
|
|
||||||
"tool": tool,
|
|
||||||
}))
|
}))
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
))
|
))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
chat_completion.messages.push(tool);
|
chat_completion.messages.push(tool);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user