Skip to content

Commit 5b58187

Browse files
committed
feat: switch rag policy from system-message to last-user-message
Signed-off-by: Xin Liu <[email protected]>
1 parent 2b3f923 commit 5b58187

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/backend/ggml.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -843,12 +843,14 @@ impl MergeRagContext for RagPromptBuilder {
843843
has_system_prompt: bool,
844844
policy: MergeRagContextPolicy,
845845
) -> ChatPromptsError::Result<()> {
846+
// check messages
846847
if messages.is_empty() {
847848
error!(target: "stdout", "No message in the chat request.");
848849

849850
return Err(ChatPromptsError::PromptError::NoMessages);
850851
}
851852

853+
// check context
852854
if context.is_empty() {
853855
let err_msg = "No context provided.";
854856

@@ -858,13 +860,13 @@ impl MergeRagContext for RagPromptBuilder {
858860
return Err(ChatPromptsError::PromptError::Operation(err_msg.into()));
859861
}
860862

863+
// check rag policy
864+
let mut policy = policy;
861865
if policy == MergeRagContextPolicy::SystemMessage && !has_system_prompt {
862-
let err_msg = "The chat model does not support system message, while the given rag policy by '--policy' option requires that the RAG context is merged into system message. Please check the relevant CLI options and try again.";
863-
864866
// log
865-
error!(target: "stdout", "{}", &err_msg);
867+
info!(target: "stdout", "The chat model does not support system message. Switch the currect rag policy to `last-user-message`");
866868

867-
return Err(ChatPromptsError::PromptError::Operation(err_msg.into()));
869+
policy = MergeRagContextPolicy::LastUserMessage;
868870
}
869871
info!(target: "stdout", "rag_policy: {}", &policy);
870872

@@ -954,7 +956,7 @@ impl MergeRagContext for RagPromptBuilder {
954956
}
955957
}
956958
MergeRagContextPolicy::LastUserMessage => {
957-
info!(target: "stdout", "Merge RAG context into last user message.");
959+
info!(target: "stdout", "Merge RAG context into the latest user message.");
958960

959961
let len = messages.len();
960962
match &messages.last() {

0 commit comments

Comments
 (0)