Skip to content

Commit b248aca

Browse files
author
Pierre
authored
Merge pull request #79 from WorkflowAI/pierre-readme-key-feature-code-example
docs: enhance README with key features and add flight info extraction example
2 parents 9f327ee + edeaa0d commit b248aca

File tree

4 files changed

+212
-4
lines changed

4 files changed

+212
-4
lines changed

README.md

Lines changed: 134 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![PyPI version](https://img.shields.io/pypi/v/workflowai.svg)](https://pypi.org/project/workflowai/)
44
[![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
5+
[![Python versions](https://img.shields.io/pypi/pyversions/workflowai.svg)](https://pypi.org/project/workflowai/)
56

67
Official SDK from [WorkflowAI](https://workflowai.com) for Python.
78

@@ -11,17 +12,146 @@ Official SDK from [WorkflowAI](https://workflowai.com) for Python.
1112

1213
This SDK is designed for Python teams who prefer code-first development. It provides greater control through direct code integration while still leveraging the full power of the WorkflowAI platform, complementing the web-app experience.
1314

14-
## Installation
15+
## Key Features
1516

16-
`workflowai` requires a python >= 3.9.
17+
- **Model-agnostic**: Works with all major AI models including OpenAI, Anthropic, Claude, Google/Gemini, Mistral, Deepseek, with a unified interface that makes switching between providers seamless. [View all supported models](https://github.com/WorkflowAI/python-sdk/blob/main/workflowai/core/domain/model.py).
18+
19+
- **Open-source and flexible deployment**: WorkflowAI is fully open-source with flexible deployment options. Run it self-hosted on your own infrastructure for maximum data control, or use the managed [WorkflowAI Cloud](https://docs.workflowai.com/workflowai-cloud/introduction) service for hassle-free updates and automatic scaling.
20+
21+
- **Observability integrated**: Built-in monitoring and logging capabilities that provide insights into your AI workflows, making debugging and optimization straightforward. Learn more about [observability features](https://docs.workflowai.com/concepts/runs).
22+
23+
- **Cost tracking**: Automatically calculates and tracks the cost of each AI model run, providing transparency and helping you manage your AI budget effectively. Learn more about [cost tracking](https://docs.workflowai.com/python-sdk/agent#cost-latency).
24+
25+
- **Type-safe**: Leverages Python's type system to catch errors at development time rather than runtime, ensuring more reliable AI applications.
26+
27+
- **Structured output**: Uses Pydantic models to validate and structure AI responses. WorkflowAI ensures your AI responses always match your defined structure, simplifying integrations, reducing parsing errors, and making your data reliable and ready for use. Learn more about [structured input and output](https://docs.workflowai.com/python-sdk/agent#schema-input-output).
28+
29+
- **Streaming supported**: Enables real-time streaming of AI responses for low latency applications, with immediate validation of partial outputs. Learn more about [streaming capabilities](https://docs.workflowai.com/python-sdk/agent#streaming).
30+
31+
- **Provider fallback**: Automatically switches to alternative AI providers when the primary provider fails, ensuring high availability and reliability for your AI applications. This feature allows you to define fallback strategies that maintain service continuity even during provider outages or rate limiting.
32+
33+
- **Built-in tools**: Comes with powerful built-in tools like web search and web browsing capabilities, allowing your agents to access real-time information from the internet. These tools enable your AI applications to retrieve up-to-date data, research topics, and interact with web content without requiring complex integrations. Learn more about [built-in tools](https://docs.workflowai.com/python-sdk/tools).
34+
35+
- **Custom tools support**: Easily extend your agents' capabilities by creating custom tools tailored to your specific needs. Whether you need to query internal databases, call external APIs, or perform specialized calculations, WorkflowAI's tool framework makes it simple to augment your AI with domain-specific functionality. Learn more about [custom tools](https://docs.workflowai.com/python-sdk/tools#defining-custom-tools).
36+
37+
- **Integrated with WorkflowAI**: The SDK seamlessly syncs with the WorkflowAI web application, giving you access to a powerful playground where you can edit prompts and compare models side-by-side. This hybrid approach combines the flexibility of code-first development with the visual tools needed for effective prompt engineering and model evaluation.
38+
39+
- **Multimodality support**: Build agents that can handle multiple modalities, such as images, PDFs, documents, and audio. Learn more about [multimodal capabilities](https://docs.workflowai.com/python-sdk/multimodality).
40+
41+
- **Caching support**: To save money and improve latency, WorkflowAI supports caching. When enabled, identical requests return cached results instead of making new API calls to AI providers. Learn more about [caching capabilities](https://docs.workflowai.com/python-sdk/agent#cache).
42+
43+
44+
45+
## Get Started
46+
47+
`workflowai` requires Python 3.9 or higher.
1748

1849
```sh
1950
pip install workflowai
2051
```
2152

22-
## Get Started
53+
Here's a simple example of a WorkflowAI agent that extracts structured flight information from email content:
54+
55+
56+
```python
57+
import asyncio
58+
from datetime import datetime
59+
from enum import Enum
60+
61+
from pydantic import BaseModel, Field
62+
63+
import workflowai
64+
from workflowai import Model
65+
66+
# Input class
67+
class EmailInput(BaseModel):
68+
email_content: str
69+
70+
# Output class
71+
class FlightInfo(BaseModel):
72+
# Enum for standardizing flight status values
73+
class Status(str, Enum):
74+
"""Possible statuses for a flight booking."""
75+
CONFIRMED = "Confirmed"
76+
PENDING = "Pending"
77+
CANCELLED = "Cancelled"
78+
DELAYED = "Delayed"
79+
COMPLETED = "Completed"
80+
81+
passenger: str
82+
airline: str
83+
flight_number: str
84+
from_airport: str = Field(description="Three-letter IATA airport code for departure")
85+
to_airport: str = Field(description="Three-letter IATA airport code for arrival")
86+
departure: datetime
87+
arrival: datetime
88+
status: Status
89+
90+
# Agent definition
91+
@workflowai.agent(
92+
id="flight-info-extractor",
93+
model=Model.GEMINI_2_0_FLASH_LATEST,
94+
)
95+
async def extract_flight_info(email_input: EmailInput) -> FlightInfo:
96+
# Agent prompt
97+
"""
98+
Extract flight information from an email containing booking details.
99+
"""
100+
...
101+
102+
103+
async def main():
104+
email = """
105+
Dear Jane Smith,
106+
107+
Your flight booking has been confirmed. Here are your flight details:
108+
109+
Flight: UA789
110+
From: SFO
111+
To: JFK
112+
Departure: 2024-03-25 9:00 AM
113+
Arrival: 2024-03-25 5:15 PM
114+
Booking Reference: XYZ789
115+
116+
Total Journey Time: 8 hours 15 minutes
117+
Status: Confirmed
118+
119+
Thank you for choosing United Airlines!
120+
"""
121+
run = await extract_flight_info.run(EmailInput(email_content=email))
122+
print(run)
123+
124+
125+
if __name__ == "__main__":
126+
asyncio.run(main())
127+
128+
129+
# Output:
130+
# ==================================================
131+
# {
132+
# "passenger": "Jane Smith",
133+
# "airline": "United Airlines",
134+
# "flight_number": "UA789",
135+
# "from_airport": "SFO",
136+
# "to_airport": "JFK",
137+
# "departure": "2024-03-25T09:00:00",
138+
# "arrival": "2024-03-25T17:15:00",
139+
# "status": "Confirmed"
140+
# }
141+
# ==================================================
142+
# Cost: $ 0.00009
143+
# Latency: 1.18s
144+
# URL: https://workflowai.com/_/agents/flight-info-extractor/runs/0195ee02-bdc3-72b6-0e0b-671f0b22b3dc
145+
```
146+
> **Ready to run!** This example works straight out of the box - no tweaking needed.
147+
148+
Agents built with `workflowai` SDK can be run in the [WorkflowAI web application](https://workflowai.com/docs/agents/flight-info-extractor/1?showDiffMode=false&show2ColumnLayout=false&taskRunId1=0195ee21-988e-7309-eb32-cd49a9b90f46&taskRunId2=0195ee21-9898-723a-0469-1458a180d3b0&taskRunId3=0195ee21-9892-72f1-ca2d-c29e18285073&versionId=fb7b29cd00031675d0c19e3d09852b27) too.
149+
150+
[![WorkflowAI Playground](/examples/assets/web/playground-flight-info-extractor.png)](https://workflowai.com/docs/agents/flight-info-extractor/1?showDiffMode=false&show2ColumnLayout=false&taskRunId1=0195ee21-988e-7309-eb32-cd49a9b90f46&taskRunId2=0195ee21-9898-723a-0469-1458a180d3b0&taskRunId3=0195ee21-9892-72f1-ca2d-c29e18285073&versionId=fb7b29cd00031675d0c19e3d09852b27)
151+
152+
And the runs executed via the SDK are synced with the web application.
23153

24-
Follow the steps in our [Getting Started Guide](https://docs.workflowai.com/python-sdk/get-started).
154+
[![WorkflowAI Runs](/examples/assets/web/runs-flight-info-extractor.png)](https://workflowai.com/docs/agents/flight-info-extractor/1/runs?page=0)
25155

26156
## Documentation
27157

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"""
2+
This example demonstrates how to create a WorkflowAI agent that extracts flight information from emails.
3+
It showcases:
4+
5+
1. Using Pydantic models for structured data extraction
6+
2. Extracting specific details like flight numbers, dates, and times
7+
"""
8+
9+
import asyncio
10+
from datetime import datetime
11+
from enum import Enum
12+
13+
from pydantic import BaseModel, Field
14+
15+
import workflowai
16+
from workflowai import Model
17+
18+
19+
class EmailInput(BaseModel):
20+
"""Raw email content containing flight booking details.
21+
This could be a confirmation email, itinerary update, or e-ticket from any airline."""
22+
email_content: str
23+
24+
25+
class FlightInfo(BaseModel):
26+
"""Model for extracted flight information."""
27+
class Status(str, Enum):
28+
"""Possible statuses for a flight booking."""
29+
CONFIRMED = "Confirmed"
30+
PENDING = "Pending"
31+
CANCELLED = "Cancelled"
32+
DELAYED = "Delayed"
33+
COMPLETED = "Completed"
34+
35+
passenger: str
36+
airline: str
37+
flight_number: str
38+
from_airport: str = Field(description="Three-letter IATA airport code for departure")
39+
to_airport: str = Field(description="Three-letter IATA airport code for arrival")
40+
departure: datetime
41+
arrival: datetime
42+
status: Status
43+
44+
@workflowai.agent(
45+
id="flight-info-extractor",
46+
model=Model.GEMINI_2_0_FLASH_LATEST,
47+
)
48+
async def extract_flight_info(email_input: EmailInput) -> FlightInfo:
49+
"""
50+
Extract flight information from an email containing booking details.
51+
"""
52+
...
53+
54+
55+
async def main():
56+
email = """
57+
Dear Jane Smith,
58+
59+
Your flight booking has been confirmed. Here are your flight details:
60+
61+
Flight: UA789
62+
From: SFO
63+
To: JFK
64+
Departure: 2024-03-25 9:00 AM
65+
Arrival: 2024-03-25 5:15 PM
66+
Booking Reference: XYZ789
67+
68+
Total Journey Time: 8 hours 15 minutes
69+
Status: Confirmed
70+
71+
Thank you for choosing United Airlines!
72+
"""
73+
run = await extract_flight_info.run(EmailInput(email_content=email))
74+
print(run)
75+
76+
77+
if __name__ == "__main__":
78+
asyncio.run(main())
3.6 MB
Loading
5.43 MB
Loading

0 commit comments

Comments
 (0)