Spaces:
Sleeping
Sleeping
Download src/main.py from low-key-007/CHatbotRL: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/spaces/low-key-007/CHatbotRL/resolve/main/src/main.py
- Command line
-
hf download hf://spaces/low-key-007/CHatbotRL/src/main.py
-
curl -L -o main.py https://huggingface.co/spaces/low-key-007/CHatbotRL/resolve/main/src/main.py
1.15 kB
| from fastapi import FastAPI, Request, UploadFile, File | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from src.rag_engine import engine | |
| from src.config import Config | |
| # Import other utils... | |
| app = FastAPI(title="NeuroFolio API", version="2.0") | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_methods=["*"], | |
| allow_headers=["*"] | |
| ) | |
| async def chat_endpoint(req: Request): | |
| body = await req.json() | |
| user_msg = body.get("message", "") | |
| session_id = req.headers.get("X-Session-Id") | |
| # 1. Retrieve Context via RAG Engine | |
| context = engine.retrieve(user_msg) | |
| # 2. Construct System Prompt (Simplified) | |
| system_prompt = f"Context:\n{context}\n\nAnswer the user." | |
| # 3. Call LLM (Logic from your original code goes here) | |
| # ... | |
| return {"reply": "Response generated", "context_used": context} | |
| async def feedback_endpoint(req: Request): | |
| body = await req.json() | |
| # 1. Log Feedback | |
| # 2. Adjust RAG Weights | |
| engine.adjust_weights(body["message"], int(body["rating"])) | |
| return {"status": "weights_updated"} |