mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-11 03:38:38 +00:00
fix only apply vertex $schema fixes
This commit is contained in:
parent
c5f7182547
commit
7b2b8d32ce
2 changed files with 23 additions and 6 deletions
|
|
@ -164,7 +164,12 @@ def _build_vertex_schema(parameters: dict):
|
|||
# 4. Suppress unnecessary title generation:
|
||||
# * https://github.com/pydantic/pydantic/issues/1051
|
||||
# * http://cl/586221780
|
||||
strip_titles(parameters)
|
||||
strip_field(parameters, field_name="title")
|
||||
|
||||
strip_field(
|
||||
parameters, field_name="$schema"
|
||||
) # 5. Remove $schema - json schema value, not supported by OpenAPI - causes vertex errors.
|
||||
|
||||
return parameters
|
||||
|
||||
|
||||
|
|
@ -245,14 +250,14 @@ def add_object_type(schema):
|
|||
add_object_type(items)
|
||||
|
||||
|
||||
def strip_titles(schema):
|
||||
schema.pop("title", None)
|
||||
def strip_field(schema, field_name: str):
|
||||
schema.pop(field_name, None)
|
||||
|
||||
properties = schema.get("properties", None)
|
||||
if properties is not None:
|
||||
for name, value in properties.items():
|
||||
strip_titles(value)
|
||||
strip_field(value, field_name)
|
||||
|
||||
items = schema.get("items", None)
|
||||
if items is not None:
|
||||
strip_titles(items)
|
||||
strip_field(items, field_name)
|
||||
|
|
|
|||
|
|
@ -400,14 +400,26 @@ class VertexGeminiConfig:
|
|||
value = _remove_additional_properties(value)
|
||||
# remove 'strict' from tools
|
||||
value = _remove_strict_from_schema(value)
|
||||
|
||||
for tool in value:
|
||||
openai_function_object: Optional[ChatCompletionToolParamFunctionChunk] = (
|
||||
None
|
||||
)
|
||||
if "function" in tool: # tools list
|
||||
openai_function_object = ChatCompletionToolParamFunctionChunk( # type: ignore
|
||||
_openai_function_object = ChatCompletionToolParamFunctionChunk( # type: ignore
|
||||
**tool["function"]
|
||||
)
|
||||
|
||||
if (
|
||||
"parameters" in _openai_function_object
|
||||
and _openai_function_object["parameters"] is not None
|
||||
): # OPENAI accepts JSON Schema, Google accepts OpenAPI schema.
|
||||
_openai_function_object["parameters"] = _build_vertex_schema(
|
||||
_openai_function_object["parameters"]
|
||||
)
|
||||
|
||||
openai_function_object = _openai_function_object
|
||||
|
||||
elif "name" in tool: # functions list
|
||||
openai_function_object = ChatCompletionToolParamFunctionChunk(**tool) # type: ignore
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue