Skip to content

Commit

Permalink
Add user in meta-prompt for Mistral (#2929)
Browse files Browse the repository at this point in the history
* Add user in meta-prompt for Mistral

* ✨
  • Loading branch information
flvndvd authored Dec 19, 2023
1 parent 61a2851 commit 2cfa7fb
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions core/src/providers/mistral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,23 @@ struct ChatMessage {
impl TryFrom<&BaseChatMessage> for ChatMessage {
type Error = anyhow::Error;

fn try_from(value: &BaseChatMessage) -> Result<Self, Self::Error> {
let mistral_role = MistralAIChatMessageRole::try_from(&value.role)
fn try_from(cm: &BaseChatMessage) -> Result<Self, Self::Error> {
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,
})
}
Expand Down

0 comments on commit 2cfa7fb

Please sign in to comment.