forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconversation_metadata.py
More file actions
34 lines (26 loc) · 1.03 KB
/
Copy pathconversation_metadata.py
File metadata and controls
34 lines (26 loc) · 1.03 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
from typing import Any, cast
from pydantic import BaseModel, Field
class ConversationMetadataKeys:
PEOPLE = 'people'
TOPICS = 'topics'
ENTITIES = 'entities'
DATES = 'dates'
class ConversationMetadata(BaseModel):
people: list[str] = Field(default_factory=list)
topics: list[str] = Field(default_factory=list)
entities: list[str] = Field(default_factory=list)
dates: list[str] = Field(default_factory=list)
def to_vector_metadata(self) -> dict[str, list[str]]:
return {
ConversationMetadataKeys.PEOPLE: self.people,
ConversationMetadataKeys.TOPICS: self.topics,
ConversationMetadataKeys.ENTITIES: self.entities,
ConversationMetadataKeys.DATES: self.dates,
}
def metadata_list(metadata: dict[str, Any], key: str) -> list[str]:
value = metadata.get(key, [])
if isinstance(value, list):
return cast(list[str], value)
if isinstance(value, tuple):
return [str(item) for item in cast(tuple[object, ...], value)]
return []