FrankYang0529 commented on code in PR #74729:
URL: https://github.com/apache/airflow/pull/74729#discussion_r4321419701
##########
providers/common/ai/tests/unit/common/ai/operators/test_agent.py:
##########
@@ -1032,6 +1046,99 @@ def test_execute_structured_output(self, mock_hook_cls,
make_mock_run_result):
assert result.text == "Great"
assert result.score == 0.95
+ @pytest.mark.parametrize(
+ "output_type",
+ [
+ pytest.param([Summary, int], id="list-of-output-types"),
+ pytest.param(ToolOutput(Summary), id="output-marker"),
+ pytest.param(_summarize, id="output-function"),
+ pytest.param(SummaryAlias, id="type-alias"),
+ pytest.param(SummaryNewType, id="new-type"),
+ ],
+ )
+ @patch("airflow.providers.common.ai.operators.agent.PydanticAIHook",
autospec=True)
+ def test_execute_dumps_a_model_the_worker_does_not_register(
+ self, mock_hook_cls, make_mock_run_result, output_type
+ ):
+ mock_hook_cls.get_hook.return_value.create_agent.return_value =
_make_mock_agent(
+ Summary(text="ok"), make_mock_run_result
+ )
+ op = AgentOperator(
+ task_id="test", prompt="Analyze this", llm_conn_id="my_llm",
output_type=output_type
+ )
+
+ result = op.execute(context=MagicMock())
+
+ assert result == {"text": "ok", "score": 0.0}
+
+ @requires_typed_xcom
+ @pytest.mark.parametrize(
+ ("output_type", "output", "expected", "serialize_output"),
+ [
+ pytest.param(
+ ToolOutput(list[Summary]),
+ [Summary(text="ok")],
+ [{"text": "ok", "score": 0.0}],
+ False,
+ id="list-in-output-marker",
+ ),
+ pytest.param(
+ [list[Summary], int],
+ [Summary(text="ok")],
+ [{"text": "ok", "score": 0.0}],
+ False,
+ id="list-in-list-of-output-types",
+ ),
+ pytest.param(
+ ToolOutput(tuple[Summary, int]),
+ (Summary(text="ok"), 1),
+ ({"text": "ok", "score": 0.0}, 1),
+ False,
+ id="tuple-in-output-marker",
+ ),
+ pytest.param(
+ ToolOutput(dict[str, Summary]),
+ {"a": Summary(text="ok")},
+ {"a": {"text": "ok", "score": 0.0}},
+ False,
+ id="dict-in-output-marker",
+ ),
+ pytest.param(
+ ToolOutput(list[Summary]),
+ [Summary(text="ok")],
+ [{"text": "ok", "score": 0.0}],
+ True,
+ id="list-in-output-marker-with-serialize-output",
+ ),
+ pytest.param(
+ ToolOutput(LinkedSummary),
+ LinkedSummary(kind=SummaryKind.SHORT,
url=HttpUrl("https://example.com/a")),
+ {"kind": "short", "url": "https://example.com/a"},
+ False,
+ id="enum-and-url-fields",
+ ),
+ ],
+ )
+ @patch("airflow.providers.common.ai.operators.agent.PydanticAIHook",
autospec=True)
+ def test_execute_pushes_each_model_the_worker_does_not_register_as_json(
Review Comment:
Added `test_execute_keeps_each_model_the_worker_registers` with
`list[Summary]`, `tuple[Summary, int]` and `dict[str, Summary]` rows.
--
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]