Spaces:
Running
Running
Commit ·
934c6ee
1
Parent(s): a74720f
Upload app.py
Browse files- src/apps/app.py +14 -7
src/apps/app.py
CHANGED
|
@@ -483,10 +483,15 @@ async def stream_text_conversational(websocket: WebSocket, query: str, role: str
|
|
| 483 |
if len(chat_history)>chat_limit:
|
| 484 |
chat_history.pop(0)
|
| 485 |
except Exception as e:
|
| 486 |
-
|
| 487 |
-
print(f"Chatbot error: {
|
| 488 |
-
|
| 489 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 490 |
|
| 491 |
@app.websocket("/conversational_chat")
|
| 492 |
async def conversational_chat(websocket: WebSocket, role: Optional[str] = None):
|
|
@@ -563,10 +568,12 @@ async def conversational_chat(websocket: WebSocket, role: Optional[str] = None):
|
|
| 563 |
except Exception as e:
|
| 564 |
print(f"WebSocket error: {e}")
|
| 565 |
try:
|
| 566 |
-
await websocket.send_text(
|
|
|
|
|
|
|
|
|
|
| 567 |
except:
|
| 568 |
-
|
| 569 |
-
break
|
| 570 |
|
| 571 |
|
| 572 |
# Run the application
|
|
|
|
| 483 |
if len(chat_history)>chat_limit:
|
| 484 |
chat_history.pop(0)
|
| 485 |
except Exception as e:
|
| 486 |
+
error_str = str(e)
|
| 487 |
+
print(f"Chatbot error: {error_str}")
|
| 488 |
+
# Show a professional message — never dump raw API errors to users
|
| 489 |
+
if "404" in error_str or "No endpoints" in error_str:
|
| 490 |
+
user_msg = "\n\n⚠️ **Service Temporarily Unavailable**\nThe AI provider is currently unavailable. Please send your message again — the system will automatically switch to an alternative model.\n\nIf the issue persists, please try again in a moment."
|
| 491 |
+
else:
|
| 492 |
+
user_msg = f"\n\n⚠️ **An error occurred.** Please try sending your message again.\n\n_If the issue persists, please contact support._"
|
| 493 |
+
await websocket.send_text(user_msg)
|
| 494 |
+
await websocket.send_text("[DONE]")
|
| 495 |
|
| 496 |
@app.websocket("/conversational_chat")
|
| 497 |
async def conversational_chat(websocket: WebSocket, role: Optional[str] = None):
|
|
|
|
| 568 |
except Exception as e:
|
| 569 |
print(f"WebSocket error: {e}")
|
| 570 |
try:
|
| 571 |
+
await websocket.send_text(
|
| 572 |
+
"\n\n⚠️ **Connection interrupted.** Please try sending your message again."
|
| 573 |
+
)
|
| 574 |
+
await websocket.send_text("[DONE]")
|
| 575 |
except:
|
| 576 |
+
break
|
|
|
|
| 577 |
|
| 578 |
|
| 579 |
# Run the application
|