mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 11:43:54 +00:00
Azure OpenAI improvements - o3 native streaming, improved tool call + response format handling (#8292)
* fix(convert_dict_to_response.py): only convert if response is the response_format tool call passed in Fixes https://github.com/BerriAI/litellm/issues/8241 * fix(gpt_transformation.py): makes sure response format / tools conversion doesn't remove previous tool calls * refactor(gpt_transformation.py): refactor out json schema converstion to base config keeps logic consistent across providers * fix(o_series_transformation.py): support o3 mini native streaming Fixes https://github.com/BerriAI/litellm/issues/8274 * fix(gpt_transformation.py): remove unused variables * test: update test
This commit is contained in:
parent
1b267edf13
commit
0038443b1e
7 changed files with 260 additions and 55 deletions
|
@ -283,3 +283,156 @@ def test_azure_openai_gpt_4o_naming(monkeypatch):
|
|||
print(mock_post.call_args.kwargs)
|
||||
|
||||
assert "tool_calls" not in mock_post.call_args.kwargs
|
||||
|
||||
|
||||
def test_azure_gpt_4o_with_tool_call_and_response_format():
|
||||
from litellm import completion
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel
|
||||
import litellm
|
||||
|
||||
class InvestigationOutput(BaseModel):
|
||||
alert_explanation: Optional[str] = None
|
||||
investigation: Optional[str] = None
|
||||
conclusions_and_possible_root_causes: Optional[str] = None
|
||||
next_steps: Optional[str] = None
|
||||
related_logs: Optional[str] = None
|
||||
app_or_infra: Optional[str] = None
|
||||
external_links: Optional[str] = None
|
||||
|
||||
tools = [
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "get_current_time",
|
||||
"description": "Returns the current date and time",
|
||||
"strict": True,
|
||||
"parameters": {
|
||||
"properties": {
|
||||
"timezone": {
|
||||
"type": "string",
|
||||
"description": "The timezone to get the current time for (e.g., 'UTC', 'America/New_York')",
|
||||
}
|
||||
},
|
||||
"required": ["timezone"],
|
||||
"type": "object",
|
||||
"additionalProperties": False,
|
||||
},
|
||||
},
|
||||
}
|
||||
]
|
||||
|
||||
response = litellm.completion(
|
||||
model="azure/gpt-4o",
|
||||
messages=[
|
||||
{
|
||||
"role": "system",
|
||||
"content": "You are a tool-calling AI assist provided with common devops and IT tools that you can use to troubleshoot problems or answer questions.\nWhenever possible you MUST first use tools to investigate then answer the question.",
|
||||
},
|
||||
{"role": "user", "content": "What is the current date and time in NYC?"},
|
||||
],
|
||||
drop_params=True,
|
||||
temperature=0.00000001,
|
||||
tools=tools,
|
||||
tool_choice="auto",
|
||||
response_format=InvestigationOutput, # commenting this line will cause the output to be correct
|
||||
)
|
||||
|
||||
assert response.choices[0].finish_reason == "tool_calls"
|
||||
|
||||
print(response.to_json())
|
||||
|
||||
|
||||
def test_map_openai_params():
|
||||
"""
|
||||
Ensure response_format does not override tools
|
||||
"""
|
||||
from litellm.llms.azure.chat.gpt_transformation import AzureOpenAIConfig
|
||||
|
||||
azure_openai_config = AzureOpenAIConfig()
|
||||
tools = [
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "get_current_time",
|
||||
"description": "Returns the current date and time",
|
||||
"strict": True,
|
||||
"parameters": {
|
||||
"properties": {
|
||||
"timezone": {
|
||||
"type": "string",
|
||||
"description": "The timezone to get the current time for (e.g., 'UTC', 'America/New_York')",
|
||||
}
|
||||
},
|
||||
"required": ["timezone"],
|
||||
"type": "object",
|
||||
"additionalProperties": False,
|
||||
},
|
||||
},
|
||||
}
|
||||
]
|
||||
received_args = {
|
||||
"non_default_params": {
|
||||
"temperature": 1e-08,
|
||||
"response_format": {
|
||||
"type": "json_schema",
|
||||
"json_schema": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"alert_explanation": {
|
||||
"anyOf": [{"type": "string"}, {"type": "null"}],
|
||||
"title": "Alert Explanation",
|
||||
},
|
||||
"investigation": {
|
||||
"anyOf": [{"type": "string"}, {"type": "null"}],
|
||||
"title": "Investigation",
|
||||
},
|
||||
"conclusions_and_possible_root_causes": {
|
||||
"anyOf": [{"type": "string"}, {"type": "null"}],
|
||||
"title": "Conclusions And Possible Root Causes",
|
||||
},
|
||||
"next_steps": {
|
||||
"anyOf": [{"type": "string"}, {"type": "null"}],
|
||||
"title": "Next Steps",
|
||||
},
|
||||
"related_logs": {
|
||||
"anyOf": [{"type": "string"}, {"type": "null"}],
|
||||
"title": "Related Logs",
|
||||
},
|
||||
"app_or_infra": {
|
||||
"anyOf": [{"type": "string"}, {"type": "null"}],
|
||||
"title": "App Or Infra",
|
||||
},
|
||||
"external_links": {
|
||||
"anyOf": [{"type": "string"}, {"type": "null"}],
|
||||
"title": "External Links",
|
||||
},
|
||||
},
|
||||
"title": "InvestigationOutput",
|
||||
"type": "object",
|
||||
"additionalProperties": False,
|
||||
"required": [
|
||||
"alert_explanation",
|
||||
"investigation",
|
||||
"conclusions_and_possible_root_causes",
|
||||
"next_steps",
|
||||
"related_logs",
|
||||
"app_or_infra",
|
||||
"external_links",
|
||||
],
|
||||
},
|
||||
"name": "InvestigationOutput",
|
||||
"strict": True,
|
||||
},
|
||||
},
|
||||
"tools": tools,
|
||||
"tool_choice": "auto",
|
||||
},
|
||||
"optional_params": {},
|
||||
"model": "gpt-4o",
|
||||
"drop_params": True,
|
||||
"api_version": "2024-02-15-preview",
|
||||
}
|
||||
optional_params = azure_openai_config.map_openai_params(**received_args)
|
||||
assert "tools" in optional_params
|
||||
assert len(optional_params["tools"]) > 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue