diff --git a/maubot_llmplus/aibot.py b/maubot_llmplus/aibot.py index 917136e..22e70e9 100644 --- a/maubot_llmplus/aibot.py +++ b/maubot_llmplus/aibot.py @@ -167,16 +167,19 @@ class AiBotPlugin(AbsExtraConfigPlugin): async for chunk in platform.create_chat_completion_stream(self, evt): accumulated += chunk if len(accumulated) - last_edit_len >= EDIT_THRESHOLD: - display = accumulated + " ▌" - new_content = TextMessageEventContent( - msgtype=MessageType.TEXT, - body=display, - format=Format.HTML, - formatted_body=markdown.render(display) - ) - new_content.set_edit(response_event_id) - await self.client.send_message(evt.room_id, new_content) - last_edit_len = len(accumulated) + try: + display = accumulated + " ▌" + new_content = TextMessageEventContent( + msgtype=MessageType.TEXT, + body=display, + format=Format.HTML, + formatted_body=markdown.render(display) + ) + new_content.set_edit(response_event_id) + await self.client.send_message(evt.room_id, new_content) + last_edit_len = len(accumulated) + except Exception as edit_err: + self.log.warning(f"Streaming mid-edit failed (skipping): {edit_err}") except Exception as e: self.log.exception(f"Streaming error: {e}") if not accumulated: