Skip to content

Commit

Permalink
refactor!: improve MergeRagContext trait impl for RagPromptBuilder
Browse files Browse the repository at this point in the history
Signed-off-by: Xin Liu <[email protected]>
  • Loading branch information
apepkuss committed Jul 30, 2024
1 parent a1493cb commit 004fd89
Showing 1 changed file with 12 additions and 27 deletions.
39 changes: 12 additions & 27 deletions src/backend/ggml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,33 +555,18 @@ impl MergeRagContext for RagPromptBuilder {

match &messages[0] {
ChatCompletionRequestMessage::System(message) => {
let system_message = match GLOBAL_RAG_PROMPT.get() {
Some(global_rag_prompt) => {
// compose new system message content
let content = format!(
"{rag_prompt}\n{context}",
rag_prompt = global_rag_prompt.to_owned(),
context = context.trim_end()
);
// create system message
ChatCompletionRequestMessage::new_system_message(
content,
message.name().cloned(),
)
}
None => {
// compose new system message content
let content = format!(
"{system_message}\n{context}",
system_message = message.content().trim(),
context = context.trim_end()
);
// create system message
ChatCompletionRequestMessage::new_system_message(
content,
message.name().cloned(),
)
}
let system_message = {
// compose new system message content
let content = format!(
"{system_message}\n{context}",
system_message = message.content().trim(),
context = context.trim_end()
);
// create system message
ChatCompletionRequestMessage::new_system_message(
content,
message.name().cloned(),
)
};

// replace the original system message
Expand Down

0 comments on commit 004fd89

Please sign in to comment.