mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-13 02:22:50 +00:00
Ensure that function_call_prompt extends system messages following its current schema
Fixes #11267
This commit is contained in:
@@ -3711,7 +3711,14 @@ def function_call_prompt(messages: list, functions: list):
|
||||
function_added_to_prompt = False
|
||||
for message in messages:
|
||||
if "system" in message["role"]:
|
||||
message["content"] += f""" {function_prompt}"""
|
||||
if isinstance(message["content"], str):
|
||||
message["content"] += f""" {function_prompt}"""
|
||||
else:
|
||||
message["content"].append({
|
||||
"type": "text",
|
||||
"text": f""" {function_prompt}""",
|
||||
"cache_control": {"type": "ephemeral"}
|
||||
})
|
||||
function_added_to_prompt = True
|
||||
|
||||
if function_added_to_prompt is False:
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
"""
|
||||
Test for GitHub issue #11267 - System message format issue with Ollama + tools
|
||||
"""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
@patch("litellm.add_function_to_prompt", True)
|
||||
def test_system_message_format_issue_reproduction():
|
||||
"""
|
||||
Reproduces the system message format bug from GitHub issue #11267.
|
||||
"""
|
||||
from litellm import completion
|
||||
|
||||
# Define test data directly from data.jsonl content
|
||||
model = "ollama/custom_model_name" # Use explicit Ollama model
|
||||
messages = [
|
||||
{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "What is the capital of France?"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "You are Claude Code, Anthropic's official CLI for Claude.",
|
||||
"cache_control": {"type": "ephemeral"}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
temperature = 1
|
||||
|
||||
# Add tools to trigger the bug - this is what causes the issue
|
||||
tools = [
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "get_weather",
|
||||
"description": "Get weather for a location",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"location": {"type": "string"}
|
||||
},
|
||||
"required": ["location"]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
response = completion(
|
||||
model=model,
|
||||
messages=messages,
|
||||
tools=tools,
|
||||
temperature=temperature,
|
||||
mock_response=True
|
||||
)
|
||||
|
||||
assert len(messages[1]["content"]) == 2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Testing system message format issue...")
|
||||
test_system_message_format_issue_reproduction()
|
||||
print("Tests completed!")
|
||||
Reference in New Issue
Block a user