Skip to content

飞书回复新增思考过程,https://github.com/AstrBotDevs/AstrBot/issues/1415 #1421

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mio4kon
Copy link

@mio4kon mio4kon commented Apr 27, 2025

解决了 #1415

Motivation

提高飞书交互体验。

  • 调用LLM之前增加等待交互,LLM请求完成后更新等待内容。
  • 未配置提供商时,有对应提示给用户。
  • 😊 我的 Commit Message 符合良好的规范
  • 👀 我的更改经过良好的测试
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。
  • 😮 我的更改没有引入恶意代码

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

Sourcery 总结

通过在 Lark (飞书) 上显示“思考中”指示器来改善用户体验,以提示正在处理请求。

新功能:

  • 在收到请求后立即在 Lark 上发送“思考中...”消息(在私信中或被提及时)。
  • 完成后,将“思考中...”消息替换为最终回复。
  • 对“思考中...”消息和最终回复均使用 Lark 互动卡片。
  • 如果没有可用的 LLM 提供程序,则通过 Lark 通知用户。
Original summary in English

Summary by Sourcery

Improve the user experience on Lark (Feishu) by showing a "thinking" indicator while processing requests.

New Features:

  • Send a "thinking..." message on Lark immediately upon receiving a request (in DMs or when mentioned).
  • Replace the "thinking..." message with the final response upon completion.
  • Utilize Lark interactive cards for both "thinking" messages and final replies.
  • Notify the user via Lark if no LLM provider is available.

Copy link
Contributor

sourcery-ai bot commented Apr 27, 2025

## Sourcery 评审指南

此 Pull Request 实现了 Lark 平台集成的功能,旨在改善 LLM 处理期间的用户体验。它引入了一个“思考中”消息,该消息在收到用户的查询后立即发送,并在最终 LLM 响应可用时更新。这是通过发送初始交互式卡片消息并随后更新它来实现的。

_由于更改看起来很简单,不需要可视化表示,因此未生成任何图表。_

### 文件级别更改

| 变更 | 详情 | 文件 |
| ------ | ------- | ----- |
| 在 Lark 中实现发送和更新交互式“思考中”消息。 | <ul><li>将 `thinking_message_id` 添加到 `LarkMessageEvent` 以跟踪临时消息。</li><li>添加辅助方法(`_create_card_content`,`_extract_message_text`)以处理交互式卡片消息内容。</li><li>添加方法(`_send_new_message`,`_update_message`)以发送新的交互式消息和更新现有消息。</li><li>修改主要的 `send` 方法,以根据 `thinking_message_id` 的存在使用新的更新/发送逻辑。</li><li>在适配器中添加 `_send_thinking_message` 方法以发送初始“思考中”消息。</li><li>修改适配器中的消息处理(`convert_msg`),以便为直接消息或群组中提及机器人的消息发送初始思考消息,并将消息 ID 存储在事件对象上。</li></ul> | `astrbot/core/platform/sources/lark/lark_event.py`<br/>`astrbot/core/platform/sources/lark/lark_adapter.py` |
| 为处理管道中缺少的 LLM 提供程序添加错误处理。 | <ul><li>修改 `LLMRequestStage` 以设置错误消息,如果没有找到 LLM 提供程序,则停止事件处理。</li></ul> | `astrbot/core/pipeline/process_stage/stage.py` |

### 可能相关的 issue

- **#1415**: 此 PR 在等待 LLM 响应时在飞书中添加了一个临时的“思考中”消息,并在之后对其进行更新。这直接实现了该 issue 的建议。
- **#1415**: 此 PR 在 LLM 调用期间为飞书添加了一个“思考中”消息,并改进了对缺少提供程序的错误处理,从而解决了该 issue 的某些方面。

---

<details>
<summary>提示和命令</summary>

#### 与 Sourcery 互动

