@@ -640,7 +640,7 @@ async def test(self, event: AstrMessageEvent):
640640
641641> 当前适配情况:仅 aiocqhttp
642642
643- QQ 表情 ID 参考:https://bot.q.qq.com/wiki/develop/api-v2/openapi/emoji/model.html#EmojiType
643+ QQ 表情 ID 参考:< https://bot.q.qq.com/wiki/develop/api-v2/openapi/emoji/model.html#EmojiType >
644644
645645``` python
646646from astrbot.api.event import filter , AstrMessageEvent
@@ -653,7 +653,6 @@ async def test(self, event: AstrMessageEvent):
653653
654654![ 发送 QQ 表情] ( ../../source/images/plugin/image-5.png )
655655
656-
657656### 控制事件传播
658657
659658``` python{6}
@@ -764,7 +763,6 @@ class ConfigPlugin(Star):
764763
765764如果您在发布不同版本时更新了 Schema,请注意,AstrBot 会递归检查 Schema 的配置项,如果发现配置文件中缺失了某个配置项,会自动添加默认值。但是 AstrBot 不会删除配置文件中** 多余的** 配置项,即使这个配置项在新的 Schema 中不存在(您在新的 Schema 中删除了这个配置项)。
766765
767-
768766### 文转图
769767
770768#### 基本
@@ -942,8 +940,6 @@ await empty_mention_waiter(event, session_filter=CustomFilter()) # 这里传入
942940
943941甚至,可以使用这个特性来让群内组队!
944942
945-
946-
947943### AI
948944
949945#### 通过提供商调用 LLM
@@ -980,8 +976,8 @@ async def test(self, event: AstrMessageEvent):
980976- ` model ` (str): 可选。用于强制指定使用的模型。默认使用这个提供商默认配置的模型。
981977- ` tool_calls_result ` (dict): 可选。用于传入工具调用的结果。
982978
983-
984979::: details LLMResponse 类型定义
980+
985981``` py
986982
987983@dataclass
@@ -1078,6 +1074,7 @@ class LLMResponse:
10781074 )
10791075 return ret
10801076```
1077+
10811078:::
10821079
10831080#### 获取其他类型的提供商
@@ -1090,7 +1087,6 @@ class LLMResponse:
10901087- 获取所有语音合成提供商: ` self.context.get_all_tts_providers() ` 。
10911088- 获取所有嵌入提供商: ` self.context.get_all_embedding_providers() ` 。
10921089
1093-
10941090::: details STTProvider / TTSProvider / EmbeddingProvider 类型定义
10951091
10961092``` py
@@ -1158,8 +1154,8 @@ from dataclasses import dataclass, field
11581154
11591155@dataclass
11601156class HelloWorldTool (FunctionTool ):
1161- name: str = " hello_world"
1162- description: str = " Say hello to the world."
1157+ name: str = " hello_world" # 工具名称
1158+ description: str = " Say hello to the world." # 工具描述
11631159 parameters: dict = field(
11641160 default_factory = lambda : {
11651161 " type" : " object" ,
@@ -1171,12 +1167,12 @@ class HelloWorldTool(FunctionTool):
11711167 },
11721168 " required" : [" greeting" ],
11731169 }
1174- )
1170+ ) # 工具参数定义,见 OpenAI 官网或 https://json-schema.org/understanding-json-schema/
11751171
11761172 async def run (
11771173 self ,
1178- event : AstrMessageEvent,
1179- greeting : str ,
1174+ event : AstrMessageEvent, # 必须包含此 event 参数在前面,用于获取上下文
1175+ greeting : str , # 工具参数,必须与 parameters 中定义的参数名一致
11801176 ):
11811177 return f " { greeting} , World! " # 也支持 mcp.types.CallToolResult 类型
11821178```
@@ -1221,6 +1217,7 @@ async def get_weather(self, event: AstrMessageEvent, location: str) -> MessageEv
12211217
12221218> [ !NOTE]
12231219> 对于装饰器注册的 llm_tool,如果需要调用 Provider.text_chat(),func_tool(ToolSet 类型) 可以通过以下方式获取:
1220+ >
12241221> ``` py
12251222> func_tool = self .context.get_llm_tool_manager() # 获取 AstrBot 的 LLM Tool Manager,包含了所有插件和 MCP 注册的 Tool
12261223> tool = func_tool.get_func(" xxx" )
@@ -1242,8 +1239,8 @@ curr_cid = await conv_mgr.get_curr_conversation_id(uid)
12421239conversation = await conv_mgr.get_conversation(uid, curr_cid) # Conversation
12431240```
12441241
1245-
12461242::: details Conversation 类型定义
1243+
12471244``` py
12481245@dataclass
12491246class Conversation :
@@ -1267,13 +1264,13 @@ class Conversation:
12671264 created_at: int = 0
12681265 updated_at: int = 0
12691266```
1270- :::
1271-
12721267
1268+ :::
12731269
12741270** 所有方法**
12751271
12761272##### ` new_conversation `
1273+
12771274- ** Usage**
12781275 在当前会话中新建一条对话,并自动切换为该对话。
12791276- ** Arguments**
@@ -1286,6 +1283,7 @@ class Conversation:
12861283 ` str ` – 新生成的 UUID 对话 ID
12871284
12881285##### ` switch_conversation `
1286+
12891287- ** Usage**
12901288 将会话切换到指定的对话。
12911289- ** Arguments**
@@ -1295,6 +1293,7 @@ class Conversation:
12951293 ` None `
12961294
12971295##### ` delete_conversation `
1296+
12981297- ** Usage**
12991298 删除会话中的某条对话;若 ` conversation_id ` 为 ` None ` ,则删除当前对话。
13001299- ** Arguments**
@@ -1304,6 +1303,7 @@ class Conversation:
13041303 ` None `
13051304
13061305##### ` get_curr_conversation_id `
1306+
13071307- ** Usage**
13081308 获取当前会话正在使用的对话 ID。
13091309- ** Arguments**
@@ -1312,6 +1312,7 @@ class Conversation:
13121312 ` str | None ` – 当前对话 ID,不存在时返回 ` None `
13131313
13141314##### ` get_conversation `
1315+
13151316- ** Usage**
13161317 获取指定对话的完整对象;若不存在且 ` create_if_not_exists=True ` 则自动创建。
13171318- ** Arguments**
@@ -1322,6 +1323,7 @@ class Conversation:
13221323 ` Conversation | None `
13231324
13241325##### ` get_conversations `
1326+
13251327- ** Usage**
13261328 拉取用户或平台下的全部对话列表。
13271329- ** Arguments**
@@ -1331,6 +1333,7 @@ class Conversation:
13311333 ` List[Conversation] `
13321334
13331335##### ` get_filtered_conversations `
1336+
13341337- ** Usage**
13351338 分页 + 关键词搜索对话。
13361339- ** Arguments**
@@ -1343,6 +1346,7 @@ class Conversation:
13431346 ` tuple[list[Conversation], int] ` – 对话列表与总数
13441347
13451348##### ` update_conversation `
1349+
13461350- ** Usage**
13471351 更新对话的标题、历史记录或 persona_id。
13481352- ** Arguments**
@@ -1355,6 +1359,7 @@ class Conversation:
13551359 ` None `
13561360
13571361##### ` get_human_readable_context `
1362+
13581363- ** Usage**
13591364 生成分页后的人类可读对话上下文,方便展示或调试。
13601365- ** Arguments**
@@ -1391,15 +1396,13 @@ persona_mgr = self.context.persona_manager
13911396- ** Raises**
13921397 ` ValueError ` – 当不存在时抛出
13931398
1394-
13951399##### ` get_all_personas `
13961400
13971401- ** Usage**
13981402 一次性获取数据库中所有人格。
13991403- ** Returns**
14001404 ` list[Persona] ` – 人格列表,可能为空
14011405
1402-
14031406##### ` create_persona `
14041407
14051408- ** Usage**
@@ -1414,7 +1417,6 @@ persona_mgr = self.context.persona_manager
14141417- ** Raises**
14151418 ` ValueError ` – 若 ` persona_id ` 已存在
14161419
1417-
14181420##### ` update_persona `
14191421
14201422- ** Usage**
@@ -1429,7 +1431,6 @@ persona_mgr = self.context.persona_manager
14291431- ** Raises**
14301432 ` ValueError ` – 若 ` persona_id ` 不存在
14311433
1432-
14331434##### ` delete_persona `
14341435
14351436- ** Usage**
@@ -1439,7 +1440,6 @@ persona_mgr = self.context.persona_manager
14391440- ** Raises**
14401441 ` Valueable ` – 若 ` persona_id ` 不存在
14411442
1442-
14431443##### ` get_default_persona_v3 `
14441444
14451445- ** Usage**
@@ -1450,7 +1450,6 @@ persona_mgr = self.context.persona_manager
14501450- ** Returns**
14511451 ` Personality ` – v3 格式的默认人格对象
14521452
1453-
14541453::: details Persona / Personality 类型定义
14551454
14561455``` py
@@ -1501,7 +1500,6 @@ class Personality(TypedDict):
15011500
15021501:::
15031502
1504-
15051503### 其他
15061504
15071505#### 配置文件
@@ -1557,19 +1555,16 @@ async def helloworld(self, event: AstrMessageEvent):
15571555
15581556关于 CQHTTP API,请参考如下文档:
15591557
1560- Napcat API 文档:https://napcat.apifox.cn/
1561-
1562- Lagrange API 文档:https://lagrange-onebot.apifox.cn/
1563-
1558+ Napcat API 文档:< https://napcat.apifox.cn/ >
15641559
1560+ Lagrange API 文档:< https://lagrange-onebot.apifox.cn/ >
15651561
15661562#### 载入的所有插件
15671563
15681564``` py
15691565plugins = self .context.get_all_stars() # 返回 StarMetadata 包含了插件类实例、配置等等
15701566```
15711567
1572-
15731568#### 注册一个异步任务
15741569
15751570直接在 ** init** () 中使用 ` asyncio.create_task() ` 即可。
@@ -1588,7 +1583,6 @@ class TaskPlugin(Star):
15881583 print (" Hello" )
15891584```
15901585
1591-
15921586#### 获取加载的所有平台
15931587
15941588``` py
0 commit comments