Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces message chain splitting by media type for the QQ Official platform adapter, ensuring that each message chunk contains at most one media component (Image, Record, Video, or File). This is handled in both QQOfficialMessageEvent and QQOfficialPlatformAdapter, with accompanying unit tests. The review feedback points out that the use_markdown_ attribute of the original MessageChain is not preserved when creating the split chunks, and suggests refactoring the chunk creation into a helper function to ensure all necessary attributes are copied correctly.
| chunks.append( | ||
| MessageChain( | ||
| chain=current_chain, | ||
| use_t2i_=message.use_t2i_, | ||
| type=message.type, | ||
| ) | ||
| ) | ||
| current_chain = [] | ||
| current_has_media = False | ||
|
|
||
| current_chain.append(component) | ||
| current_has_media = current_has_media or is_media | ||
|
|
||
| if current_chain or not message.chain: | ||
| chunks.append( | ||
| MessageChain( | ||
| chain=current_chain, | ||
| use_t2i_=message.use_t2i_, | ||
| type=message.type, | ||
| ) | ||
| ) |
There was a problem hiding this comment.
In _split_message_chain_by_media, when splitting the message chain, the use_markdown_ attribute of the original MessageChain is not copied to the new chunks. To avoid code duplication when creating these chunks in multiple places, please refactor the chunk creation logic into a shared helper function that copies all necessary attributes (like use_markdown_). Also, remember to update _post_send_one (line 293) to use message_to_send instead of self.send_buffer when retrieving use_markdown_ to keep it self-contained.
def create_chunk(current_chain):
chunk = MessageChain(
chain=current_chain,
use_t2i_=message.use_t2i_,
type=message.type,
)
if hasattr(message, "use_markdown_"):
chunk.use_markdown_ = message.use_markdown_
return chunkReferences
- When implementing similar functionality for different cases, refactor the logic into a shared helper function to avoid code duplication.
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
_post_send, streaming is disabled for all chunks whenever the message is split (viastream_for_chain = stream if len(message_chains) == 1 else None); if the intent is to stream text-only parts even when media is present later, consider decidingstreamper chunk based on whether that chunk contains media. - In
_post_send_one, the guardif not message_to_send:depends onMessageChain's truthiness semantics; if the actual intent is to skip empty chains, it would be more explicit and robust to checkif not message_to_send.chain:instead.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `_post_send`, streaming is disabled for all chunks whenever the message is split (via `stream_for_chain = stream if len(message_chains) == 1 else None`); if the intent is to stream text-only parts even when media is present later, consider deciding `stream` per chunk based on whether that chunk contains media.
- In `_post_send_one`, the guard `if not message_to_send:` depends on `MessageChain`'s truthiness semantics; if the actual intent is to skip empty chains, it would be more explicit and robust to check `if not message_to_send.chain:` instead.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
fixes: #8210
Modifications / 改动点
Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Update QQ Official message sending to split message chains by media elements and adjust sending behavior accordingly.
New Features:
Enhancements:
Tests: