From e0f3cd580cb85066f7d36241a03c30aa50a8a31d Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Sat, 27 Jul 2024 22:30:04 -0700 Subject: [PATCH] fix(factory.py): support mistral ai prefix:true in messages Fixes https://github.com/BerriAI/litellm/issues/4882 --- litellm/llms/prompt_templates/factory.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/litellm/llms/prompt_templates/factory.py b/litellm/llms/prompt_templates/factory.py index efe8124975e..2218fa56816 100644 --- a/litellm/llms/prompt_templates/factory.py +++ b/litellm/llms/prompt_templates/factory.py @@ -235,6 +235,12 @@ def mistral_api_pt(messages): """ new_messages = [] for m in messages: + special_keys = ["role", "content", "tool_calls"] + extra_args = {} + if isinstance(m, dict): + for k, v in m.items(): + if k not in special_keys: + extra_args[k] = v texts = "" if isinstance(m["content"], list): for c in m["content"]: @@ -244,7 +250,8 @@ def mistral_api_pt(messages): texts += c["text"] elif isinstance(m["content"], str): texts = m["content"] - new_m = {"role": m["role"], "content": texts} + + new_m = {"role": m["role"], "content": texts, **extra_args} if new_m["role"] == "tool" and m.get("name"): new_m["name"] = m["name"]