Skip to content

Conversation

@lss233
Copy link
Owner

@lss233 lss233 commented May 5, 2025

fixes #1469

好的,这是翻译成中文的 pull request 总结:

Sourcery 总结

修复 Telegram 多模态消息处理和工作流执行超时问题

Bug 修复:

  • 改进了对带有标题和实体的 Telegram 消息的处理
  • 修复了工作流执行超时逻辑,以处理负超时值
  • 更新了前缀匹配规则,使其适用于多模态消息

增强功能:

  • 增强了 Telegram 消息解析,以支持不同的消息类型
  • 简化了工作流超时实现
Original summary in English

Summary by Sourcery

Fix Telegram multi-modal message handling and workflow execution timeout issues

Bug Fixes:

  • Improved handling of Telegram messages with captions and entities
  • Fixed workflow execution timeout logic to handle negative timeout values
  • Updated prefix matching rule to work with multi-modal messages

Enhancements:

  • Enhanced Telegram message parsing to support different message types
  • Simplified workflow timeout implementation

- Updated TelegramAdapter to support both text and caption messages, improving message processing capabilities.
- Modified message_rules to check for TextMessage instances when matching prefixes, enhancing rule accuracy.
- Improved WorkflowExecutor to handle negative timeout values gracefully, ensuring robust execution management.
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented May 5, 2025

## Reviewer's Guide

此拉取请求修改了 Telegram 消息适配器,以正确处理多模态消息(带有媒体/标题的文本),并更新了前缀匹配规则以处理这些消息。它还简化了工作流执行超时逻辑。

### File-Level Changes

| Change | Details | Files |
| ------ | ------- | ----- |
| 更新了 Telegram 消息转换以处理标题和相关的实体。 | <ul><li>修改了 `convert_to_message` 以检查 `message.caption` 以及 `message.text`。</li><li>处理了 `message.caption_entities` 以及 `message.entities`。</li><li>使用了 `MessageEntityType` 枚举来进行实体类型检查,而不是字符串字面量。</li></ul> | `kirara_ai/plugins/im_telegram_adapter/adapter.py` |
| 修改了前缀匹配规则以在消息元素中进行检查。 | <ul><li>更新了 `PrefixRule.match` 以迭代 `message.message_elements`。</li><li>检查是否有任何 `TextMessage` 元素以指定的前缀开头。</li></ul> | `kirara_ai/workflow/core/dispatch/rules/message_rules.py` |
| 简化了工作流执行超时处理。 | <ul><li>移除了对 `max_timeout > 0` 的显式检查。</li><li>如果 `max_timeout` 为负数,则将其设置为 `None`,允许直接与 `asyncio.timeout` 一起使用(其中 `None` 表示没有超时)。</li></ul> | `kirara_ai/workflow/core/execution/executor.py` |

### Assessment against linked issues

| Issue | Objective | Addressed | Explanation |
| ------ | ------- | ----- | ----- |
| #1469 | 机器人应该在 Telegram 群聊中通过 @ 或关键词被触发时响应。 | ✅ |  |
| #1469 | 机器人应该正确地将图片上传到 API 并在 Telegram 群聊中回复。 | ✅ |  |

---

<details>
<summary>Tips and commands</summary>

#### Interacting with Sourcery

- **Trigger a new review:** Comment `@sourcery-ai review` on the pull request.
- **Continue discussions:** Reply directly to Sourcery's review comments.
- **Generate a GitHub issue from a review comment:** Ask Sourcery to create an
  issue from a review comment by replying to it. You can also reply to a
  review comment with `@sourcery-ai issue` to create an issue from it.
- **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull
  request title to generate a title at any time. You can also comment
  `@sourcery-ai title` on the pull request to (re-)generate the title at any time.
- **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in
  the pull request body to generate a PR summary at any time exactly where you
  want it. You can also comment `@sourcery-ai summary` on the pull request to
  (re-)generate the summary at any time.
- **Generate reviewer's guide:** Comment `@sourcery-ai guide` on the pull
  request to (re-)generate the reviewer's guide at any time.
- **Resolve all Sourcery comments:** Comment `@sourcery-ai resolve` on the
  pull request to resolve all Sourcery comments. Useful if you've already
  addressed all the comments and don't want to see them anymore.
