gopidesupavan commented on PR #62816:
URL: https://github.com/apache/airflow/pull/62816#issuecomment-4000582807
> Hi @kaxil
>
> I have taken your "thin hook" suggestion into consideration. However, I
believe that relying solely on environment variables might not be sufficient
for Airflow users; being able to fetch configurations directly from connection
extras is highly valuable.
>
> I've reviewed all the current pydanticai providers and noticed that only
AzureProvider and LiteLLMProvider require their own specific parameters instead
of the standard base_url.
>
> To handle this distinction cleanly without over-engineering or building
registries, I am planning to introduce a simple _build_provider_kwargs(conn)
helper method. This method will parse the connection and return the appropriate
kwargs dictionary to feed directly into the resolved provider_cls.
>
> What are your thoughts on proceeding with this approach? Does this align
better with the design goals?
>
> ```
> def _build_provider_kwargs(
> provider_cls: type,
> api_key: str | None,
> base_url: str | None,
> extra: dict[str, Any],
> ) -> dict[str, Any]:
> sig = inspect.signature(provider_cls.__init__)
> accepted: set[str] = {
> name
> for name, param in sig.parameters.items()
> if name != "self"
> and param.kind
> not in (inspect.Parameter.VAR_POSITIONAL,
inspect.Parameter.VAR_KEYWORD)
> }
>
> candidates: dict[str, Any] = {
> "api_key": api_key,
> "base_url": base_url,
> # Alias used by AzureProvider instead of base_url
> "azure_endpoint": base_url,
> # Alias used by LiteLLMProvider instead of base_url
> "api_base": base_url,
> **{k: v for k, v in extra.items() if k != "model"},
> }
>
> return {k: v for k, v in candidates.items() if k in accepted and v
is not None}
>
> def get_conn(self) -> Model:
> .....
> if api_key or base_url:
> provider_name = model_name.split(":")[0] if ":" in model_name
else "openai"
> provider_cls = infer_provider_class(provider_name)
> kwargs: dict[str, Any] =
self._build_provider_kwargs(provider_cls, api_key, base_url, extra)
> try:
> provider = provider_cls(**kwargs)
> except TypeError:
> provider = infer_provider(provider_name)
> ....
> ```
What if we simply read key-value pairs from conn_extras and pass them
directly to the provider? We could define a schema in the connection extras
like {provider_extra_args: {...}}, then document that this field and point
users to the pydantic-ai docs to configure it correctly themselves ?
--
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]