Update endpoints.py
Browse files- endpoints.py +22 -2
endpoints.py
CHANGED
|
@@ -2,7 +2,7 @@ from fastapi import APIRouter, Depends, HTTPException, UploadFile, File, Query,
|
|
| 2 |
from fastapi.responses import StreamingResponse, JSONResponse
|
| 3 |
from fastapi.encoders import jsonable_encoder
|
| 4 |
from typing import Optional, List
|
| 5 |
-
from
|
| 6 |
from auth import get_current_user
|
| 7 |
from utils import clean_text_response
|
| 8 |
from analysis import analyze_patient_report
|
|
@@ -15,6 +15,26 @@ from bson import ObjectId
|
|
| 15 |
import asyncio
|
| 16 |
from bson.errors import InvalidId
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
def create_router(agent, logger, patients_collection, analysis_collection, users_collection):
|
| 19 |
router = APIRouter()
|
| 20 |
|
|
@@ -93,7 +113,7 @@ def create_router(agent, logger, patients_collection, analysis_collection, users
|
|
| 93 |
# Store chat session in database
|
| 94 |
chat_entry = {
|
| 95 |
"user_id": current_user["email"],
|
| 96 |
-
"patient_id": request.patient_id
|
| 97 |
"message": request.message,
|
| 98 |
"response": cleaned_text,
|
| 99 |
"chat_type": "chat",
|
|
|
|
| 2 |
from fastapi.responses import StreamingResponse, JSONResponse
|
| 3 |
from fastapi.encoders import jsonable_encoder
|
| 4 |
from typing import Optional, List
|
| 5 |
+
from pydantic import BaseModel
|
| 6 |
from auth import get_current_user
|
| 7 |
from utils import clean_text_response
|
| 8 |
from analysis import analyze_patient_report
|
|
|
|
| 15 |
import asyncio
|
| 16 |
from bson.errors import InvalidId
|
| 17 |
|
| 18 |
+
# Define the ChatRequest model with an optional patient_id
|
| 19 |
+
class ChatRequest(BaseModel):
|
| 20 |
+
message: str
|
| 21 |
+
history: Optional[List[dict]] = None
|
| 22 |
+
format: Optional[str] = "clean"
|
| 23 |
+
temperature: Optional[float] = 0.7
|
| 24 |
+
max_new_tokens: Optional[int] = 512
|
| 25 |
+
patient_id: Optional[str] = None # Added optional patient_id field
|
| 26 |
+
|
| 27 |
+
class VoiceOutputRequest(BaseModel):
|
| 28 |
+
text: str
|
| 29 |
+
language: str = "en-US"
|
| 30 |
+
slow: bool = False
|
| 31 |
+
return_format: str = "mp3"
|
| 32 |
+
|
| 33 |
+
class RiskLevel(BaseModel):
|
| 34 |
+
level: str
|
| 35 |
+
score: float
|
| 36 |
+
factors: Optional[List[str]] = None
|
| 37 |
+
|
| 38 |
def create_router(agent, logger, patients_collection, analysis_collection, users_collection):
|
| 39 |
router = APIRouter()
|
| 40 |
|
|
|
|
| 113 |
# Store chat session in database
|
| 114 |
chat_entry = {
|
| 115 |
"user_id": current_user["email"],
|
| 116 |
+
"patient_id": request.patient_id, # Now safely optional, defaults to None
|
| 117 |
"message": request.message,
|
| 118 |
"response": cleaned_text,
|
| 119 |
"chat_type": "chat",
|