add
This commit is contained in:
@@ -167,16 +167,19 @@ class AiBotPlugin(AbsExtraConfigPlugin):
|
|||||||
async for chunk in platform.create_chat_completion_stream(self, evt):
|
async for chunk in platform.create_chat_completion_stream(self, evt):
|
||||||
accumulated += chunk
|
accumulated += chunk
|
||||||
if len(accumulated) - last_edit_len >= EDIT_THRESHOLD:
|
if len(accumulated) - last_edit_len >= EDIT_THRESHOLD:
|
||||||
display = accumulated + " ▌"
|
try:
|
||||||
new_content = TextMessageEventContent(
|
display = accumulated + " ▌"
|
||||||
msgtype=MessageType.TEXT,
|
new_content = TextMessageEventContent(
|
||||||
body=display,
|
msgtype=MessageType.TEXT,
|
||||||
format=Format.HTML,
|
body=display,
|
||||||
formatted_body=markdown.render(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)
|
new_content.set_edit(response_event_id)
|
||||||
last_edit_len = len(accumulated)
|
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:
|
except Exception as e:
|
||||||
self.log.exception(f"Streaming error: {e}")
|
self.log.exception(f"Streaming error: {e}")
|
||||||
if not accumulated:
|
if not accumulated:
|
||||||
|
|||||||
Reference in New Issue
Block a user