- **触发新的审查:** 在 pull request 上评论 `@sourcery-ai review`。
- **继续讨论:** 直接回复 Sourcery 的审查评论。
- **从审查评论生成 GitHub issue:** 通过回复审查评论,要求 Sourcery 从审查评论创建一个 issue。您也可以回复审查评论并使用 `@sourcery-ai issue` 从中创建一个 issue。
- **生成 pull request 标题:** 在 pull request 标题中的任何位置写入 `@sourcery-ai` 以随时生成标题。您也可以在 pull request 上评论 `@sourcery-ai title` 以随时(重新)生成标题。
- **生成 pull request 摘要:** 在 pull request 正文中的任何位置写入 `@sourcery-ai summary` 以随时在您想要的位置生成 PR 摘要。您也可以在 pull request 上评论 `@sourcery-ai summary` 以随时(重新)生成摘要。
- **生成评审指南:** 在 pull request 上评论 `@sourcery-ai guide` 以随时(重新)生成评审指南。
- **解决所有 Sourcery 评论:** 在 pull request 上评论 `@sourcery-ai resolve` 以解决所有 Sourcery 评论。如果您已经解决了所有评论并且不想再看到它们,这将非常有用。
- **驳回所有 Sourcery 审查:** 在 pull request 上评论 `@sourcery-ai dismiss` 以驳回所有现有的 Sourcery 审查。如果您想重新开始新的审查,这将特别有用 - 不要忘记评论 `@sourcery-ai review` 以触发新的审查!

#### 自定义您的体验

访问您的 [仪表板](https://app.sourcery.ai) 以:
- 启用或禁用审查功能,例如 Sourcery 生成的 pull request 摘要、评审指南等。
- 更改审查语言。
- 添加、删除或编辑自定义审查说明。
- 调整其他审查设置。

#### 获得帮助

- [联系我们的支持团队](mailto:[email protected]) 提出问题或反馈。
- 访问我们的 [文档](https://docs.sourcery.ai) 以获取详细的指南和信息。
- 通过在 [X/Twitter](https://x.com/SourceryAI)、[LinkedIn](https://www.linkedin.com/company/sourcery-ai/) 或 [GitHub](https://github.com/sourcery-ai) 上关注我们,与 Sourcery 团队保持联系。

</details>
Original review guide in English

Reviewer's Guide by Sourcery

This pull request implements a feature for Lark platform integration to improve user experience during LLM processing. It introduces a 'thinking' message that is sent immediately after receiving a user's query and is updated with the final LLM response once available. This is achieved by sending an initial interactive card message and subsequently updating it.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Implement sending and updating of an interactive 'thinking' message in Lark.
  • Add thinking_message_id to LarkMessageEvent to track the temporary message.
  • Add helper methods (_create_card_content, _extract_message_text) for handling interactive card message content.
  • Add methods (_send_new_message, _update_message) for sending new interactive messages and updating existing ones.
  • Modify the main send method to use the new update/send logic based on the presence of thinking_message_id.
  • Add _send_thinking_message method in the adapter to send the initial 'thinking' message.
  • Modify message processing in the adapter (convert_msg) to send the initial thinking message for direct messages or messages where the bot is mentioned in a group, and store the message ID on the event object.
astrbot/core/platform/sources/lark/lark_event.py
astrbot/core/platform/sources/lark/lark_adapter.py
Add error handling for missing LLM providers in the processing pipeline.
  • Modify the LLMRequestStage to set an error message and stop event processing if no LLM provider is found.
astrbot/core/pipeline/process_stage/stage.py

Possibly linked issues


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

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.

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

总体评论

  • 仅使用提取的文本在更新的卡片中发送最终响应可能无法完全代表最初包含图像或其他富媒体的回复。
以下是我在审查期间查看的内容
  • 🟡 一般问题:发现 1 个问题
  • 🟢 安全性:一切看起来都很好
  • 🟢 测试:一切看起来都很好
  • 🟢 复杂性:一切看起来都很好
  • 🟢 文档:一切看起来都很好

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

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

Overall Comments:

  • Sending the final response within an updated card using only extracted text might not fully represent replies originally containing images or other rich media.
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.

Copy link
Member

@Soulter Soulter left a comment

Choose a reason for hiding this comment

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

这个更改是否会导致在开启了分段回复或者插件用这个 Event 发送多条消息的情况下(即触发多次 send())会一直编辑同一条消息?

@Soulter Soulter force-pushed the feat-support-lark-thinking-msg branch from 3c3d4ce to 58f6c84 Compare April 29, 2025 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants