YAshhh29 commented on code in PR #69812:
URL: https://github.com/apache/airflow/pull/69812#discussion_r4111577430
##########
providers/openai/src/airflow/providers/openai/operators/openai.py:
##########
@@ -21,15 +21,43 @@
from functools import cached_property
from typing import TYPE_CHECKING, Any, ClassVar
+from pydantic import BaseModel, ValidationError
+
from airflow.providers.common.compat.sdk import BaseOperator, conf
from airflow.providers.openai.exceptions import OpenAIBatchJobException
from airflow.providers.openai.hooks.openai import OpenAIHook,
validate_execute_complete_event
from airflow.providers.openai.triggers.openai import OpenAIBatchTrigger
if TYPE_CHECKING:
+ from openai.types.responses import Response
+
from airflow.providers.common.compat.sdk import Context
+def _get_structured_response_details(response: Any) -> str:
Review Comment:
Good point, it's typed as `ParsedResponse[BaseModel]` now. I tried the same
typo on 2.37.0 and mypy flags `content.refusl` as `attr-defined`, where it
passed silently with `Any`.
##########
providers/openai/src/airflow/providers/openai/hooks/openai.py:
##########
@@ -273,6 +279,30 @@ def create_response(self, input: Any, model: str =
"gpt-4o-mini", **kwargs: Any)
"""
return self.conn.responses.create(model=model, input=input, **kwargs)
+ def parse_response(
+ self,
+ input: Any,
+ text_format: type[_TextFormatT],
+ model: str = "gpt-4o-mini",
+ **kwargs: Any,
Review Comment:
Makes sense, I applied your suggestion: `model` is second like in
`create_response`, and `text_format` is keyword-only like the SDK. There's also
a test that passing the model positionally works and `parse_response(prompt,
Person)` raises.
--
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]