-
Notifications
You must be signed in to change notification settings - Fork 17.5k
Add quick start guide to common.ai provider docs #69552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f31b8d4
Add quick start guide to common.ai provider docs
Lee-W aa99465
Fix common.ai quickstart install command and connection example
Lee-W 7349dff
Extract common.ai quickstart Dag into a tested example file
Lee-W 197ba6c
Link common.ai quickstart to the full extras list
Lee-W 8cc3e90
Link common.ai model extras to the upstream pydantic-ai list
Lee-W File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| .. Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| .. http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| .. Unless required by applicable law or agreed to in writing, | ||
| software distributed under the License is distributed on an | ||
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations | ||
| under the License. | ||
|
|
||
| .. _howto/quickstart: | ||
|
|
||
| Quick start | ||
| =========== | ||
|
|
||
| This guide installs the provider, configures a connection, and runs a first | ||
| LLM task. | ||
|
|
||
| Before you start: this assumes a working :doc:`apache-airflow:installation/index` | ||
| (Airflow 3.0+) already exists, you have an API key for the LLM provider you | ||
| plan to use, and step 3 below makes a real, billed API call to that provider. | ||
|
|
||
| 1. Install | ||
| ---------- | ||
|
|
||
| Install the provider together with the extra matching the model SDK you plan | ||
| to use — ``openai``, ``anthropic``, ``google``, or ``bedrock`` (see | ||
| :doc:`index` for the full list of available extras). Replace ``<extra>`` | ||
| below with the one you need: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| pip install "apache-airflow-providers-common-ai[<extra>]" | ||
|
|
||
| 2. Configure the connection | ||
| ---------------------------- | ||
|
|
||
| Every LLM call goes through a Pydantic AI connection (``conn_type`` ``pydanticai``, | ||
| default connection id ``pydanticai_default``). The model is set in ``provider:model`` | ||
| format and the API key goes in the password field. See :ref:`howto/connection:pydanticai` | ||
| for the full reference, including providers that | ||
| don't need an API key (Bedrock, Vertex AI). | ||
|
|
||
| The quickest way to set one up is an environment variable. Replace | ||
| ``openai:gpt-5.3`` with a model you have access to and ``sk-...`` with your | ||
| actual API key: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| export AIRFLOW_CONN_PYDANTICAI_DEFAULT='{"conn_type": "pydanticai", "password": "sk-...", "extra": {"model": "openai:gpt-5.3"}}' | ||
|
|
||
| Or add it through the Airflow UI (``Admin > Connections``) or the CLI (``airflow connections add``). | ||
|
|
||
| 3. Write your first Dag | ||
| ------------------------ | ||
|
|
||
| The ``@task.llm`` decorator turns a function that returns a prompt string into | ||
| a task that sends that prompt to the LLM and returns its response: | ||
|
|
||
| .. exampleinclude:: /../../ai/src/airflow/providers/common/ai/example_dags/example_quickstart.py | ||
| :language: python | ||
| :start-after: [START howto_quickstart_llm] | ||
| :end-before: [END howto_quickstart_llm] | ||
|
|
||
| Run it like any other Dag (``airflow dags test quickstart_llm``) and the | ||
| ``summarize`` task pushes the LLM's response to XCom. | ||
|
|
||
| Structured output | ||
| ^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| Need typed data instead of a string? Set ``output_type`` to a Pydantic | ||
| ``BaseModel`` and the model instance is pushed to XCom unchanged. See the | ||
| "Structured Output" section of the :ref:`howto/operator:llm` guide for the | ||
| full example and its XCom-deserialization requirements. | ||
|
|
||
| Where to go next | ||
| ----------------- | ||
|
|
||
| - :doc:`operators/index` — the full set of operators and ``@task`` decorators | ||
| (file analysis, SQL, branching, schema comparison). | ||
| - :doc:`toolsets` — give an agent tools built from Airflow hooks, SQL | ||
| databases, or MCP servers. | ||
| - :ref:`howto/operator:agent` — run a multi-turn agent that reasons and calls | ||
| tools instead of a single prompt-response call. | ||
| - :doc:`observability` — trace LLM and tool calls with OpenTelemetry. |
37 changes: 37 additions & 0 deletions
37
providers/common/ai/src/airflow/providers/common/ai/example_dags/example_quickstart.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| """Quickstart example: a first @task.llm Dag.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| # [START howto_quickstart_llm] | ||
| from airflow.sdk import dag, task | ||
|
|
||
|
|
||
| @dag(schedule=None, tags=["example"]) | ||
| def quickstart_llm(): | ||
| @task.llm(llm_conn_id="pydanticai_default", system_prompt="You are a helpful assistant. Be concise.") | ||
| def summarize(text: str): | ||
| return f"Summarize this article: {text}" | ||
|
|
||
| summarize( | ||
| "Apache Airflow is a platform for programmatically authoring, scheduling, and monitoring workflows." | ||
| ) | ||
|
|
||
|
|
||
| quickstart_llm() | ||
| # [END howto_quickstart_llm] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.