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.ai
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.1.2.tar.gz
(13.3 kB
view details)
Built Distribution
File details
Details for the file workflowai-0.1.2.tar.gz
.
File metadata
- Download URL: workflowai-0.1.2.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8537c4177c1f8eabc9ed94aee432dfe6a21f234fffd07e6de7ae79fb4cf565d2 |
|
MD5 | 0690756a7c6b2fedd26cc09c30726ce8 |
|
BLAKE2b-256 | 95029ec426c990902983378283c12f443765338a65b34d2762ed20a26d19b49d |
File details
Details for the file workflowai-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: workflowai-0.1.2-py3-none-any.whl
- Upload date:
- Size: 21.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cec16ba3f287f2762e00b22394b54c8746169ef7bfd71663a9ae066456ede6b |
|
MD5 | d6a60728121df676391b0c685aa2b8d1 |
|
BLAKE2b-256 | e4923f0f1a4de43bb95c3e0f2ef53ff5d5f58e6d70414a9ad144b07a6bdeb1c5 |