42Cummer commited on
Commit
756c3ae
·
verified ·
1 Parent(s): 231999e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -53,11 +53,20 @@ class ChatRequest(BaseModel):
53
 
54
  @app.post("/chat")
55
  async def chat(request: ChatRequest):
56
- if request.user_id not in chatbots:
57
- chatbots[request.user_id] = UofTearsBot(llm)
58
- current_bot = chatbots[request.user_id]
59
- response = current_bot.converse(request.user_text)
60
- return JSONResponse(content={"response": response, "history": current_bot.history})
 
 
 
 
 
 
 
 
 
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():