mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-05-14 16:23:57 +02:00
Make it work by retrieving content from the index
This commit is contained in:
parent
ac39a436d9
commit
3a71df7b5a
@ -88,23 +88,25 @@ async fn chat(
|
|||||||
|
|
||||||
let mut response;
|
let mut response;
|
||||||
loop {
|
loop {
|
||||||
let mut tools = chat_completion.tools.get_or_insert_default();
|
let tools = chat_completion.tools.get_or_insert_default();
|
||||||
tools.push(ChatCompletionToolArgs::default()
|
tools.push(
|
||||||
|
ChatCompletionToolArgs::default()
|
||||||
.r#type(ChatCompletionToolType::Function)
|
.r#type(ChatCompletionToolType::Function)
|
||||||
.function(FunctionObjectArgs::default()
|
.function(
|
||||||
|
FunctionObjectArgs::default()
|
||||||
.name("searchInIndex")
|
.name("searchInIndex")
|
||||||
.description(DEFAULT_SEARCH_IN_INDEX_TOOL_DESCRIPTION)
|
.description(&search_in_index_description)
|
||||||
.parameters(json!({
|
.parameters(json!({
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"index_uid": {
|
"index_uid": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["main"],
|
"enum": ["main"],
|
||||||
"description": DEFAULT_SEARCH_IN_INDEX_INDEX_PARAMETER_TOOL_DESCRIPTION,
|
"description": search_in_index_index_description,
|
||||||
},
|
},
|
||||||
"q": {
|
"q": {
|
||||||
"type": ["string", "null"],
|
"type": ["string", "null"],
|
||||||
"description": DEFAULT_SEARCH_IN_INDEX_Q_PARAMETER_TOOL_DESCRIPTION,
|
"description": search_in_index_q_param_description,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["index_uid", "q"],
|
"required": ["index_uid", "q"],
|
||||||
@ -115,7 +117,7 @@ async fn chat(
|
|||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap(),
|
||||||
);
|
);
|
||||||
response = dbg!(client.chat().create(chat_completion.clone()).await.unwrap());
|
response = dbg!(client.chat().create(chat_completion.clone()).await.unwrap());
|
||||||
|
|
||||||
@ -137,7 +139,7 @@ async fn chat(
|
|||||||
|
|
||||||
for call in meili_calls {
|
for call in meili_calls {
|
||||||
let SearchInIndexParameters { index_uid, q } =
|
let SearchInIndexParameters { index_uid, q } =
|
||||||
serde_json::from_str(dbg!(&call.function.arguments)).unwrap();
|
serde_json::from_str(&call.function.arguments).unwrap();
|
||||||
|
|
||||||
let mut query = SearchQuery {
|
let mut query = SearchQuery {
|
||||||
q,
|
q,
|
||||||
@ -145,6 +147,7 @@ async fn chat(
|
|||||||
semantic_ratio: SemanticRatio::default(),
|
semantic_ratio: SemanticRatio::default(),
|
||||||
embedder: EMBEDDER_NAME.to_string(),
|
embedder: EMBEDDER_NAME.to_string(),
|
||||||
}),
|
}),
|
||||||
|
limit: 20,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -241,10 +244,15 @@ fn format_documents(index: &Index, documents: impl Iterator<Item = Document>) ->
|
|||||||
quantized: _,
|
quantized: _,
|
||||||
} = config;
|
} = config;
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct Doc<T: Serialize> {
|
||||||
|
doc: T,
|
||||||
|
}
|
||||||
|
|
||||||
let template = liquid::ParserBuilder::with_stdlib().build().unwrap().parse(&template).unwrap();
|
let template = liquid::ParserBuilder::with_stdlib().build().unwrap().parse(&template).unwrap();
|
||||||
documents
|
documents
|
||||||
.map(|doc| {
|
.map(|doc| {
|
||||||
let object = liquid::to_object(&doc).unwrap();
|
let object = liquid::to_object(&Doc { doc }).unwrap();
|
||||||
template.render(&object).unwrap()
|
template.render(&object).unwrap()
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user