- **Dismiss all Sourcery reviews:** Comment `@sourcery-ai dismiss` on the pull
  request to dismiss all existing Sourcery reviews. Especially useful if you
  want to start fresh with a new review - don't forget to comment
  `@sourcery-ai review` to trigger a new review!

#### Customizing Your Experience

Access your [dashboard](https://app.sourcery.ai) to:
- Enable or disable review features such as the Sourcery-generated pull request
  summary, the reviewer's guide, and others.
- Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.

#### Getting Help

- [Contact our support team](mailto:[email protected]) for questions or feedback.
- Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information.
- Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).

</details>
Original review guide in English

Reviewer's Guide

This pull request modifies the Telegram message adapter to correctly handle multimodal messages (text with media/captions) and updates the prefix matching rule to work with these messages. It also simplifies the workflow execution timeout logic.

File-Level Changes

Change Details Files
Updated Telegram message conversion to handle captions and associated entities.
  • Modified convert_to_message to check message.caption in addition to message.text.
  • Processed message.caption_entities alongside message.entities.
  • Used MessageEntityType enum for entity type checks instead of string literals.
kirara_ai/plugins/im_telegram_adapter/adapter.py
Modified prefix matching rule to check within message elements.
  • Updated PrefixRule.match to iterate through message.message_elements.
  • Checks if any TextMessage element starts with the specified prefix.
kirara_ai/workflow/core/dispatch/rules/message_rules.py
Simplified workflow execution timeout handling.
  • Removed explicit check for max_timeout > 0.
  • Set max_timeout to None if negative, allowing direct use with asyncio.timeout (where None means no timeout).
kirara_ai/workflow/core/execution/executor.py

Assessment against linked issues

Issue Objective Addressed Explanation
#1469 The bot should be triggered in Telegram group chats when mentioned via @ or keywords.
#1469 The bot should correctly upload images to the API and respond in Telegram group chats.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov
Copy link

codecov bot commented May 5, 2025

Codecov Report

Attention: Patch coverage is 46.15385% with 7 lines in your changes missing coverage. Please review.

Project coverage is 61.09%. Comparing base (bc892dd) to head (8b76abb).

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...a_ai/workflow/core/dispatch/rules/message_rules.py 20.00% 4 Missing ⚠️
kirara_ai/workflow/core/execution/executor.py 62.50% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1480      +/-   ##
==========================================
- Coverage   61.11%   61.09%   -0.02%     
==========================================
  Files         168      168              
  Lines        9243     9246       +3     
==========================================
  Hits         5649     5649              
- Misses       3594     3597       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lss233 - 我已经查看了你的更改 - 这里有一些反馈:

  • 考虑一下 PrefixRule 是否应该只在第一个 TextMessage 元素以该前缀开头时匹配,而不是消息中的任何 TextMessage 元素。
  • 验证 executor.py 中更新的超时逻辑是否根据预期行为正确处理 max_execution_time 值为 0 和负数的情况(立即超时与无超时)。
以下是我在审查期间查看的内容
  • 🟡 General issues: 发现 1 个问题
  • 🟢 Security: 一切看起来都很好
  • 🟢 Testing: 一切看起来都很好
  • 🟢 Complexity: 一切看起来都很好
  • 🟢 Documentation: 一切看起来都很好

Sourcery 对开源项目是免费的 - 如果你喜欢我们的评论,请考虑分享它们 ✨
请帮助我变得更有用!请点击每个评论上的 👍 或 👎,我将使用这些反馈来改进你的评论。
Original comment in English

Hey @lss233 - I've reviewed your changes - here's some feedback:

  • Consider if the PrefixRule should only match if the first TextMessage element starts with the prefix, rather than any TextMessage element within the message.
  • Verify that the updated timeout logic in executor.py correctly handles max_execution_time values of 0 and negative numbers according to the intended behavior (immediate timeout vs. no timeout).
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@github-actions
Copy link

github-actions bot commented May 5, 2025

MyPy 类型检查通过 ✅

PR 修改的代码行通过了类型检查。

lss233 and others added 2 commits May 6, 2025 01:16
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
- Modified the timeout condition in WorkflowExecutor to allow for zero or negative values, ensuring no execution time limit is enforced in such cases. This change improves the robustness of workflow execution management.
@lss233 lss233 merged commit 1610605 into master May 5, 2025
5 of 6 checks passed
@lss233 lss233 deleted the fix/telegram_dispatch_rules branch May 5, 2025 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] 多模态功能 - TG群聊内无法触发

2 participants