Lee-W commented on code in PR #76801:
URL: https://github.com/apache/airflow/pull/76801#discussion_r4677662063
##########
providers/common/ai/tests/unit/common/ai/hooks/test_pydantic_ai.py:
##########
@@ -907,12 +921,55 @@ def test_param_builds_chain_in_order(self, registry,
infer_model_stub):
model = hook.get_conn()
assert isinstance(model, FallbackModel)
- assert model.models == [
+ assert get_chain_members(model) == [
infer_model_stub.models["openai:gpt-5.6-sol"],
infer_model_stub.models["anthropic:claude-opus-4-6"],
infer_model_stub.models["groq:llama-4"],
]
+ @pytest.mark.asyncio
+ async def test_response_is_stamped_with_the_member_that_answered(self,
registry, infer_model_stub):
+ def fail(messages, info):
+ raise ModelAPIError("primary", "down")
+
+ def answer(messages, info):
+ return ModelResponse(parts=[TextPart("answered")])
+
+ infer_model_stub.models["openai:gpt-5.6-sol"] = FunctionModel(fail,
model_name="primary-model")
+ infer_model_stub.models["anthropic:claude-opus-4-6"] = FunctionModel(
+ answer, model_name="second-model"
+ )
+ registry.add("primary", extra={"model": "openai:gpt-5.6-sol"})
+ registry.add("second", extra={"model": "anthropic:claude-opus-4-6"})
+
+ model = PydanticAIHook(llm_conn_id="primary",
fallback_conn_ids=["second"]).get_conn()
+ response = await model.request([ModelRequest.user_text_prompt("go")],
None, ModelRequestParameters())
+
+ assert get_member_model_id(response) == "function:second-model"
+ assert get_member_conn_id(response) == "second"
+
+ @pytest.mark.asyncio
+ async def
test_two_connections_serving_one_model_each_stamp_their_own_conn_id(
+ self, registry, infer_model_stub
+ ):
+ asked = []
+
+ def fail_then_answer(messages, info):
+ asked.append(info)
+ if len(asked) == 1:
+ raise ModelAPIError("shared", "down")
+ return ModelResponse(parts=[TextPart("answered")])
+
+ infer_model_stub.models["openai:gpt-5.6-sol"] =
FunctionModel(fail_then_answer, model_name="shared")
+ registry.add("primary", extra={"model": "openai:gpt-5.6-sol"})
+ registry.add("gateway", extra={"model": "openai:gpt-5.6-sol"})
+
+ model = PydanticAIHook(llm_conn_id="primary",
fallback_conn_ids=["gateway"]).get_conn()
+ response = await model.request([ModelRequest.user_text_prompt("go")],
None, ModelRequestParameters())
+
+ assert get_member_conn_id(response) == "gateway"
Review Comment:
Added. The list is read from the `MemberStampingModel` members because
`Model` has no `conn_id` for the type checker; a member built without the
wrapper shortens the list, so it fails the same assertion.
--
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]