forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalendar_context.py
More file actions
46 lines (38 loc) · 2.17 KB
/
Copy pathcalendar_context.py
File metadata and controls
46 lines (38 loc) · 2.17 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
from datetime import datetime
from typing import Any, Callable, List, Optional
from pydantic import BaseModel, Field
class MeetingParticipant(BaseModel):
"""Represents a participant in a calendar meeting"""
name: Optional[str] = Field(default=None, description="Participant's display name")
email: Optional[str] = Field(default=None, description="Participant's email address")
class CalendarMeetingContext(BaseModel):
"""Calendar meeting metadata to provide context for conversation processing"""
calendar_event_id: str = Field(description="System calendar event ID")
title: str = Field(description="Meeting title from calendar")
participants: List[MeetingParticipant] = Field(default_factory=list, description="List of meeting participants")
platform: Optional[str] = Field(default=None, description="Meeting platform (Zoom, Teams, Google Meet, etc.)")
meeting_link: Optional[str] = Field(default=None, description="URL to join the meeting")
start_time: datetime = Field(description="Meeting start time")
duration_minutes: int = Field(description="Meeting duration in minutes")
notes: Optional[str] = Field(default=None, description="Meeting notes/description from calendar")
calendar_source: Optional[str] = Field(
default='system_calendar', description="Calendar source (system_calendar, google, outlook, etc.)"
)
@classmethod
def from_records(
cls,
records: List[dict[str, Any]],
on_error: Optional[Callable[[dict[str, Any], Exception], None]] = None,
) -> List['CalendarMeetingContext']:
"""Build a list of contexts from raw stored records, skipping any that fail
validation so a single malformed meeting cannot hide all of a user's meetings.
`on_error(record, exception)`, when provided, is called for each skipped record.
"""
parsed: List['CalendarMeetingContext'] = []
for record in records:
try:
parsed.append(cls(**record))
except Exception as exc: # noqa: BLE001 - one bad record must not break the whole list
if on_error is not None:
on_error(record, exc)
return parsed