docs: 补充 LLM Tool 注册文档警告说明#8178
Conversation
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In the English guide, consider wrapping the version-specific
add_llm_toolsvs legacytool_mgr.func_listsnippet in an explicit version note (e.g., a[!NOTE]block) so that readers immediately understand which example applies to which AstrBot version without reading inline comments. - The deprecation and docstring-format warnings are now duplicated in both the English and Chinese guides; to reduce future drift, you might centralize the detailed explanation (e.g., in a shared section or partial) and keep the language-specific docs focused on usage while linking to that canonical section.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the English guide, consider wrapping the version-specific `add_llm_tools` vs legacy `tool_mgr.func_list` snippet in an explicit version note (e.g., a `[!NOTE]` block) so that readers immediately understand which example applies to which AstrBot version without reading inline comments.
- The deprecation and docstring-format warnings are now duplicated in both the English and Chinese guides; to reduce future drift, you might centralize the detailed explanation (e.g., in a shared section or partial) and keep the language-specific docs focused on usage while linking to that canonical section.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request updates the AI documentation in both English and Chinese to include detailed instructions on registering tools with AstrBot. It introduces the add_llm_tools method for version 4.5.1+, explains the @filter.llm_tool decorator, and provides critical warnings regarding deprecated methods and the mandatory Args: block formatting in docstrings for parameter schema generation. Feedback was provided to improve the type accuracy of the example code by using AsyncGenerator for functions that yield results.
|
|
||
| ```py{3,4,5,6,7} | ||
| @filter.llm_tool(name="get_weather") # If name is omitted, the function name is used | ||
| async def get_weather(self, event: AstrMessageEvent, location: str) -> MessageEventResult: |
There was a problem hiding this comment.
由于函数内部使用了 yield 关键字,该函数实际上是一个异步生成器。建议将返回类型注解改为 AsyncGenerator[MessageEventResult, None] 以保持类型准确性。同时请确保已从 typing 或 collections.abc 导入 AsyncGenerator。
| async def get_weather(self, event: AstrMessageEvent, location: str) -> MessageEventResult: | |
| async def get_weather(self, event: AstrMessageEvent, location: str) -> AsyncGenerator[MessageEventResult, None]: |
There was a problem hiding this comment.
依旧,这是示例代码,不是生产代码)
fix #8143 LLM 工具注册相关文档缺少关键警告
Modifications / 改动点
docs/en/dev/star/guides/ai.md:补充缺失的"注册 Tool 到 AstrBot"章节,包含 add_llm_tools() 用法、register_llm_tool() 弃用警告、以及装饰器注册小节(含 Args: 段格式要求)docs/zh/dev/star/guides/ai.md:修正装饰器小节引导语语病("如果请务必" → "请务必"),新增 register_llm_tool() 弃用警告,新增装饰器依赖 docstring Args: 段生成参数 schema 的说明及缺失后果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
Clarify and expand the LLM tool registration guidance in the AI plugin documentation for both English and Chinese versions.
Documentation: