No project description provided
Project description
WorkflowAI Python
A library to use WorkflowAI with Python
Installation
workflowai
requires a python >= 3.9.
pip install workflowai
Usage
Usage examples are available in the examples directory.
Set up the workflowai client
import workflowai
wai = workflowai.start(
url=..., # defaults to WORKFLOWAI_API_URL env var or https://api.workflowai.com
api_key=..., # defaults to WORKFLOWAI_API_KEY env var
)
Define a task
We use pydantic for type definitions.
from pydantic import BaseModel, Field
from workflowai import Task, TaskVersionReference
class CityToCapitalTaskInput(BaseModel):
city: str
class CityToCapitalTaskOutput(BaseModel):
capital: str
class CityToCapitalTask(Task[CityToCapitalTaskInput, CityToCapitalTaskOutput]):
id: str = "citytocapital"
schema_id: int = 1
input_class: type[CityToCapitalTaskInput] = CityToCapitalTaskInput
output_class: type[CityToCapitalTaskOutput] = CityToCapitalTaskOutput
# The default version that should be used when running the task
version: TaskVersionReference = TaskVersionReference(
iteration=4,
)
Run a task
task = CityToCapitalTask()
task_input = CityToCapitalTaskInput(city=city)
task_run = await wai.run(task, task_input)
print(task_run.task_output)
It is also possible to stream a task output
task = CityToCapitalTask()
task_input = CityToCapitalTaskInput(city=city)
iterator = await wai.run(task, task_input, stream=True)
async for chunk in iterator:
print(chunk) # chunk is a partial (non validated) CityToCapitalTaskOutput
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
workflowai-0.2.0.tar.gz
(14.5 kB
view details)
Built Distribution
File details
Details for the file workflowai-0.2.0.tar.gz
.
File metadata
- Download URL: workflowai-0.2.0.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f48b19a8c6af6406940485da34fd6febd388a63c1496491c4a4797611e44b898 |
|
MD5 | 61784d43d584e2f1cb85061d2c0a4a44 |
|
BLAKE2b-256 | 3e1adbd9b9cab58de5b0075f1bcb03efc1bd4d1abe9b9fa8291569220f367845 |
File details
Details for the file workflowai-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: workflowai-0.2.0-py3-none-any.whl
- Upload date:
- Size: 22.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f6d4daf8a50f0bda4e0207d35b2c75b43ca22c1a5e9af85484fa9ba1b82e475 |
|
MD5 | 3264fa15512cf873df4c779502089ebc |
|
BLAKE2b-256 | 67a340214ab608041f4c43c82bc1714b802d9acf8c32bdc29f6832e55c29972c |