66"""
77
88import json
9+ from typing import Any
910from astrbot .core import sp
1011
1112from collections .abc import Callable , Awaitable
1617class ConversationManager :
1718 """负责管理会话与 LLM 的对话,某个会话当前正在用哪个对话。"""
1819
19- def __init__ (self , db_helper : BaseDatabase ):
20+ def __init__ (self , db_helper : BaseDatabase ) -> None :
2021 self .session_conversations : dict [str , str ] = {}
2122 self .db = db_helper
2223 self .save_interval = 60 # 每 60 秒保存一次
@@ -101,7 +102,9 @@ async def new_conversation(
101102 await sp .session_put (unified_msg_origin , "sel_conv_id" , conv .conversation_id )
102103 return conv .conversation_id
103104
104- async def switch_conversation (self , unified_msg_origin : str , conversation_id : str ):
105+ async def switch_conversation (
106+ self , unified_msg_origin : str , conversation_id : str
107+ ) -> None :
105108 """切换会话的对话
106109
107110 Args:
@@ -113,7 +116,7 @@ async def switch_conversation(self, unified_msg_origin: str, conversation_id: st
113116
114117 async def delete_conversation (
115118 self , unified_msg_origin : str , conversation_id : str | None = None
116- ):
119+ ) -> None :
117120 """删除会话的对话,当 conversation_id 为 None 时删除会话当前的对话
118121
119122 Args:
@@ -129,7 +132,7 @@ async def delete_conversation(
129132 self .session_conversations .pop (unified_msg_origin , None )
130133 await sp .session_remove (unified_msg_origin , "sel_conv_id" )
131134
132- async def delete_conversations_by_user_id (self , unified_msg_origin : str ):
135+ async def delete_conversations_by_user_id (self , unified_msg_origin : str ) -> None :
133136 """删除会话的所有对话
134137
135138 Args:
@@ -207,7 +210,7 @@ async def get_filtered_conversations(
207210 page_size : int = 20 ,
208211 platform_ids : list [str ] | None = None ,
209212 search_query : str = "" ,
210- ** kwargs ,
213+ ** kwargs : Any , # noqa: ANN401
211214 ) -> tuple [list [Conversation ], int ]:
212215 """获取过滤后的对话列表
213216
@@ -239,7 +242,7 @@ async def update_conversation(
239242 history : list [dict ] | None = None ,
240243 title : str | None = None ,
241244 persona_id : str | None = None ,
242- ):
245+ ) -> None :
243246 """更新会话的对话
244247
245248 Args:
@@ -260,7 +263,7 @@ async def update_conversation(
260263
261264 async def update_conversation_title (
262265 self , unified_msg_origin : str , title : str , conversation_id : str | None = None
263- ):
266+ ) -> None :
264267 """更新会话的对话标题
265268
266269 Args:
@@ -281,7 +284,7 @@ async def update_conversation_persona_id(
281284 unified_msg_origin : str ,
282285 persona_id : str ,
283286 conversation_id : str | None = None ,
284- ):
287+ ) -> None :
285288 """更新会话的对话 Persona ID
286289
287290 Args:
@@ -298,8 +301,12 @@ async def update_conversation_persona_id(
298301 )
299302
300303 async def get_human_readable_context (
301- self , unified_msg_origin , conversation_id , page = 1 , page_size = 10
302- ):
304+ self ,
305+ unified_msg_origin : str ,
306+ conversation_id : str ,
307+ page : int = 1 ,
308+ page_size : int = 10 ,
309+ ) -> tuple [list [str ], int ]:
303310 """获取人类可读的上下文
304311
305312 Args:
0 commit comments