💾v0.1.4,将夸赞名单改为存储至单独的数据目录而非工作目录

This commit is contained in:
Asankilp 2024-10-03 11:58:33 +08:00
parent e096655fc5
commit aa605afc9e
4 changed files with 32 additions and 25 deletions

View File

@ -93,7 +93,7 @@ _✨ 使用 Azure OpenAI 推理服务的聊天机器人插件 ✨_
发送`marsho`指令可以获取使用说明 发送`marsho`指令可以获取使用说明
## 👍 夸赞名单 ## 👍 夸赞名单
夸赞名单存储于 Bot 工作目录的`praises.json`下,当配置项为`true`时发起一次聊天后自动生成,包含人物名字与人物优点两个基本数据。 夸赞名单存储于插件数据目录下的`praises.json`里(该目录路径会在 Bot 启动时输出到日志),当配置项为`true`时发起一次聊天后自动生成,包含人物名字与人物优点两个基本数据。
存储于其中的人物会被 Marsho “认识”和“喜欢”。 存储于其中的人物会被 Marsho “认识”和“喜欢”。
其结构类似于: 其结构类似于:
```json ```json

View File

@ -1,8 +1,10 @@
from nonebot.plugin import PluginMetadata, inherit_supported_adapters, require from nonebot.plugin import PluginMetadata, inherit_supported_adapters, require
require("nonebot_plugin_alconna") require("nonebot_plugin_alconna")
require("nonebot_plugin_localstore")
from .azure import * from .azure import *
from nonebot import get_driver from nonebot import get_driver, logger
from .config import ConfigModel from .config import ConfigModel, config
import nonebot_plugin_localstore as store
usage = """MarshoAI Alpha by Asankilp usage = """MarshoAI Alpha by Asankilp
用法 用法
marsho <聊天内容> : Marsho 进行对话当模型为 GPT-4o(-mini) 等时可以带上图片进行对话 marsho <聊天内容> : Marsho 进行对话当模型为 GPT-4o(-mini) 等时可以带上图片进行对话
@ -33,5 +35,10 @@ driver = get_driver()
@driver.on_startup @driver.on_startup
async def _(): async def _():
pass logger.info("MarshoAI 已经加载~🐾")
logger.info(f"Marsho 的插件数据存储于 : {str(store.get_plugin_data_dir())} 哦~🐾")
if config.marshoai_token == "":
logger.warning("token 未配置。可能无法进行聊天。")
else:
logger.info("token 已配置~!🐾")

View File

@ -3,6 +3,7 @@ import mimetypes
import os import os
import json import json
import httpx import httpx
import nonebot_plugin_localstore as store
from datetime import datetime from datetime import datetime
from zhDateTime import DateTime from zhDateTime import DateTime
from azure.ai.inference.models import SystemMessage from azure.ai.inference.models import SystemMessage
@ -28,16 +29,16 @@ async def get_image_b64(url):
return None return None
def get_praises(): def get_praises():
filename = "praises.json" praises_file = store.get_plugin_data_file("praises.json") # 夸赞名单文件使用localstore存储
if not os.path.exists("praises.json"): if not os.path.exists(praises_file):
init_data = { init_data = {
"like": [ "like": [
{"name":"Asankilp","advantages":"赋予了Marsho猫娘人格使用vim与vscode为Marsho写了许多代码使Marsho更加可爱"} {"name":"Asankilp","advantages":"赋予了Marsho猫娘人格使用vim与vscode为Marsho写了许多代码使Marsho更加可爱"}
] ]
} }
with open(filename,"w",encoding="utf-8") as f: with open(praises_file,"w",encoding="utf-8") as f:
json.dump(init_data,f,ensure_ascii=False,indent=4) json.dump(init_data,f,ensure_ascii=False,indent=4)
with open(filename,"r",encoding="utf-8") as f: with open(praises_file,"r",encoding="utf-8") as f:
data = json.load(f) data = json.load(f)
return data return data
@ -63,19 +64,17 @@ def get_prompt():
spell = SystemMessage(content=marsho_prompt+prompts) spell = SystemMessage(content=marsho_prompt+prompts)
return spell return spell
def suggest_solution(errinfo: str): def suggest_solution(errinfo: str) -> str:
suggestion = "" suggestions = {
if "content_filter" in errinfo: "content_filter": "消息已被内容过滤器过滤。请调整聊天内容后重试。",
suggestion = "消息已被内容过滤器过滤。请调整聊天内容后重试。" "RateLimitReached": "模型达到调用速率限制。请稍等一段时间或联系Bot管理员。",
elif "RateLimitReached" in errinfo: "tokens_limit_reached": "请求token达到上限。请重置上下文。",
suggestion = "模型达到调用速率限制。请稍等一段时间或联系Bot管理员。" "content_length_limit": "请求体过大。请重置上下文。",
elif "tokens_limit_reached" in errinfo: "unauthorized": "Azure凭据无效。请联系Bot管理员。"
suggestion = "请求token达到上限。请重置上下文。" }
elif "content_length_limit" in errinfo:
suggestion = "请求体过大。请重置上下文。" for key, suggestion in suggestions.items():
elif "unauthorized" in errinfo: if key in errinfo:
suggestion = "Azure凭据无效。请联系Bot管理员。" return f"\n{suggestion}"
if suggestion != "":
return "\n"+suggestion return ""
else:
return suggestion

View File

@ -1,6 +1,6 @@
[project] [project]
name = "nonebot-plugin-marshoai" name = "nonebot-plugin-marshoai"
version = "0.1.3" version = "0.1.4"
description = "Nonebot2插件调用Azure OpenAI服务实现猫娘聊天" description = "Nonebot2插件调用Azure OpenAI服务实现猫娘聊天"
readme = "README.md" readme = "README.md"
requires-python = "<4.0,>=3.9" requires-python = "<4.0,>=3.9"
@ -8,6 +8,7 @@ authors = [{ name = "Asankilp", email = "asankilp@outlook.com" }]
dependencies = [ dependencies = [
"nonebot2>=2.2.0", "nonebot2>=2.2.0",
"nonebot-plugin-alconna>=0.48.0", "nonebot-plugin-alconna>=0.48.0",
"nonebot-plugin-localstore>=0.7.1",
"azure-ai-inference>=1.0.0b4", "azure-ai-inference>=1.0.0b4",
"zhDatetime>=1.1.1", "zhDatetime>=1.1.1",
"aiohttp>=3.9", "aiohttp>=3.9",