Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -53,11 +53,20 @@ class ChatRequest(BaseModel):
|
|
| 53 |
|
| 54 |
@app.post("/chat")
|
| 55 |
async def chat(request: ChatRequest):
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
@app.get("/", response_class=HTMLResponse)
|
| 63 |
async def home():
|
|
|
|
| 53 |
|
| 54 |
@app.post("/chat")
|
| 55 |
async def chat(request: ChatRequest):
|
| 56 |
+
try:
|
| 57 |
+
if request.user_id not in chatbots:
|
| 58 |
+
chatbots[request.user_id] = UofTearsBot(llm)
|
| 59 |
+
current_bot = chatbots[request.user_id]
|
| 60 |
+
response = current_bot.converse(request.user_text)
|
| 61 |
+
return JSONResponse(content={"response": response, "history": current_bot.history})
|
| 62 |
+
except Exception as e:
|
| 63 |
+
import traceback
|
| 64 |
+
traceback.print_exc() # logs full stack trace to HF Logs
|
| 65 |
+
return JSONResponse(
|
| 66 |
+
status_code=500,
|
| 67 |
+
content={"error": str(e)}
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
|
| 71 |
@app.get("/", response_class=HTMLResponse)
|
| 72 |
async def home():
|