sofzcc commited on
Commit
0a7f319
·
verified ·
1 Parent(s): 6afe59f

Update app/routers/chat.py

Browse files
Files changed (1) hide show
  1. app/routers/chat.py +35 -0
app/routers/chat.py CHANGED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import APIRouter
2
+ from fastapi import Depends
3
+ from fastapi import HTTPException
4
+
5
+ from app.dependencies import get_assistant
6
+ from app.schemas.chat import ChatRequest
7
+ from app.schemas.chat import ChatResponse
8
+
9
+ router = APIRouter()
10
+
11
+
12
+ @router.post("/", response_model=ChatResponse)
13
+ async def chat(
14
+ request: ChatRequest,
15
+ assistant=Depends(get_assistant)
16
+ ):
17
+
18
+ try:
19
+
20
+ response, sources, contexts = (
21
+ assistant.answer(request.message)
22
+ )
23
+
24
+ return ChatResponse(
25
+ response=response,
26
+ sources=sources,
27
+ contexts=contexts
28
+ )
29
+
30
+ except Exception as e:
31
+
32
+ raise HTTPException(
33
+ status_code=500,
34
+ detail=str(e)
35
+ )