from fastapi import APIRouter, Request, UploadFile from backend.services.llm_service import question_and_answer from backend.schemas.basic_schema import QuestionRequest from backend.services.rag_service import upload_document, rag_chat, rag_chat_stream from fastapi.responses import StreamingResponse router = APIRouter(prefix="/api") # http://127.0.0.1:8000/api/question @router.post("/question") async def question(req: QuestionRequest): answer = question_and_answer(req.question) return {"message" : answer} # http://127.0.0.1:8000/api/rag/upload @router.post("/rag/upload") async def file_Upload(file: UploadFile): # 서비스 호출 return upload_document(file) # http://127.0.0.1:8000/api/rag/question @router.post("/rag/question") async def question(req: QuestionRequest): answer = rag_chat(req.question) return {"message" : answer} @router.post("/rag/question/stream") async def question_stream(req: QuestionRequest): answer = rag_chat_stream(req.question) return StreamingResponse(rag_chat_stream(req.question), media_type="text/plain")