-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix: 给kook适配器实现send_streaming方法(降级到普通文本消息发送)来修复启用了流逝输出后可能llm消息发不出去的bug
#7749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,6 @@ | ||||||||
| import asyncio | ||||||||
| import json | ||||||||
| from collections.abc import Coroutine | ||||||||
| from collections.abc import AsyncGenerator, Coroutine | ||||||||
| from pathlib import Path | ||||||||
| from typing import Any | ||||||||
|
|
||||||||
|
|
@@ -208,3 +208,19 @@ async def send(self, message: MessageChain): | |||||||
| logger.error(f"[kook] {err_msg}") | ||||||||
|
|
||||||||
| await super().send(message) | ||||||||
|
|
||||||||
| async def send_streaming( | ||||||||
| self, generator: AsyncGenerator[MessageChain, None], use_fallback: bool = False | ||||||||
| ): | ||||||||
| """KOOK 平台不支持流式输出, 调用此方法将回退到普通`send`方法""" | ||||||||
| buffer = None | ||||||||
| async for chain in generator: | ||||||||
| if not buffer: | ||||||||
| buffer = chain | ||||||||
| else: | ||||||||
| buffer.chain.extend(chain.chain) | ||||||||
| if not buffer: | ||||||||
| return None | ||||||||
| buffer.squash_plain() | ||||||||
| await self.send(buffer) | ||||||||
| return await super().send_streaming(generator, use_fallback) | ||||||||
|
Comment on lines
+225
to
+226
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): Avoid double-processing and using an already-consumed generator in Here the generator is fully consumed into Given the docstring that KOOK does not support streaming and this method should fall back to a normal
This avoids using an exhausted generator and prevents double-sending.
Comment on lines
+225
to
+226
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 在此处调用
Suggested change
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): Use explicit
is Nonecheck forbufferto avoid relying onMessageChaintruthiness.Since
bufferstarts asNone, usingif not buffer:will also trigger ifMessageChainis a valid but falsy value (e.g., empty if it implements__bool__/__len__). That changes behavior betweenNoneand an empty chain. Useif buffer is None:to distinguish the initial state from an emptyMessageChainand make the intent explicit.