forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory_api_response.py
More file actions
42 lines (33 loc) · 1.33 KB
/
Copy pathmemory_api_response.py
File metadata and controls
42 lines (33 loc) · 1.33 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
"""HTTP response builders for public memory API payloads."""
from collections.abc import Mapping
from typing import Any, Iterable
from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse
from pydantic import BaseModel
from utils.memory.memory_api_contract import MemoryApiExposure, memory_api_payload, memory_api_payloads
def memory_item_response(
value: BaseModel | dict[str, Any],
exposure: MemoryApiExposure,
*,
headers: Mapping[str, str] | None = None,
) -> JSONResponse:
return JSONResponse(content=jsonable_encoder(memory_api_payload(value, exposure)), headers=dict(headers or {}))
def memory_list_response(
values: Iterable[BaseModel | dict[str, Any]],
exposure: MemoryApiExposure,
*,
headers: Mapping[str, str] | None = None,
) -> JSONResponse:
return JSONResponse(content=jsonable_encoder(memory_api_payloads(values, exposure)), headers=dict(headers or {}))
def memory_batch_response(
values: Iterable[BaseModel | dict[str, Any]],
exposure: MemoryApiExposure,
*,
created_count: int,
headers: Mapping[str, str] | None = None,
) -> JSONResponse:
content = {
'memories': memory_api_payloads(values, exposure),
'created_count': created_count,
}
return JSONResponse(content=jsonable_encoder(content), headers=dict(headers or {}))