Untitled
unknown
plain_text
10 months ago
2.8 kB
6
Indexable
# 1) Define your Pydantic model for the meeting invite
class MeetingInvite(BaseModel):
data_issues: str = Field(
description="String describing any issues or needed clarifications. Empty if none."
)
meeting_start: str = Field(
description="ISO 8601 UTC timestamp for the meeting start (e.g., '2025-01-17T14:00:00Z'). Empty if not provided."
)
meeting_end: str = Field(
description="ISO 8601 UTC timestamp for the meeting end (e.g., '2025-01-17T15:00:00Z'). Empty if not provided."
)
attendees: List[str] = Field(
description="List of attendee email addresses."
)
email_subject: str = Field(
description="Meeting subject if user provides one, or empty string."
)
email_body: str = Field(
description="Meeting body/description if user provides one, or empty string."
)
# 2) Create a JSON output parser for the MeetingInvite model
parser = JsonOutputParser(pydantic_object=MeetingInvite)
# 3) Prepare the prompt template
# - This merges your instructions and the parser’s format instructions.
# - Note how we inject the user’s query and the user_to_email map into the template.
meeting_invite_prompt = PromptTemplate(
template="""
You are a system that parses a user's meeting request: {query}
You must return **valid JSON** with these exact keys:
1. "data_issues"
2. "meeting_start"
3. "meeting_end"
4. "attendees"
5. "email_subject"
6. "email_body"
Requirements:
- "data_issues":
- If there's ambiguity about which user to add (e.g., two similar names in the user_to_email map: {user_to_email}), provide a clarification message here.
- If a requested user is not found in user_to_email, provide an appropriate error message here.
- If there are no issues, leave this key as an empty string ("").
- "meeting_start" / "meeting_end":
- Must be ISO 8601 UTC timestamps (e.g., "2025-01-17T14:00:00Z").
- If user doesn't provide a start/end time, leave them empty or use defaults.
- "attendees":
- A list of attendee email addresses.
- "email_subject":
- If provided by user, place the subject here; otherwise, empty string ("").
- "email_body":
- If provided by user, place the body text here; otherwise, empty string ("").
No additional keys beyond these six should be in your output.
{format_instructions}
""",
input_variables=["query", "user_to_email"],
partial_variables={"format_instructions": parser.get_format_instructions()},
)
# 4) Set up the chain
# - Replace `ChatOpenAI(...)` with whatever model you are using (e.g., your llm).
# - The chain will produce text, which we then parse with `parser`.
model = ChatOpenAI(temperature=0.0) # Example LLM initialization
chain = meeting_invite_prompt | model | parserEditor is loading...
Leave a Comment