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