forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvice.py
More file actions
91 lines (70 loc) · 3.05 KB
/
Copy pathadvice.py
File metadata and controls
91 lines (70 loc) · 3.05 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""Advice — proactive coaching items."""
from fastapi import APIRouter, Depends, HTTPException, Query
from pydantic import BaseModel, Field
from models.advice import Advice
from models.shared import StatusResponse
import database.advice as advice_db
from utils.other import endpoints as auth
router = APIRouter()
# ============================================================================
# REQUEST MODELS
# ============================================================================
class CreateAdviceRequest(BaseModel):
content: str = Field(..., min_length=1, max_length=10000)
category: str | None = Field(None, max_length=100)
reasoning: str | None = Field(None, max_length=5000)
source_app: str | None = Field(None, max_length=200)
confidence: float = Field(0.5, ge=0.0, le=1.0)
context_summary: str | None = Field(None, max_length=5000)
current_activity: str | None = Field(None, max_length=500)
class UpdateAdviceRequest(BaseModel):
is_read: bool | None = None
is_dismissed: bool | None = None
# ============================================================================
# ENDPOINTS
# ============================================================================
@router.post('/v1/advice', tags=['advice'], response_model=Advice)
def create_advice(
request: CreateAdviceRequest,
uid: str = Depends(auth.get_current_user_uid),
):
return advice_db.create_advice(
uid,
content=request.content,
category=request.category or 'other',
reasoning=request.reasoning,
source_app=request.source_app,
confidence=request.confidence,
context_summary=request.context_summary,
current_activity=request.current_activity,
)
@router.get('/v1/advice', tags=['advice'], response_model=list[Advice])
def get_advice(
limit: int = Query(100, ge=1, le=1000),
offset: int = Query(0, ge=0),
category: str | None = Query(None),
include_dismissed: bool = Query(False),
uid: str = Depends(auth.get_current_user_uid),
):
return advice_db.get_advice(uid, limit=limit, offset=offset, category=category, include_dismissed=include_dismissed)
@router.patch('/v1/advice/{advice_id}', tags=['advice'], response_model=Advice)
def update_advice(
advice_id: str,
request: UpdateAdviceRequest,
uid: str = Depends(auth.get_current_user_uid),
):
result = advice_db.update_advice(uid, advice_id, is_read=request.is_read, is_dismissed=request.is_dismissed)
if result is None:
raise HTTPException(status_code=404, detail='Advice not found')
return result
@router.delete('/v1/advice/{advice_id}', tags=['advice'], response_model=StatusResponse)
def delete_advice(
advice_id: str,
uid: str = Depends(auth.get_current_user_uid),
):
advice_db.delete_advice(uid, advice_id)
return {'status': 'ok'}
@router.post('/v1/advice/mark-all-read', tags=['advice'], response_model=StatusResponse)
def mark_all_advice_read(uid: str = Depends(auth.get_current_user_uid)):
count = advice_db.mark_all_advice_read(uid)
return {'status': f'marked {count} as read'}