from guardrails import Guard
from guardrails.hub import RegexMatch
from pydantic import BaseModel, Field
from typing import List
NAME_REGEX = "^[A-Z][a-z]+\s[A-Z][a-z]+$"
class Delivery(BaseModel):
custome_name: str=Field(validators=[RegexMatch(regex=NAME_REGEX)], description="customer name")
pickup_time: str=Field(description="date and time of pickup")
pickup_location: str=Field(description="address of pickup")
dropoff_time: str=Field(description="date and time of dropoff")
dropoff_location: str=Field(description="address of dropoff")
price: str = Field(description="price of delivery with currency symbol included")
class Schedule(BaseModel):
deliveries: List[Delivery]
guard = Guard.for_pydantic(Schedule)
chat_history="""
nelson and murdock: i need a pickup 797 9th Avenue, manila envelope, June 3 10:00am with dropoff 10:30am Courthouse, 61 Center Street C/O frank james
operator: quote - $23.00
neslon and murdock: perfect, we accept the quote
operator: 797 9th ave, 10:00am pickup comfirmed
abc flowers: i need a pickup of a flowers from abc flowers at 21 3rd street at 11:00am on june 2 with a dropoff at 75th Ave at 5:30pm same day
operator: 21 3rd street flowers quote - $14.50
abc flowers: accepted
polk and wardell: i need a pickup of a bagels from Bakers Co at 331 5th street at 11:00am on june 3 with a dropoff at 75th Ave at 5:30pm same day
operator: 331 5th street bagels quote - $34.50
polk and wardell: accepted
"""
prompt = """
From the chat exchanges below extract a schedule of deliveries.
Chats:
${chat_history}
"""
messages = [{
"role": "system",
"content": "You are a helpful assistant."
}, {
"role": "user",
"content": prompt
}]