kaxil commented on code in PR #76975:
URL: https://github.com/apache/airflow/pull/76975#discussion_r4623402878


##########
providers/common/ai/src/airflow/providers/common/ai/batch/dispatch.py:
##########
@@ -49,20 +49,34 @@
 
 if TYPE_CHECKING:
     from airflow.providers.common.ai.batch.base import BatchAdapter
+    from airflow.providers.common.ai.batch.output_schema import OutputSpec
     from airflow.sdk import Connection
 
 ENTRY_POINT_GROUP = "airflow.providers.common.ai.batch_adapters"
 
 #: adapter name -> (module path, class name), resolved lazily by 
:func:`import_adapter_class`.
 _ADAPTER_MODULES: dict[str, tuple[str, str]] = {
-    "openai": ("airflow.providers.common.ai.batch.openai", 
"OpenAIBatchAdapter"),
-    "anthropic": ("airflow.providers.common.ai.batch.anthropic", 
"AnthropicBatchAdapter"),
+    "openai": ("airflow.providers.common.ai.batch.pydantic_ai_backend", 
"OpenAIBatchAdapter"),
+    "anthropic": ("airflow.providers.common.ai.batch.pydantic_ai_backend", 
"AnthropicBatchAdapter"),
+    "google": ("airflow.providers.common.ai.batch.pydantic_ai_backend", 
"GoogleBatchAdapter"),
 }
 
 #: model_id prefix -> the adapter that serves it under another name. 
``openai-chat`` is
-#: pydantic-ai's Chat Completions prefix, and Chat Completions is what the 
``openai`` adapter submits.
+#: pydantic-ai's Chat Completions prefix; the ``openai`` adapter batches on 
the Responses API
+#: instead and builds the ``openai:`` model of the same name.
 _ADAPTER_ALIASES: dict[str, str] = {"openai-chat": "openai"}

Review Comment:
   Added, and a test builds a real Responses model from an `openai-responses:` 
id.



##########
providers/common/ai/tests/unit/common/ai/operators/test_llm_batch.py:
##########
@@ -480,10 +483,84 @@ def 
test_stale_batch_is_cancelled_through_the_connection_that_owns_it(self, fake
             with pytest.raises(TaskDeferred):
                 _make_operator(result_path=result_path, deferrable=True, 
llm_conn_id="account_b").execute(ctx)
 
-        build_adapter.assert_any_call("openai", llm_conn_id="account_a")
+        build_adapter.assert_any_call(
+            "openai", llm_conn_id="account_a", model_id="openai:gpt-5", 
batch_handle=None
+        )
         assert fake_adapter.cancel_calls == ["batch_1"]
         assert len(fake_adapter.submit_calls) == 2
 
+    def test_stale_batch_is_cancelled_through_the_model_it_was_submitted_with(
+        self, fake_adapter, result_path
+    ):
+        ctx = _context()
+        with _running(fake_adapter) as build_adapter:
+            with pytest.raises(TaskDeferred):
+                _make_operator(result_path=result_path, deferrable=True, 
model_id="openai:gpt-5").execute(ctx)
+
+            with pytest.raises(TaskDeferred):
+                _make_operator(
+                    result_path=result_path, deferrable=True, 
model_id="openai:gpt-5-mini"
+                ).execute(ctx)
+
+        build_adapter.assert_any_call(
+            "openai", llm_conn_id="my_openai", model_id="openai:gpt-5", 
batch_handle=None
+        )
+        assert fake_adapter.cancel_calls == ["batch_1"]
+
+    def 
test_stale_batch_without_a_recorded_model_is_cancelled_through_the_current_adapter(
+        self, fake_adapter, result_path
+    ):
+        ctx = _context()
+        with _running(fake_adapter) as build_adapter:
+            with pytest.raises(TaskDeferred):
+                _make_operator(result_path=result_path, 
deferrable=True).execute(ctx)
+            key, _ = LLMBatchOperator._identity(ctx)
+            record = state_module.read_state(ObjectStoragePath(result_path), 
key)
+            with mock.patch.object(
+                state_module, "read_state", autospec=True, 
return_value=replace(record, model_id=None)
+            ):
+                with pytest.raises(TaskDeferred):
+                    _make_operator(requests=["changed"], 
result_path=result_path, deferrable=True).execute(
+                        ctx
+                    )
+
+        build_adapter.assert_not_called()
+        assert fake_adapter.cancel_calls == ["batch_1"]
+
+
+class TestCompletionWindow:
+    def 
test_a_non_default_window_is_flagged_as_ignored_by_the_pydantic_ai_backends(
+        self, fake_adapter, result_path, caplog
+    ):
+        with _running(fake_adapter), caplog.at_level(logging.WARNING):
+            with pytest.raises(TaskDeferred):
+                _make_operator(
+                    result_path=result_path,
+                    deferrable=True,
+                    model_id="anthropic:claude-sonnet-4-5",
+                    completion_window="12h",
+                ).execute(_context())
+
+        assert any("completion_window" in r.getMessage() for r in 
caplog.records)
+
+    def test_a_non_default_window_is_flagged_for_openai_too(self, 
fake_adapter, result_path, caplog):

Review Comment:
   By the time this got merged with #76974 the operator tests had become three 
different cases, so I left those. Merged the two 
`..._built_from_the_connection_hook` dispatch tests into one parametrized over 
all three adapters.



-- 
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]

Reply via email to