Autoflows
Automated Flyte Workflows using LLMs
The autoflows package allows you to run Flyte workflows that are powered by
LLMs. These workflows use LLMs to determine which task to run in a suite of
user-defined, trusted Flyte tasks.
Installation
pip install autoflows
Usage
First we can define some Flyte tasks as usual:
# example.py
from flytekit import task
from autoflows import autoflow
image_spec = ImageSpec(
"auto-workflows",
registry="ghcr.io/unionai-oss",
requirements="requirements.txt",
python_version="3.10",
)
@task(container_image=image_spec)
def add_numbers(x: float, y: float) -> FlyteFile: ...
@task(container_image=image_spec)
def concat_strings(strings: List[str]) -> FlyteFile: ...
@task(container_image=image_spec)
def train_classifier(data: List[dict], target_column: str) -> FlyteFile:
...
Then, in the same file, we define a FlyteRemote object that we want to use to
run our autoflow.
# example.py
remote = FlyteRemote(
config=Config(
platform=PlatformConfig(
endpoint="<my_endpoitn>",
client_id="<my_client_id>",
),
),
default_project="flytesnacks",
default_domain="development",
)
Finally, we define the autoflow function:
# example.py
@autoflow(
tasks=[add_numbers, concat_strings, train_classifier],
model="gpt-3.5-turbo-1106",
remote=remote,
openai_secret_group="<OPENAI_API_SECRET_GROUP>",
openai_secret_key="<OPENAI_API_SECRET_KEY>",
client_secret_group="<CLIENT_SECRET_GROUP>",
client_secret_key="<CLIENT_SECRET_KEY>",
container_image=image_spec,
)
async def main(prompt: str, inputs: dict) -> FlyteFile:
"""You are a helpful bot that picks functions based on a prompt and a set of inputs.
What tool should I use for completing the task '{prompt}' using the following inputs?
{inputs}
"""
Running on Flyte or Union
Then, you can register the workflow along with all of the tasks:
pyflyte --config config.yaml register example.py
Where config.yaml is the Flyte configuration file pointing to your Flyte or
Union cluster.
Finally, you can run the workflow, and let the autoflow function decide which
task to run based on the prompt and inputs. For example, to add two numbers, you
would do:
pyflyte --config config.yaml run example.py main \
--prompt "Add these two numbers" \
--inputs '{"x": 1, "y": 2}'
To concatenate two strings, you would do:
pyflyte run \
test_auto_workflow.py auto_wf \
--prompt "Combine these two strings together" \
--inputs '{"strings": ["hello", " ", "world"]}'
And to train a classifier based on data:
pyflyte run \
test_auto_workflow.py auto_wf \
--prompt "Train a classifier on this small dataset" \
--inputs "{\"target_column\": \"y\", \"training_data\": $(cat data.json)}"
Where data.json contains json objects that looks something like:
[
{"x": 5, "y": 10},
{"x": 3, "y": 5},
{"x": 10, "y": 19},
]
Release files for autoflows 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| autoflows-0.0.1.tar.gz | 9.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| autoflows-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.4 kB
Release files / autoflows-0.0.1.tar.gz
| Download URL | autoflows-0.0.1.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
253c149e08358d44a912c23c8c72c5b7bc257e8823383bb713b9de04d52d9111
|
|
BLAKE2b-256 checksum How to use checksums |
12fa4349928c9d5fc8c19004fe19cf78a2bc524886a865dcce8e8ac4e0e7e07d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.0
|
Release files / autoflows-0.0.1-py3-none-any.whl
| Download URL | autoflows-0.0.1-py3-none-any.whl |
|---|---|
| Size | 12.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
994c450749d98d98ac456e72cd645fd99e672bdb8f43995bc4a0d936f5535ec6
|
|
BLAKE2b-256 checksum How to use checksums |
c62f9ff7b662adc2c54e47d1bd4e68becfb01eaab894bf6251924c71ce5424f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.0
|