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.3.tar.gz
(13.7 kB
view details)
Built Distribution
File details
Details for the file workflowai-0.1.3.tar.gz
.
File metadata
- Download URL: workflowai-0.1.3.tar.gz
- Upload date:
- Size: 13.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17957ff52ed6436fbbbd5313c3e1104f21e7643db1609bbdb1f6619c8bf908f7 |
|
MD5 | cb157fa5c89bb2b8cedd5cb9091069e0 |
|
BLAKE2b-256 | 671e27db1a15bb25721c2a61dd18c7992f56550fe1d9e58180e49bed1f2d9792 |
File details
Details for the file workflowai-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: workflowai-0.1.3-py3-none-any.whl
- Upload date:
- Size: 21.6 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 | 00daba7f0d6196a1db058bc424504eb9bb1ed966863a563e6cd55efe9ed91490 |
|
MD5 | f0b79fe00dbc0cd5594403049c29d7ff |
|
BLAKE2b-256 | d252ec898e86b49eddd813e4882cec0b679d0f5dec4cc63225a504c260e036db |