-
-
Notifications
You must be signed in to change notification settings - Fork 968
标准化AstrBot api #2594
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?
标准化AstrBot api #2594
Changes from 14 commits
389a13f
edbed8a
87fe4c4
b1a3c4a
e87b1b4
fde90e0
5bdb104
cd4994c
68ee386
47be122
3c5f7c5
f9334d7
607bfe0
26a6a03
4f8a7d0
03eacd6
b808ac8
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 |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Astrbot API | ||
|
|
||
| 提供了 AstrBot 所有的适合插件使用的 api | ||
|
|
||
| ## API 结构 | ||
|
|
||
| astrbot.api: 包括了所有的导入 | ||
| astrbot.api.all(将弃用): 包括了所有的导入, 由 astrbot.api 代替 | ||
| astrbot.api.message_components(将弃用): 包括了所有消息组件, 由 astrbot.api.event.message.message_components 代替 | ||
|
|
||
| astrbot.api.event: 包括了 AstrBot 事件以及相关类的导入 | ||
| astrbot.api.event.filter(将弃用): 包括了事件过滤器, 用于注册 Handler, 由 astrbot.api.star.register 统一注册来代替 | ||
| astrbot.api.event.message: 包括了 AstrBot 事件中, 所有有关消息的类 | ||
| astrbot.api.api.event.message.message_components: 包括了所有消息组件 | ||
|
|
||
| astrbot.api.platform: 包括了所有平台相关的导入 | ||
|
|
||
| astrbot.api.provider: 包括了所有大模型供应商相关的导入 | ||
|
|
||
| astrbot.api.star: 包括了所有插件相关的导入 | ||
| astrbot.api.star.register: 包括了所有插件注册 Handler 相关的导入 | ||
|
|
||
| astrbot.api.tool: 包括了所有大模型工具, agent 相关的导入 | ||
|
|
||
| astrbot.api.util: 包括了所有的实用工具的导入 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,192 @@ | ||
| """ | ||
| astrbot.api | ||
| 该模块提供最常用最核心的一些接口 | ||
| """ | ||
|
|
||
| # astrbot.api | ||
| from astrbot.core.config.astrbot_config import AstrBotConfig | ||
| from astrbot import logger | ||
| from astrbot.core import html_renderer | ||
| from astrbot.core import sp | ||
| from astrbot.core.star.register import register_llm_tool as llm_tool | ||
|
|
||
| __all__ = ["AstrBotConfig", "logger", "html_renderer", "llm_tool", "sp"] | ||
| # 原: astrbot.api.message_components (已弃用) | ||
| # 现: astrbot.api.event.message.MessageComponents | ||
| from .message_components import ( | ||
| ComponentType, # 枚举所有消息类型名 | ||
| BaseMessageComponent, # 消息类型基类, 如果你需要适配新的消息类型, 可以选择继承此类 | ||
| # 常用消息组件 | ||
| Plain, # 纯文本消息 | ||
| Face, # QQ表情 | ||
| Record, # 语音 | ||
| Video, # 视频 | ||
| At, # @ | ||
| AtAll, # @全体成员 | ||
| Node, # 转发节点 | ||
| Nodes, # 多个转发节点 | ||
| Poke, # QQ 戳一戳 | ||
| Image, # 图片 | ||
| Reply, # 回复消息 | ||
| Forward, # 转发消息 | ||
| File, # 文件 | ||
| # 其他消息组件 | ||
| Music, # 音乐分享 | ||
| Json, # Json 消息 | ||
| TTS, # TTS | ||
| Unknown, # 未知类型 | ||
| # 特定平台消息组件 | ||
| Dice, # 骰子 | ||
| Contact, # 推荐好友/群 | ||
| RPS, # 猜拳魔法表情 | ||
| ## 微信 | ||
| WechatEmoji, # 微信表情 | ||
| # 仅接收 | ||
| Share, # 链接分享 | ||
| Shake, # 私聊窗口抖动 | ||
| ) | ||
|
|
||
| # astrbot.api.event | ||
| from astrbot.core.platform import AstrMessageEvent | ||
| from astrbot.core.message.message_event_result import ( | ||
| MessageEventResult, | ||
| MessageChain, | ||
| CommandResult, | ||
| EventResultType, | ||
| ResultContentType, | ||
| ) | ||
|
|
||
| # astrbot.api.platform | ||
| from astrbot.core.platform import ( | ||
| AstrBotMessage, # AstrBot 消息, 其实应当出现在事件 api 下, 因为它是事件的一部分, 此处保留向后兼容 | ||
| MessageMember, # AstrBot 消息成员, 其实应当出现在事件 api 下, 此处保留向后兼容 | ||
| MessageType, # AstrBot 消息类型, 其实应当出现在事件 api 下, 此处保留向后兼容 | ||
| Platform, | ||
| PlatformMetadata, | ||
| Group, # 一个群聊 | ||
| ) | ||
| from astrbot.core.platform.register import register_platform_adapter | ||
|
|
||
| # astrbot.api.provider | ||
| from astrbot.core.provider import Provider, STTProvider, Personality | ||
| from astrbot.core.provider.entities import ( | ||
| ProviderRequest, | ||
| ProviderType, | ||
| ProviderMetaData, | ||
| LLMResponse, | ||
| ) | ||
|
|
||
| # astrbot.api.star | ||
| from astrbot.core.star.register import ( | ||
| register_star as register, # 注册插件(Star) | ||
| ) | ||
| from astrbot.core.star import Context, Star, StarTools | ||
| from astrbot.core.star.config import load_config, put_config, update_config # 已弃用 | ||
|
|
||
| # 原: astrbot.api.event.filter (已弃用) | ||
| # 现: astrbot.api.star.register | ||
| from astrbot.core.star.register import ( | ||
| register_command as command, # 注册命令 | ||
| register_command_group as command_group, # 注册命令组 | ||
| register_event_message_type as event_message_type, # 注册监听器: 事件消息类型 | ||
| register_regex as regex, # 注册监听器: 正则表达式 | ||
| register_platform_adapter_type as platform_adapter_type, # 注册监听器: 平台适配器类型 | ||
| register_permission_type as permission_type, # 注册监听器: 权限类型 | ||
| register_custom_filter as custom_filter, # 注册监听器: 自定义过滤器 | ||
| register_on_astrbot_loaded as on_astrbot_loaded, # 注册触发器: AstrBot 加载完成时 | ||
| register_on_llm_request as on_llm_request, # 注册触发器: LLM 请求时 | ||
| register_on_llm_response as on_llm_response, # 注册触发器: LLM 响应时 | ||
| register_on_decorating_result as on_decorating_result, # 注册触发器: 装饰结果时 | ||
| register_after_message_sent as after_message_sent, # 注册触发器: 消息发送后 | ||
| register_llm_tool as llm_tool, # 注册 LLM 工具 | ||
| ) | ||
|
|
||
| # 监听器所用到的过滤器和类型 | ||
| from astrbot.core.star.filter.event_message_type import ( | ||
| EventMessageTypeFilter, | ||
| EventMessageType, | ||
| ) | ||
| from astrbot.core.star.filter.platform_adapter_type import ( | ||
| PlatformAdapterTypeFilter, | ||
| PlatformAdapterType, | ||
| ) | ||
| from astrbot.core.star.filter.permission import PermissionTypeFilter, PermissionType | ||
| from astrbot.core.star.filter.custom_filter import CustomFilter | ||
|
|
||
| __all__ = [ | ||
| "AstrBotConfig", | ||
| "logger", | ||
| "html_renderer", | ||
| "llm_tool", | ||
| "sp", | ||
| "ComponentType", | ||
| "BaseMessageComponent", | ||
| "Plain", | ||
| "Face", | ||
| "Record", | ||
| "Video", | ||
| "At", | ||
| "AtAll", | ||
| "Node", | ||
| "Nodes", | ||
| "Poke", | ||
| "Image", | ||
| "Reply", | ||
| "Forward", | ||
| "File", | ||
| "Music", | ||
| "Json", | ||
| "TTS", | ||
| "Unknown", | ||
| "Dice", | ||
| "Contact", | ||
| "RPS", | ||
| "WechatEmoji", | ||
| "Share", | ||
| "Shake", | ||
| "AstrMessageEvent", | ||
| "MessageEventResult", | ||
| "MessageChain", | ||
| "CommandResult", | ||
| "EventResultType", | ||
| "ResultContentType", | ||
| "AstrBotMessage", | ||
| "MessageMember", | ||
| "MessageType", | ||
| "Platform", | ||
| "PlatformMetadata", | ||
| "Group", | ||
| "register_platform_adapter", | ||
| "Provider", | ||
| "STTProvider", | ||
| "Personality", | ||
| "ProviderRequest", | ||
| "ProviderType", | ||
| "ProviderMetaData", | ||
| "LLMResponse", | ||
| "register", | ||
| "Context", | ||
| "Star", | ||
| "StarTools", | ||
| "load_config", | ||
| "put_config", | ||
| "update_config", | ||
| "command", | ||
| "command_group", | ||
| "event_message_type", | ||
| "regex", | ||
| "platform_adapter_type", | ||
| "permission_type", | ||
| "custom_filter", | ||
| "on_astrbot_loaded", | ||
| "on_llm_request", | ||
| "on_llm_response", | ||
| "on_decorating_result", | ||
| "after_message_sent", | ||
| "EventMessageTypeFilter", | ||
| "EventMessageType", | ||
| "PlatformAdapterTypeFilter", | ||
| "PlatformAdapterType", | ||
| "PermissionTypeFilter", | ||
| "PermissionType", | ||
| "CustomFilter", | ||
| ] |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,25 +1,107 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| astrbot.api.all | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 该模块提供AstrBot全部的api接口, 如果不清楚从哪里导入, 可以从这个模块导入 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ⚠️ 标记为已弃用, 不会更新, 请使用 astrbot.api 导入 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # astrbot.api | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from astrbot.core.config.astrbot_config import AstrBotConfig | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from astrbot import logger | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from astrbot.core import html_renderer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from astrbot.core.star.register import register_llm_tool as llm_tool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from astrbot.core import sp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from astrbot.core import sp |
Copilot
AI
Nov 3, 2025
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.
Import of 'ComponentType' is not used.
Import of 'BaseMessageComponent' is not used.
Import of 'Plain' is not used.
Import of 'Face' is not used.
Import of 'Record' is not used.
Import of 'Video' is not used.
Import of 'At' is not used.
Import of 'AtAll' is not used.
Import of 'Node' is not used.
Import of 'Nodes' is not used.
Import of 'Poke' is not used.
Import of 'Image' is not used.
Import of 'Reply' is not used.
Import of 'Forward' is not used.
Import of 'File' is not used.
Import of 'Music' is not used.
Import of 'Json' is not used.
Import of 'TTS' is not used.
Import of 'Unknown' is not used.
Import of 'Dice' is not used.
Import of 'Contact' is not used.
Import of 'RPS' is not used.
Import of 'WechatEmoji' is not used.
Import of 'Share' is not used.
Import of 'Shake' is not used.
| from .message_components import ( | |
| ComponentType, # 枚举所有消息类型名 | |
| BaseMessageComponent, # 消息类型基类, 如果你需要适配新的消息类型, 可以选择继承此类 | |
| # 常用消息组件 | |
| Plain, # 纯文本消息 | |
| Face, # QQ表情 | |
| Record, # 语音 | |
| Video, # 视频 | |
| At, # @ | |
| AtAll, # @全体成员 | |
| Node, # 转发节点 | |
| Nodes, # 多个转发节点 | |
| Poke, # QQ 戳一戳 | |
| Image, # 图片 | |
| Reply, # 回复消息 | |
| Forward, # 转发消息 | |
| File, # 文件 | |
| # 其他消息组件 | |
| Music, # 音乐分享 | |
| Json, # Json 消息 | |
| TTS, # TTS | |
| Unknown, # 未知类型 | |
| # 特定平台消息组件 | |
| Dice, # 骰子 | |
| Contact, # 推荐好友/群 | |
| RPS, # 猜拳魔法表情 | |
| ## 微信 | |
| WechatEmoji, # 微信表情 | |
| # 仅接收 | |
| Share, # 链接分享 | |
| Shake, # 私聊窗口抖动 | |
| ) | |
| # from .message_components import ... # 已弃用, 不再导入消息组件 |
Copilot
AI
Nov 3, 2025
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.
Import of 'AstrMessageEvent' is not used.
| from astrbot.core.platform import AstrMessageEvent |
Copilot
AI
Nov 3, 2025
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.
Import of 'AstrBotMessage' is not used.
Import of 'MessageMember' is not used.
Import of 'MessageType' is not used.
Import of 'Platform' is not used.
Import of 'PlatformMetadata' is not used.
Import of 'Group' is not used.
| from astrbot.core.platform import ( | |
| AstrBotMessage, # AstrBot 消息, 其实应当出现在事件 api 下, 因为它是事件的一部分, 此处保留向后兼容 | |
| MessageMember, # AstrBot 消息成员, 其实应当出现在事件 api 下, 此处保留向后兼容 | |
| MessageType, # AstrBot 消息类型, 其实应当出现在事件 api 下, 此处保留向后兼容 | |
| Platform, | |
| PlatformMetadata, | |
| Group, # 一个群聊 | |
| ) |
Copilot
AI
Nov 3, 2025
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.
Import of 'register_platform_adapter' is not used.
| from astrbot.core.platform.register import register_platform_adapter |
Copilot
AI
Nov 3, 2025
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.
Import of 'Provider' is not used.
Import of 'STTProvider' is not used.
Import of 'Personality' is not used.
| from astrbot.core.provider import Provider, STTProvider, Personality | |
| # from astrbot.core.provider import Provider, STTProvider, Personality # Removed unused imports |
Copilot
AI
Nov 3, 2025
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.
Import of 'ProviderRequest' is not used.
Import of 'ProviderType' is not used.
Import of 'ProviderMetaData' is not used.
Import of 'LLMResponse' is not used.
| ProviderRequest, | |
| ProviderType, | |
| ProviderMetaData, | |
| LLMResponse, | |
| # ProviderRequest, | |
| # ProviderType, | |
| # ProviderMetaData, | |
| # LLMResponse, |
Copilot
AI
Nov 3, 2025
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.
Import of 'Context' is not used.
Import of 'Star' is not used.
Import of 'StarTools' is not used.
| from astrbot.core.star import Context, Star, StarTools | |
| # from astrbot.core.star import Context, Star, StarTools # Removed unused imports |
Copilot
AI
Nov 3, 2025
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.
Import of 'load_config' is not used.
Import of 'put_config' is not used.
Import of 'update_config' is not used.
| from astrbot.core.star.config import load_config, put_config, update_config # 已弃用 |
Copilot
AI
Nov 3, 2025
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.
Import of 'command' is not used.
Import of 'command_group' is not used.
Import of 'event_message_type' is not used.
Import of 'regex' is not used.
Import of 'platform_adapter_type' is not used.
Import of 'permission_type' is not used.
Import of 'custom_filter' is not used.
Import of 'on_astrbot_loaded' is not used.
Import of 'on_llm_request' is not used.
Import of 'on_llm_response' is not used.
Import of 'on_decorating_result' is not used.
Import of 'after_message_sent' is not used.
Import of 'llm_tool' is not used.
| from astrbot.core.star.register import ( | |
| register_command as command, # 注册命令 | |
| register_command_group as command_group, # 注册命令组 | |
| register_event_message_type as event_message_type, # 注册监听器: 事件消息类型 | |
| register_regex as regex, # 注册监听器: 正则表达式 | |
| register_platform_adapter_type as platform_adapter_type, # 注册监听器: 平台适配器类型 | |
| register_permission_type as permission_type, # 注册监听器: 权限类型 | |
| register_custom_filter as custom_filter, # 注册监听器: 自定义过滤器 | |
| register_on_astrbot_loaded as on_astrbot_loaded, # 注册触发器: AstrBot 加载完成时 | |
| register_on_llm_request as on_llm_request, # 注册触发器: LLM 请求时 | |
| register_on_llm_response as on_llm_response, # 注册触发器: LLM 响应时 | |
| register_on_decorating_result as on_decorating_result, # 注册触发器: 装饰结果时 | |
| register_after_message_sent as after_message_sent, # 注册触发器: 消息发送后 | |
| register_llm_tool as llm_tool, # 注册 LLM 工具 | |
| ) | |
| # Removed unused imports: command, command_group, event_message_type, regex, platform_adapter_type, permission_type, custom_filter, on_astrbot_loaded, on_llm_request, on_llm_response, on_decorating_result, after_message_sent, llm_tool |
Copilot
AI
Nov 3, 2025
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.
Import of 'PermissionTypeFilter' is not used.
Import of 'PermissionType' is not used.
| from astrbot.core.star.filter.permission import PermissionTypeFilter, PermissionType | |
| # from astrbot.core.star.filter.permission import PermissionTypeFilter, PermissionType |
Copilot
AI
Nov 3, 2025
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.
Import of 'CustomFilter' is not used.
| from astrbot.core.star.filter.custom_filter import CustomFilter |
Uh oh!
There was an error while loading. Please reload this page.