mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-16 23:41:43 +00:00
Merge 9b0cbff907 into c2c2a623c0
This commit is contained in:
commit
2185ecc909
2 changed files with 78 additions and 0 deletions
|
|
@ -75,6 +75,7 @@ class _GenAIContentPart(TypedDict, total=False):
|
|||
class _GenAIFunctionDeclaration(TypedDict, total=False):
|
||||
name: ReadOnly[str]
|
||||
description: ReadOnly[str]
|
||||
parameters: ReadOnly[object]
|
||||
parametersJsonSchema: ReadOnly[object]
|
||||
|
||||
|
||||
|
|
@ -392,6 +393,8 @@ class GoogleGenAIAdapter:
|
|||
function_chunk["description"] = func_decl["description"]
|
||||
if "parametersJsonSchema" in func_decl:
|
||||
function_chunk["parameters"] = func_decl["parametersJsonSchema"]
|
||||
elif "parameters" in func_decl:
|
||||
function_chunk["parameters"] = func_decl["parameters"]
|
||||
|
||||
openai_tool: _JsonDict = {"type": "function", "function": function_chunk}
|
||||
openai_tools.append(openai_tool)
|
||||
|
|
|
|||
|
|
@ -1267,3 +1267,78 @@ def test_inline_data_backward_compatibility_text_only():
|
|||
content, str
|
||||
), "Content should be a string for text-only messages (backward compatibility)"
|
||||
assert content == "Hello, how are you?"
|
||||
|
||||
|
||||
def test_tools_transformation_parameters_field():
|
||||
from litellm.google_genai.adapters.transformation import GoogleGenAIAdapter
|
||||
|
||||
adapter = GoogleGenAIAdapter()
|
||||
|
||||
schema = {
|
||||
"type": "OBJECT",
|
||||
"properties": {"city": {"type": "STRING", "description": "City name"}},
|
||||
"required": ["city"],
|
||||
}
|
||||
tools = [
|
||||
{
|
||||
"functionDeclarations": [
|
||||
{
|
||||
"name": "get_weather",
|
||||
"description": "Get the weather for a city",
|
||||
"parameters": schema,
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
completion_request = adapter.translate_generate_content_to_completion(
|
||||
model="gpt-3.5-turbo",
|
||||
contents={"role": "user", "parts": [{"text": "Weather in Hanoi?"}]},
|
||||
tools=tools,
|
||||
)
|
||||
|
||||
function = completion_request["tools"][0]["function"]
|
||||
assert function["name"] == "get_weather"
|
||||
assert function["parameters"] == {
|
||||
"type": "object",
|
||||
"properties": {"city": {"type": "string", "description": "City name"}},
|
||||
"required": ["city"],
|
||||
}
|
||||
|
||||
|
||||
def test_tools_transformation_prefers_parameters_json_schema():
|
||||
from litellm.google_genai.adapters.transformation import GoogleGenAIAdapter
|
||||
|
||||
adapter = GoogleGenAIAdapter()
|
||||
|
||||
tools = [
|
||||
{
|
||||
"functionDeclarations": [
|
||||
{
|
||||
"name": "get_weather",
|
||||
"parameters": {
|
||||
"type": "OBJECT",
|
||||
"properties": {"ignored": {"type": "STRING"}},
|
||||
},
|
||||
"parametersJsonSchema": {
|
||||
"type": "object",
|
||||
"properties": {"city": {"type": "string"}},
|
||||
"required": ["city"],
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
completion_request = adapter.translate_generate_content_to_completion(
|
||||
model="gpt-3.5-turbo",
|
||||
contents={"role": "user", "parts": [{"text": "Weather in Hanoi?"}]},
|
||||
tools=tools,
|
||||
)
|
||||
|
||||
function = completion_request["tools"][0]["function"]
|
||||
assert function["parameters"] == {
|
||||
"type": "object",
|
||||
"properties": {"city": {"type": "string"}},
|
||||
"required": ["city"],
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue