mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-14 09:03:16 +00:00
fix(responses): omit tool strict when not provided
This commit is contained in:
parent
fd4cef22ea
commit
491c020c0a
2 changed files with 30 additions and 1 deletions
|
|
@ -2928,7 +2928,7 @@ class LiteLLMCompletionResponsesConfig:
|
|||
"name": typed_tool.get("name") or "",
|
||||
"description": typed_tool.get("description") or "",
|
||||
"parameters": parameters,
|
||||
"strict": typed_tool.get("strict", False) or False,
|
||||
**({"strict": typed_tool["strict"]} if "strict" in typed_tool else {}),
|
||||
},
|
||||
}
|
||||
if tool.get("cache_control"):
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ from openai.types.responses.response_function_web_search import (
|
|||
ActionSearchSource,
|
||||
ResponseFunctionWebSearch,
|
||||
)
|
||||
from openai.types.responses.tool_param import FunctionToolParam
|
||||
from pydantic import TypeAdapter, ValidationError
|
||||
|
||||
import litellm
|
||||
|
|
@ -1699,6 +1700,34 @@ def _chat_response_with_tool_search_call(
|
|||
class TestToolTransformation:
|
||||
"""Test cases for tool transformation from Responses API to Chat Completion format"""
|
||||
|
||||
@pytest.mark.parametrize("strict", [None, False, True])
|
||||
def test_responses_function_tool_preserves_strict_presence(self, strict: bool | None) -> None:
|
||||
tool: Final = cast(
|
||||
FunctionToolParam,
|
||||
{
|
||||
"type": "function",
|
||||
"name": "get_weather",
|
||||
"description": "Look up the weather",
|
||||
"parameters": {"type": "object", "properties": {"city": {"type": "string"}}},
|
||||
**({"strict": strict} if strict is not None else {}),
|
||||
},
|
||||
)
|
||||
chat_tools: Final = LiteLLMCompletionResponsesConfig.transform_responses_api_tools_to_chat_completion_tools(
|
||||
tools=[tool]
|
||||
)[0]
|
||||
|
||||
assert chat_tools == [
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": tool["name"],
|
||||
"description": tool.get("description"),
|
||||
"parameters": tool["parameters"],
|
||||
**({"strict": strict} if strict is not None else {}),
|
||||
},
|
||||
}
|
||||
]
|
||||
|
||||
def test_transform_vertex_ai_tools(self):
|
||||
"""Test that Vertex AI tools are passed through as-is"""
|
||||
from litellm.types.llms.vertex_ai import VertexToolName
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue