mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
[Fix] Magistral small system prompt diverges too much from the official recommendation (#12007)
* fix mistral _get_mistral_reasoning_system_prompt * fix test_get_mistral_reasoning_system_prompt
This commit is contained in:
parent
8da22be199
commit
1467a99aab
2 changed files with 20 additions and 11 deletions
|
|
@ -6,7 +6,7 @@ Why separate file? Make it easy to see how transformation works
|
|||
Docs - https://docs.mistral.ai/api/
|
||||
"""
|
||||
|
||||
from typing import Any, Coroutine, List, Literal, Optional, Tuple, Union, overload, cast
|
||||
from typing import Any, Coroutine, List, Literal, Optional, Tuple, Union, cast, overload
|
||||
|
||||
from litellm.litellm_core_utils.prompt_templates.common_utils import (
|
||||
handle_messages_with_content_list_to_str_conversion,
|
||||
|
|
@ -107,15 +107,28 @@ class MistralConfig(OpenAIGPTConfig):
|
|||
def _get_mistral_reasoning_system_prompt() -> str:
|
||||
"""
|
||||
Returns the system prompt for Mistral reasoning models.
|
||||
Based on Mistral's documentation: https://docs.mistral.ai/capabilities/reasoning/
|
||||
Based on Mistral's documentation: https://huggingface.co/mistralai/Magistral-Small-2506
|
||||
|
||||
Mistral recommends the following system prompt for reasoning:
|
||||
"""
|
||||
return """When solving problems, think step-by-step in <think> tags before providing your final answer. Use the following format:
|
||||
return """
|
||||
<s>[SYSTEM_PROMPT]system_prompt
|
||||
A user will ask you to solve a task. You should first draft your thinking process (inner monologue) until you have derived the final answer. Afterwards, write a self-contained summary of your thoughts (i.e. your summary should be succinct but contain all the critical steps you needed to reach the conclusion). You should use Markdown to format your response. Write both your thoughts and summary in the same language as the task posed by the user. NEVER use \boxed{} in your response.
|
||||
|
||||
<think>
|
||||
Your step-by-step reasoning process. Be thorough and work through the problem carefully.
|
||||
</think>
|
||||
Your thinking process must follow the template below:
|
||||
<think>
|
||||
Your thoughts or/and draft, like working through an exercise on scratch paper. Be as casual and as long as you want until you are confident to generate a correct answer.
|
||||
</think>
|
||||
|
||||
Then provide a clear, concise answer based on your reasoning."""
|
||||
Here, provide a concise summary that reflects your reasoning and presents a clear final answer to the user. Don't mention that this is a summary.
|
||||
|
||||
Problem:
|
||||
|
||||
[/SYSTEM_PROMPT][INST]user_message[/INST]<think>
|
||||
reasoning_traces
|
||||
</think>
|
||||
assistant_response</s>[INST]user_message[/INST]
|
||||
"""
|
||||
|
||||
def map_openai_params(
|
||||
self,
|
||||
|
|
|
|||
|
|
@ -95,10 +95,6 @@ class TestMistralReasoningSupport:
|
|||
def test_get_mistral_reasoning_system_prompt(self):
|
||||
"""Test that the reasoning system prompt is properly formatted."""
|
||||
prompt = MistralConfig._get_mistral_reasoning_system_prompt()
|
||||
|
||||
assert "<think>" in prompt
|
||||
assert "</think>" in prompt
|
||||
assert "step-by-step" in prompt
|
||||
assert isinstance(prompt, str)
|
||||
assert len(prompt) > 50 # Ensure it's not empty
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue