Repository navigation
Description
Description
Add a pydanticai_huggingface connection type so a Common AI task can point at a dedicated Hugging Face Inference Endpoint by name.
Common AI (apache-airflow-providers-common-ai) already reaches Hugging Face Inference Providers: a pydanticai connection with the huggingface: model prefix and the access token in Password. A dedicated Inference Endpoint is harder. The user copies the endpoint URL into the connection by hand and has to keep it in sync with the endpoint. The token is also entered twice, once on the huggingface connection and once on the pydanticai one.
pydantic-ai's HuggingFaceProvider already accepts either provider_name (routing through Inference Providers) or base_url (a dedicated endpoint), so this is connection plumbing and no new model integration.
Scope
- A
pydanticai_huggingfaceconnection type shipped by the Hugging Face provider behind a[common.ai]extra, followingPydanticAISnowflakeHook(pydanticai_snowflake) in the Snowflake provider. - Extra fields for
endpoint_nameandnamespace, resolved to the endpoint URL with the hook methods from Manage Hugging Face Inference Endpoints from Dags #77830, or forprovider_name. - A decision on credential reuse: either one connection serves both
HuggingFaceHookand Common AI, or the new type points at ahuggingfaceconnection ID. The PR states which one it chose and why.
This depends on #77830 for the endpoint hook methods.
Done when
@task.llm(llm_conn_id=...)reaches a dedicated endpoint whenendpoint_nameis set, and Inference Providers whenprovider_nameis set.- Common AI's
model_providers.rsttable has a Hugging Face row for the new connection type, and the Hugging Face provider docs have a connection page for it. - The end-to-end scenarios below have all been run against a real endpoint, and the PR description carries the evidence.
End-to-end verification
The whole feature is a URL lookup against a live service plus credential handling, which a mocked HfApi cannot prove. Keep the PR in draft until the evidence listed further down is in its description.
Setup:
- A live Airflow from
breeze start-airflow, with both providers installed from the PR branch. Create the connection in the UI and trigger the Dags there. - A real Hugging Face token and a small CPU Inference Endpoint in the test namespace (
airflow-hfby default) serving a small text-generation model. Redact the token from anything pasted into the PR. - Pause or delete the endpoint after the last scenario. It is billed while it runs.
Scenarios:
- Connection form. The new type appears in the connection-type list with
endpoint_name,namespaceandprovider_namefields, and saving it works. - Dedicated endpoint. With
endpoint_nameset, a@task.llmtask gets a real completion. Show that the request went to the endpoint's own URL and not to Inference Providers. - Inference Providers. With
provider_nameset instead, the same task gets a completion through that provider. - Invalid combinations. Both fields set, and neither set, each fail with an error that names the two fields. Record whether the failure happens when the connection is saved or when the task runs.
- Unknown endpoint. An
endpoint_namethat does not exist fails the task with the name and namespace in the message. - Endpoint not running. Run the task against a
pausedendpoint and against one inscaledToZero. The PR describes what happens in each case, and the how-to page says the same. - Endpoint recreated. Delete the endpoint, create it again under the same name, and rerun the task without touching the connection. It looks up the endpoint's current URL and succeeds, which is the case that breaks today when the URL is pasted into the connection.
- Token entered once. With the credential-reuse option the PR chose, the token is stored in one place and both
HuggingFaceHookand the Common AI task work. - Together with Manage Hugging Face Inference Endpoints from Dags #77830. One Dag resumes the endpoint, calls it through the new connection, and pauses it in a teardown.
- Token stays out of logs. The token appears neither in the task log nor in the rendered template fields.
What the PR needs
The code follows AGENTS.md and gets reviewed against code-review.instructions.md, so read both first. The points provider PRs trip on most:
- The hook subclasses Common AI's public
PydanticAIHook, as the Snowflake one does. Nothing is imported from core internals or from another provider's private modules. - Imports sit at the top of the file. There is no
assertoutside tests and no newraise AirflowException; useValueError,TypeErroror a dedicated exception class. - Unset fields are tested with
is None. An empty string from the connection form is treated as unset on purpose, with a test for it. - Functions and methods are named with an action verb (
get_,build_,resolve_). Comments appear only where they record a constraint the code cannot show. - Tests are pytest, with
spec/autospecon every mock, parametrization for the field combinations, and no issue numbers in names or docstrings. Each test fails when the change it covers is reverted. At least one test builds the realHuggingFaceProvider, so pydantic-ai validates the arguments it receives. provider.yamllists the new connection type, the[common.ai]extra goes inpyproject.toml, generated files are regenerated withprekand never edited by hand, and the docs change in the same PR. Providers take no newsfragment.- The diff contains only files this issue needs.
The PR description has:
- What changed and why, in words that match the diff, including the credential-reuse decision.
- For each scenario above: the task-log lines or the error message it produced.
- Screenshots: the connection form with the new fields (scenario 1), the Grid view of scenario 9, and the task log of scenario 2.
- The endpoint's status read from the API after the last run, showing it is not left running.
- Any scenario that was not run, by number, with the reason. A mocked version passing is no substitute.
- The generative-AI disclosure from the PR template, filled in, and
closes: #<this issue>.
cc @ParagEkbote
Use case/motivation
Teams that serve an open model on a dedicated Inference Endpoint want to use it from @task.llm and @task.agent the same way they use a hosted model: by naming a connection. With this connection type the Dag refers to the endpoint by name, the URL is looked up at run time, and the Hugging Face token lives in one place.
It also completes the flow from #77830. A Dag can resume an endpoint, run Common AI tasks against it through this connection, and pause it in a teardown, without an endpoint URL appearing anywhere in the Dag or the connection.
Related issues
- Manage Hugging Face Inference Endpoints from Dags #77830 adds the Inference Endpoint operators and the hook methods this builds on.
- Add Hugging Face Provider #76317 added the Hugging Face provider and
HuggingFaceHook.
Are you willing to submit a PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity