From 1070cf517f7a6311ccabd770bfc08a8f835684be Mon Sep 17 00:00:00 2001 From: taylorxie Date: Mon, 9 Mar 2026 23:06:06 +0800 Subject: [PATCH] add --- maubot_llmplus/aibot.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) 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: