Taiken_chatbot_API / app /routes /prediction_routes.py
vumichien's picture
Add application file
44a025a
from fastapi import APIRouter, HTTPException, Query
from pydantic import BaseModel
from typing import Optional
from app.services.prediction_service import predict_answer
router = APIRouter()
class PredictionRequest(BaseModel):
user_input: str
class PredictionResponse(BaseModel):
status: str
answer: Optional[str] = None
score: Optional[str] = None
message: Optional[str] = None
@router.post("/predict", response_model=PredictionResponse)
async def get_prediction(
request: PredictionRequest,
threshold_q: float = Query(0.7, description="Threshold for question matching"),
threshold_a: float = Query(0.65, description="Threshold for answer matching"),
):
"""
Predict an answer based on user input.
- **user_input**: The user's question or input text
- **threshold_q**: Threshold for question matching (default: 0.7)
- **threshold_a**: Threshold for answer matching (default: 0.65)
Returns the predicted answer and match type.
"""
result = predict_answer(request.user_input, threshold_q, threshold_a)
if result["status"] == "error":
raise HTTPException(status_code=500, detail=result["message"])
return result