2525 CommandMeta ,
2626 Match ,
2727 MsgTarget ,
28+ Subcommand ,
2829 UniMessage ,
2930 get_message_id ,
3031 on_alconna ,
@@ -206,6 +207,22 @@ async def bot_connected():
206207 permission = SUPERUSER ,
207208)
208209
210+ command_model = on_alconna (
211+ Alconna (
212+ COMMAND_PREFIXES ,
213+ "model" ,
214+ Subcommand ("help" , help_text = "显示指令帮助" ),
215+ Subcommand ("load" , Args ["config_name?" , str ], help_text = "切换指定模型配置,用法: .model load <config_name> " ),
216+ Subcommand ("reload" , help_text = "重新加载模型配置文件" ),
217+ Subcommand ("list" , help_text = "列出所有可用模型配置" ),
218+ meta = CommandMeta ("Muicebot 模型配置管理指令" ),
219+ ),
220+ priority = 10 ,
221+ block = True ,
222+ skip_for_unmatch = False ,
223+ permission = SUPERUSER ,
224+ )
225+
209226
210227nickname_event = on_alconna (
211228 Alconna (re .compile (combined_regex ), Args ["text?" , AllParam ], separators = "" ),
@@ -345,23 +362,6 @@ async def handle_command_undo(event: Event, session: async_scoped_session):
345362 await command_undo .finish (response )
346363
347364
348- @command_load .handle ()
349- async def handle_command_load (config : Match [str ] = AlconnaMatch ("config_name" )):
350- muice = Muice .get_instance ()
351- config_name = config .result
352-
353- try :
354- muice .change_model_config (reload = True )
355- except (ValueError , FileNotFoundError ) as e :
356- await UniMessage (str (e )).finish ()
357-
358- await UniMessage (
359- f"已成功加载 { config_name } "
360- if config_name
361- else f"未指定模型配置名,已加载默认模型配置: { muice .model_config_name } "
362- ).finish ()
363-
364-
365365@command_whoami .handle ()
366366async def handle_command_whoami (bot : Bot , event : Event ):
367367 user_id = event .get_user_id ()
@@ -383,8 +383,21 @@ async def handle_command_profile(
383383 await UniMessage ("成功切换消息存档~" ).finish ()
384384
385385
386+ @command_model .assign ("help" )
387+ async def handle_model_help ():
388+ await UniMessage (
389+ """Model 命令指南:
390+ - help: 显示此帮助信息
391+ - load <config_name>: 加载模型配置
392+ - reload: 重新加载模型配置文件
393+ - list: 列出所有可用的模型配置
394+ """
395+ ).finish ()
396+
397+
386398@command_reload .handle ()
387- async def handle_command_reload ():
399+ @command_model .assign ("reload" )
400+ async def handle_model_reload ():
388401 logger .info ("重新加载模型配置文件..." )
389402 muice = Muice .get_instance ()
390403
@@ -396,6 +409,38 @@ async def handle_command_reload():
396409 await UniMessage (f"已成功重载模型配置文件: { muice .model_config_name } " ).finish ()
397410
398411
412+ @command_load .handle ()
413+ @command_model .assign ("load" )
414+ async def handle_model_load (config : Match [str ] = AlconnaMatch ("config_name" )):
415+ muice = Muice .get_instance ()
416+ config_name = config .result if config .available else None
417+
418+ try :
419+ muice .change_model_config (config_name )
420+ except (ValueError , FileNotFoundError ) as e :
421+ await UniMessage (str (e )).finish ()
422+
423+ await UniMessage (
424+ f"已成功加载 { config_name } "
425+ if config_name
426+ else f"未指定模型配置名,已加载默认模型配置: { muice .model_config_name } "
427+ ).finish ()
428+
429+
430+ @command_model .assign ("list" )
431+ async def handle_model_list ():
432+ from .config import ModelConfigManager
433+
434+ config_manager = ModelConfigManager ()
435+ configs = config_manager .configs
436+ outputs = ["目前所有可用的模型配置列表:" ]
437+
438+ for name , config in configs .items ():
439+ outputs .append (f"-{ name } { config .model_name } ({ config .provider } ) 多模态: { '是' if config .multimodal else '否' } " )
440+
441+ await UniMessage ("\n " .join (outputs )).finish ()
442+
443+
399444@command_start .handle ()
400445async def handle_command_start ():
401446 pass
0 commit comments