The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test_completion_mistral_api_mistral_large_function_call
Ishaan Jaff7f63e7c15a18
diff --git a/litellm/llms/mistral/mistral_chat_transformation.py b/litellm/llms/mistral/mistral_chat_transformation.pyindex 6174952aae6..a93b1cae2a9 100644--- a/litellm/llms/mistral/mistral_chat_transformation.py+++ b/litellm/llms/mistral/mistral_chat_transformation.py@@ -14,6 +14,7 @@ from litellm.litellm_core_utils.prompt_templates.common_utils import ()from litellm.llms.openai.chat.gpt_transformation import OpenAIGPTConfigfrom litellm.secret_managers.main import get_secret_str+from litellm.types.llms.mistral import MistralToolCallMessagefrom litellm.types.llms.openai import AllMessageValues@@ -172,6 +173,7 @@ class MistralConfig(OpenAIGPTConfig):new_messages: List[AllMessageValues] = []for m in messages:m = MistralConfig._handle_name_in_message(m)+ m = MistralConfig._handle_tool_call_message(m)m = strip_none_values_from_message(m) # prevents 'extra_forbidden' errornew_messages.append(m)@@ -190,3 +192,21 @@ class MistralConfig(OpenAIGPTConfig):message.pop("name", None) # type: ignorereturn message++ @classmethod+ def _handle_tool_call_message(cls, message: AllMessageValues) -> AllMessageValues:+ """+ Mistral API only supports tool_calls in Messages in `MistralToolCallMessage` spec+ """+ _tool_calls = message.get("tool_calls")+ mistral_tool_calls: List[MistralToolCallMessage] = []+ if _tool_calls is not None:+ for _tool in _tool_calls:+ _tool_call_message = MistralToolCallMessage(+ id=_tool.get("id"),+ type="function",+ function=_tool.get("function"), # type: ignore+ )+ mistral_tool_calls.append(_tool_call_message)+ message["tool_calls"] = mistral_tool_calls # type: ignore+ return messagediff --git a/litellm/types/llms/mistral.py b/litellm/types/llms/mistral.pynew file mode 100644index 00000000000..e9563a9ae3f--- /dev/null+++ b/litellm/types/llms/mistral.py@@ -0,0 +1,12 @@+from typing import List, Literal, Optional, TypedDict, Union+++class FunctionCall(TypedDict):+ name: Optional[str]+ arguments: Optional[Union[str, dict]]+++class MistralToolCallMessage(TypedDict):+ id: Optional[str]+ type: Literal["function"]+ function: Optional[FunctionCall]diff --git a/tests/local_testing/test_completion.py b/tests/local_testing/test_completion.pyindex 24a43c01837..6da4a6cf6be 100644--- a/tests/local_testing/test_completion.py+++ b/tests/local_testing/test_completion.py@@ -1009,7 +1009,7 @@ def test_completion_mistral_api_mistral_large_function_call():try:# test without max tokensresponse = completion(- model="mistral/mistral-large-latest",+ model="mistral/open-mistral-7b",messages=messages,tools=tools,tool_choice="auto",