From 2cfa7fbae7de4a5b0d5a6ae1fcb1429b04dc4354 Mon Sep 17 00:00:00 2001 From: Flavien David Date: Tue, 19 Dec 2023 10:33:45 +0100 Subject: [PATCH] Add user in meta-prompt for Mistral (#2929) * Add user in meta-prompt for Mistral * :sparkles: --- core/src/providers/mistral.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/core/src/providers/mistral.rs b/core/src/providers/mistral.rs index a932fab691d4..9f32a9f3db94 100644 --- a/core/src/providers/mistral.rs +++ b/core/src/providers/mistral.rs @@ -76,12 +76,23 @@ struct ChatMessage { impl TryFrom<&BaseChatMessage> for ChatMessage { type Error = anyhow::Error; - fn try_from(value: &BaseChatMessage) -> Result { - let mistral_role = MistralAIChatMessageRole::try_from(&value.role) + fn try_from(cm: &BaseChatMessage) -> Result { + let mistral_role = MistralAIChatMessageRole::try_from(&cm.role) .map_err(|e| anyhow!("Error converting role: {:?}", e))?; + let meta_prompt = match cm.name.as_ref() { + Some(name) if mistral_role == MistralAIChatMessageRole::User => { + format!("[user: {}] ", name) // Include space here. + } + _ => String::from(""), + }; + Ok(ChatMessage { - content: value.content.clone(), + content: Some(format!( + "{}{}", + meta_prompt, + cm.content.clone().unwrap_or(String::from("")) + )), role: mistral_role, }) }