forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathother.py
More file actions
67 lines (51 loc) · 2.02 KB
/
Copy pathother.py
File metadata and controls
67 lines (51 loc) · 2.02 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
from datetime import datetime
from typing import Any, Callable, Iterable, List, Mapping, Optional
from pydantic import BaseModel, Field
class SaveFcmTokenRequest(BaseModel):
fcm_token: str
time_zone: str
class FcmTokenResponse(BaseModel):
status: str
class SendNotificationRequest(BaseModel):
uid: str
title: str
body: str
data: dict = Field(default_factory=dict)
class SendAppNotificationRequest(BaseModel):
aid: str
message: str
uid: str
class UploadProfile(BaseModel):
bytes: List[List[int]]
duration: int
class CreatePerson(BaseModel):
name: str = Field(min_length=2, max_length=40)
# Person photo deferred pending product input on storage: no photo/avatar/image
# field today; GCS people_profiles/ is speech-sample audio only; the app uses
# local speaker icons; unlike app/persona logos there is no person-photo URL or
# upload pattern to mirror. Do not invent an optional photo string yet.
class Person(BaseModel):
id: str
name: str
created_at: Optional[datetime] = None
updated_at: Optional[datetime] = None
speech_samples: List[str] = []
speech_sample_transcripts: Optional[List[str]] = None
speech_samples_version: int = 3
@classmethod
def deserialize_many_safe(
cls,
records: Iterable[Mapping[str, Any]],
on_error: Optional[Callable[[Mapping[str, Any], Exception], None]] = None,
) -> List['Person']:
"""Build Person objects from raw stored records, skipping any that fail validation so one
malformed or legacy person document cannot break a whole people lookup. on_error(record,
exception), when provided, is called for each skip. Mirrors Message.deserialize_many_safe."""
parsed: List['Person'] = []
for record in records:
try:
parsed.append(cls(**record))
except Exception as exc: # noqa: BLE001 - one bad record must not break the lookup
if on_error is not None:
on_error(record, exc)
return parsed