You've already forked adk-python
mirror of
https://github.com/encounter/adk-python.git
synced 2026-03-30 10:57:20 -07:00
reformat file structure
This commit is contained in:
@@ -311,46 +311,45 @@ TYPE_LABELS = {
|
||||
|
||||
|
||||
def _schema_to_dict(schema: types.Schema) -> dict:
|
||||
"""
|
||||
Recursively converts a types.Schema to a pure-python dict
|
||||
with all enum values written as lower-case strings.
|
||||
"""
|
||||
# Dump without json encoding so we still get Enum members
|
||||
schema_dict = schema.model_dump(exclude_none=True)
|
||||
"""
|
||||
Recursively converts a types.Schema to a pure-python dict
|
||||
with all enum values written as lower-case strings.
|
||||
"""
|
||||
# Dump without json encoding so we still get Enum members
|
||||
schema_dict = schema.model_dump(exclude_none=True)
|
||||
|
||||
# ---- normalise this level ------------------------------------------------
|
||||
if "type" in schema_dict:
|
||||
# schema_dict["type"] can be an Enum or a str
|
||||
t = schema_dict["type"]
|
||||
schema_dict["type"] = (t.value if isinstance(t, types.Type) else t).lower()
|
||||
# ---- normalise this level ------------------------------------------------
|
||||
if "type" in schema_dict:
|
||||
# schema_dict["type"] can be an Enum or a str
|
||||
t = schema_dict["type"]
|
||||
schema_dict["type"] = (t.value if isinstance(t, types.Type) else t).lower()
|
||||
|
||||
# ---- recurse into `items` -----------------------------------------------
|
||||
if "items" in schema_dict:
|
||||
schema_dict["items"] = _schema_to_dict(
|
||||
schema.items if isinstance(schema.items, types.Schema)
|
||||
else types.Schema.model_validate(schema_dict["items"])
|
||||
)
|
||||
# ---- recurse into `items` -----------------------------------------------
|
||||
if "items" in schema_dict:
|
||||
schema_dict["items"] = _schema_to_dict(
|
||||
schema.items
|
||||
if isinstance(schema.items, types.Schema)
|
||||
else types.Schema.model_validate(schema_dict["items"])
|
||||
)
|
||||
|
||||
# ---- recurse into `properties` ------------------------------------------
|
||||
if "properties" in schema_dict:
|
||||
new_props = {}
|
||||
for key, value in schema_dict["properties"].items():
|
||||
# value is a dict → rebuild a Schema object and recurse
|
||||
if isinstance(value, dict):
|
||||
new_props[key] = _schema_to_dict(
|
||||
types.Schema.model_validate(value)
|
||||
)
|
||||
# value is already a Schema instance
|
||||
elif isinstance(value, types.Schema):
|
||||
new_props[key] = _schema_to_dict(value)
|
||||
# plain dict without nested schemas
|
||||
else:
|
||||
new_props[key] = value
|
||||
if "type" in new_props[key]:
|
||||
new_props[key]["type"] = new_props[key]["type"].lower()
|
||||
schema_dict["properties"] = new_props
|
||||
# ---- recurse into `properties` ------------------------------------------
|
||||
if "properties" in schema_dict:
|
||||
new_props = {}
|
||||
for key, value in schema_dict["properties"].items():
|
||||
# value is a dict → rebuild a Schema object and recurse
|
||||
if isinstance(value, dict):
|
||||
new_props[key] = _schema_to_dict(types.Schema.model_validate(value))
|
||||
# value is already a Schema instance
|
||||
elif isinstance(value, types.Schema):
|
||||
new_props[key] = _schema_to_dict(value)
|
||||
# plain dict without nested schemas
|
||||
else:
|
||||
new_props[key] = value
|
||||
if "type" in new_props[key]:
|
||||
new_props[key]["type"] = new_props[key]["type"].lower()
|
||||
schema_dict["properties"] = new_props
|
||||
|
||||
return schema_dict
|
||||
return schema_dict
|
||||
|
||||
|
||||
def _function_declaration_to_tool_param(
|
||||
|
||||
@@ -691,10 +691,10 @@ function_declaration_test_cases = [
|
||||
"inner_key": types.Schema(
|
||||
type=types.Type.STRING,
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
)
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user