| ```python |
| from fastapi import APIRouter, UploadFile, File |
| from services.faiss_service import FAISSService |
| from services.gemini_service import GeminiService |
| import aiofiles |
| import os |
|
|
| router = APIRouter() |
| faiss_service = FAISSService() |
| gemini_service = GeminiService() |
|
|
| @router.post("/upload") |
| async def upload_faq(file: UploadFile = File(...)): |
| |
| temp_path = f"/tmp/{file.filename}" |
| async with aiofiles.open(temp_path, 'wb') as out_file: |
| content = await file.read() |
| await out_file.write(content) |
| |
| |
| if file.filename.endswith('.csv'): |
| docs = await process_csv(temp_path) |
| elif file.filename.endswith('.md'): |
| docs = await process_markdown(temp_path) |
| else: |
| return {"error": "Unsupported file type"} |
| |
| |
| await faiss_service.create_index(docs) |
| |
| |
| os.remove(temp_path) |
| return {"status": "success", "documents_processed": len(docs)} |
|
|
| async def process_csv(path: str): |
| |
| pass |
|
|
| async def process_markdown(path: str): |
| |
| pass |
| ``` |