SameerMesiah97 commented on code in PR #70096:
URL: https://github.com/apache/airflow/pull/70096#discussion_r3611202973
##########
providers/common/ai/src/airflow/providers/common/ai/utils/tool_definition.py:
##########
@@ -42,3 +43,55 @@ def return_schema_kwargs(schema: dict[str, Any]) ->
dict[str, Any]:
if _SUPPORTS_RETURN_SCHEMA:
return {"return_schema": schema}
return {}
+
+
+def _fragment_to_core_schema(fragment: dict[str, Any]) ->
core_schema.CoreSchema:
+ any_of = fragment.get("anyOf")
+ if isinstance(any_of, list):
+ choices: list[core_schema.CoreSchema | tuple[core_schema.CoreSchema,
str]] = [
+ _fragment_to_core_schema(choice) for choice in any_of if
isinstance(choice, dict)
+ ]
+ return core_schema.union_schema(choices) if choices else
core_schema.any_schema()
+
+ schema_type = fragment.get("type")
+ if isinstance(schema_type, list):
+ choices = [
+ _fragment_to_core_schema({**fragment, "type": item})
+ for item in schema_type
+ if isinstance(item, str)
+ ]
+ return core_schema.union_schema(choices) if choices else
core_schema.any_schema()
+
+ match schema_type:
+ case "string":
+ return core_schema.str_schema()
+ case "integer":
+ return core_schema.int_schema()
+ case "number":
+ return core_schema.float_schema()
+ case "boolean":
+ return core_schema.bool_schema()
+ case "null":
+ return core_schema.none_schema()
+ case "array":
+ items = fragment.get("items")
+ return core_schema.list_schema(
+ _fragment_to_core_schema(items) if isinstance(items, dict)
else None
+ )
+ case "object":
+ return core_schema.dict_schema()
Review Comment:
Is there a need for recursively validating nested properties here like for
arrays above? Is this intentional because Common AI tool parameters are
expected to be flat, or should nested object schemas also be validated
recursively?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]