|
|
|
@@ -15,10 +15,11 @@ from azure.ai.inference.models import (
|
|
|
|
ChatCompletionsToolCall,
|
|
|
|
ChatCompletionsToolCall,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
from azure.core.credentials import AzureKeyCredential
|
|
|
|
from azure.core.credentials import AzureKeyCredential
|
|
|
|
from nonebot import on_command, logger
|
|
|
|
from nonebot import on_command, on_message, logger
|
|
|
|
from nonebot.adapters import Message, Event
|
|
|
|
from nonebot.adapters import Message, Event
|
|
|
|
from nonebot.params import CommandArg
|
|
|
|
from nonebot.params import CommandArg
|
|
|
|
from nonebot.permission import SUPERUSER
|
|
|
|
from nonebot.permission import SUPERUSER
|
|
|
|
|
|
|
|
from nonebot.rule import Rule, to_me
|
|
|
|
from nonebot_plugin_alconna import on_alconna, MsgTarget
|
|
|
|
from nonebot_plugin_alconna import on_alconna, MsgTarget
|
|
|
|
from nonebot_plugin_alconna.uniseg import UniMessage, UniMsg
|
|
|
|
from nonebot_plugin_alconna.uniseg import UniMessage, UniMsg
|
|
|
|
import nonebot_plugin_localstore as store
|
|
|
|
import nonebot_plugin_localstore as store
|
|
|
|
@@ -29,32 +30,43 @@ from .metadata import metadata
|
|
|
|
from .models import MarshoContext, MarshoTools
|
|
|
|
from .models import MarshoContext, MarshoTools
|
|
|
|
from .util import *
|
|
|
|
from .util import *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def at_enable():
|
|
|
|
|
|
|
|
return config.marshoai_at
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
driver = get_driver()
|
|
|
|
driver = get_driver()
|
|
|
|
|
|
|
|
|
|
|
|
changemodel_cmd = on_command("changemodel", permission=SUPERUSER)
|
|
|
|
changemodel_cmd = on_command("changemodel", permission=SUPERUSER, priority=10, block=True)
|
|
|
|
resetmem_cmd = on_command("reset")
|
|
|
|
resetmem_cmd = on_command("reset", priority=10, block=True)
|
|
|
|
# setprompt_cmd = on_command("prompt",permission=SUPERUSER)
|
|
|
|
# setprompt_cmd = on_command("prompt",permission=SUPERUSER)
|
|
|
|
praises_cmd = on_command("praises", permission=SUPERUSER)
|
|
|
|
praises_cmd = on_command("praises", permission=SUPERUSER, priority=10, block=True)
|
|
|
|
add_usermsg_cmd = on_command("usermsg", permission=SUPERUSER)
|
|
|
|
add_usermsg_cmd = on_command("usermsg", permission=SUPERUSER, priority=10, block=True)
|
|
|
|
add_assistantmsg_cmd = on_command("assistantmsg", permission=SUPERUSER)
|
|
|
|
add_assistantmsg_cmd = on_command("assistantmsg", permission=SUPERUSER, priority=10, block=True)
|
|
|
|
contexts_cmd = on_command("contexts", permission=SUPERUSER)
|
|
|
|
contexts_cmd = on_command("contexts", permission=SUPERUSER, priority=10, block=True)
|
|
|
|
save_context_cmd = on_command("savecontext", permission=SUPERUSER)
|
|
|
|
save_context_cmd = on_command("savecontext", permission=SUPERUSER, priority=10, block=True)
|
|
|
|
load_context_cmd = on_command("loadcontext", permission=SUPERUSER)
|
|
|
|
load_context_cmd = on_command("loadcontext", permission=SUPERUSER, priority=10, block=True)
|
|
|
|
marsho_cmd = on_alconna(
|
|
|
|
marsho_cmd = on_alconna(
|
|
|
|
Alconna(
|
|
|
|
Alconna(
|
|
|
|
config.marshoai_default_name,
|
|
|
|
config.marshoai_default_name,
|
|
|
|
Args["text?", AllParam],
|
|
|
|
Args["text?", AllParam],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
aliases=config.marshoai_aliases,
|
|
|
|
aliases=config.marshoai_aliases,
|
|
|
|
|
|
|
|
priority=10,
|
|
|
|
|
|
|
|
block=True
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
marsho_at = on_message(rule=to_me()&at_enable, priority=11)
|
|
|
|
nickname_cmd = on_alconna(
|
|
|
|
nickname_cmd = on_alconna(
|
|
|
|
Alconna(
|
|
|
|
Alconna(
|
|
|
|
"nickname",
|
|
|
|
"nickname",
|
|
|
|
Args["name?", str],
|
|
|
|
Args["name?", str],
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
priority = 10,
|
|
|
|
|
|
|
|
block = True
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
refresh_data_cmd = on_command("refresh_data", permission=SUPERUSER, priority=10, block=True)
|
|
|
|
refresh_data_cmd = on_command("refresh_data", permission=SUPERUSER)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
command_start = driver.config.command_start
|
|
|
|
model_name = config.marshoai_default_model
|
|
|
|
model_name = config.marshoai_default_model
|
|
|
|
context = MarshoContext()
|
|
|
|
context = MarshoContext()
|
|
|
|
tools = MarshoTools()
|
|
|
|
tools = MarshoTools()
|
|
|
|
@@ -63,6 +75,7 @@ endpoint = config.marshoai_azure_endpoint
|
|
|
|
client = ChatCompletionsClient(endpoint=endpoint, credential=AzureKeyCredential(token))
|
|
|
|
client = ChatCompletionsClient(endpoint=endpoint, credential=AzureKeyCredential(token))
|
|
|
|
target_list = [] # 记录需保存历史上下文的列表
|
|
|
|
target_list = [] # 记录需保存历史上下文的列表
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@driver.on_startup
|
|
|
|
@driver.on_startup
|
|
|
|
async def _preload_tools():
|
|
|
|
async def _preload_tools():
|
|
|
|
tools_dir = store.get_plugin_data_dir() / "tools"
|
|
|
|
tools_dir = store.get_plugin_data_dir() / "tools"
|
|
|
|
@@ -71,6 +84,7 @@ async def _preload_tools():
|
|
|
|
tools.load_tools(Path(__file__).parent / "tools")
|
|
|
|
tools.load_tools(Path(__file__).parent / "tools")
|
|
|
|
tools.load_tools(store.get_plugin_data_dir() / "tools")
|
|
|
|
tools.load_tools(store.get_plugin_data_dir() / "tools")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@add_usermsg_cmd.handle()
|
|
|
|
@add_usermsg_cmd.handle()
|
|
|
|
async def add_usermsg(target: MsgTarget, arg: Message = CommandArg()):
|
|
|
|
async def add_usermsg(target: MsgTarget, arg: Message = CommandArg()):
|
|
|
|
if msg := arg.extract_plain_text():
|
|
|
|
if msg := arg.extract_plain_text():
|
|
|
|
@@ -160,9 +174,12 @@ async def refresh_data():
|
|
|
|
await refresh_data_cmd.finish("已刷新数据")
|
|
|
|
await refresh_data_cmd.finish("已刷新数据")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@marsho_at.handle()
|
|
|
|
@marsho_cmd.handle()
|
|
|
|
@marsho_cmd.handle()
|
|
|
|
async def marsho(target: MsgTarget, event: Event, text: Optional[UniMsg] = None):
|
|
|
|
async def marsho(target: MsgTarget, event: Event, text: Optional[UniMsg] = None):
|
|
|
|
global target_list
|
|
|
|
global target_list
|
|
|
|
|
|
|
|
if event.get_message().extract_plain_text() and (not text and event.get_message().extract_plain_text() != config.marshoai_default_name):
|
|
|
|
|
|
|
|
text = event.get_message()
|
|
|
|
if not text:
|
|
|
|
if not text:
|
|
|
|
# 发送说明
|
|
|
|
# 发送说明
|
|
|
|
await UniMessage(metadata.usage + "\n当前使用的模型:" + model_name).send()
|
|
|
|
await UniMessage(metadata.usage + "\n当前使用的模型:" + model_name).send()
|
|
|
|
|