diff --git a/maubot_llmplus/aibot.py b/maubot_llmplus/aibot.py index 22e70e9..3cf4b5e 100644 --- a/maubot_llmplus/aibot.py +++ b/maubot_llmplus/aibot.py @@ -1,3 +1,4 @@ +import asyncio import re from typing import Type @@ -176,7 +177,10 @@ class AiBotPlugin(AbsExtraConfigPlugin): formatted_body=markdown.render(display) ) new_content.set_edit(response_event_id) - await self.client.send_message(evt.room_id, new_content) + await asyncio.wait_for( + self.client.send_message(evt.room_id, new_content), + timeout=5.0 + ) last_edit_len = len(accumulated) except Exception as edit_err: self.log.warning(f"Streaming mid-edit failed (skipping): {edit_err}") @@ -195,7 +199,10 @@ class AiBotPlugin(AbsExtraConfigPlugin): formatted_body=markdown.render(accumulated) ) final_content.set_edit(response_event_id) - await self.client.send_message(evt.room_id, final_content) + await asyncio.wait_for( + self.client.send_message(evt.room_id, final_content), + timeout=15.0 + ) def get_ai_platform(self) -> Platform: use_platform = self.config.cur_platform diff --git a/maubot_llmplus/thrid_platform.py b/maubot_llmplus/thrid_platform.py index 308818d..db5cd22 100644 --- a/maubot_llmplus/thrid_platform.py +++ b/maubot_llmplus/thrid_platform.py @@ -1,3 +1,4 @@ +import asyncio import json from collections import deque @@ -185,7 +186,10 @@ class Anthropic(Platform): if response.status != 200: raise ValueError(f"Error: {await response.text()}") while True: - line_bytes = await response.content.readline() + try: + line_bytes = await asyncio.wait_for(response.content.readline(), timeout=60.0) + except asyncio.TimeoutError: + break if not line_bytes: break line = line_bytes.decode("utf-8").strip()