Make sure template errors are reported to the LLM and front-end without panicking

This commit is contained in:
Clément Renault 2025-06-11 09:27:14 +02:00
parent 506ee40dc5
commit 77cc3678b5
No known key found for this signature in database
GPG key ID: F250A4C4E3AE5F5F
4 changed files with 49 additions and 17 deletions

View file

@ -9,7 +9,7 @@ use async_openai::types::{
FunctionCall, FunctionCallStream, Role,
};
use bumpalo::Bump;
use meilisearch_types::error::ResponseError;
use meilisearch_types::error::{Code, ResponseError};
use meilisearch_types::heed::RoTxn;
use meilisearch_types::milli::index::ChatConfig;
use meilisearch_types::milli::prompt::{Prompt, PromptData};
@ -237,7 +237,15 @@ pub fn format_documents<'doc>(
Some(doc) => doc,
None => unreachable!("Document with internal ID {docid} not found"),
};
let text = prompt.render_document(&external_docid, document, &gfid_map, doc_alloc).unwrap();
let text = match prompt.render_document(&external_docid, document, &gfid_map, doc_alloc) {
Ok(text) => text,
Err(err) => {
return Err(ResponseError::from_msg(
err.to_string(),
Code::InvalidChatSettingDocumentTemplate,
))
}
};
renders.push(text);
}