| 227 | |
| 228 | @app.post("/insert_file", response_model=Response) |
| 229 | async def insert_file(file: UploadFile = File(...)): |
| 230 | try: |
| 231 | file_content = await file.read() |
| 232 | # Read file content |
| 233 | try: |
| 234 | content = file_content.decode("utf-8") |
| 235 | except UnicodeDecodeError: |
| 236 | # If UTF-8 decoding fails, try other encodings |
| 237 | content = file_content.decode("gbk") |
| 238 | # Insert file content |
| 239 | loop = asyncio.get_event_loop() |
| 240 | await loop.run_in_executor(None, lambda: rag.insert(content)) |
| 241 | |
| 242 | return Response( |
| 243 | status="success", |
| 244 | message=f"File content from {file.filename} inserted successfully", |
| 245 | ) |
| 246 | except Exception as e: |
| 247 | raise HTTPException(status_code=500, detail=str(e)) |
| 248 | |
| 249 | |
| 250 | @app.get("/health") |