Skip to content

Commit 850ba0a

Browse files
committed
Added frontend messages for common errors.
1 parent 08a1530 commit 850ba0a

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

main_helper/core.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,14 @@ async def send_lanlan_response(self, text: str, is_first_chunk: bool = False):
250250
except Exception as e:
251251
logger.error(f"💥 WS Send Lanlan Response Error: {e}")
252252

253-
async def handle_connection_error(self):
253+
async def handle_connection_error(self, message=None):
254+
if message:
255+
if '欠费' in message:
256+
await self.send_status("💥 智谱API触发欠费bug。请考虑充值1元。")
257+
elif 'standing' in message:
258+
await self.send_status("💥 阿里API已欠费。")
259+
else:
260+
await self.send_status(message)
254261
logger.info("💥 Session closed by API Server.")
255262
await self.disconnected_by_server()
256263

@@ -358,6 +365,10 @@ async def start_session(self, websocket: WebSocket, new=False):
358365
logger.error(f"💥 {error_message}")
359366
traceback.print_exc()
360367
await self.send_status(error_message)
368+
if 'actively refused it' in str(e):
369+
await self.send_status("💥 记忆服务器已崩溃。请检查API Key是否正确。")
370+
elif '401' in str(e):
371+
await self.send_status("💥 API Key被服务器拒绝。请检查API Key是否与所选模型匹配。")
361372
await self.cleanup()
362373

363374
async def send_user_activity(self):

main_helper/omni_realtime_client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __init__(
6565
on_interrupt: Optional[Callable[[], Awaitable[None]]] = None,
6666
on_input_transcript: Optional[Callable[[str], Awaitable[None]]] = None,
6767
on_output_transcript: Optional[Callable[[str, bool], Awaitable[None]]] = None,
68-
on_connection_error: Optional[Callable[[], Awaitable[None]]] = None,
68+
on_connection_error: Optional[Callable[[str], Awaitable[None]]] = None,
6969
on_response_done: Optional[Callable[[], Awaitable[None]]] = None,
7070
extra_event_handlers: Optional[Dict[str, Callable[[Dict[str, Any]], Awaitable[None]]]] = None
7171
):
@@ -247,6 +247,10 @@ async def handle_messages(self) -> None:
247247
# print(f"Event type: {event_type}")
248248
if event_type == "error":
249249
logger.error(f"API Error: {event['error']}")
250+
if '欠费' in event['error'] or 'standing' in event['error']:
251+
if self.handle_connection_error:
252+
await self.handle_connection_error(event['error'])
253+
await self.close()
250254
continue
251255
elif event_type == "response.done":
252256
self._is_responding = False

0 commit comments

Comments
 (0)