Skip to content

Commit

Permalink
v0.3.3,动态版本号与版本号输出
Browse files Browse the repository at this point in the history
  • Loading branch information
Asankilp committed Oct 22, 2024
1 parent 2eaf719 commit eba300c
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 36 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ _✨ 使用 Azure OpenAI 推理服务的聊天机器人插件 ✨_
插件内置了猫娘小棉(Marsho)的人物设定,可以进行可爱的聊天!
*谁不喜欢回复消息快又可爱的猫娘呢?*
**※对 Azure AI Studio等的支持待定。对 OneBot 以外的适配器支持未经过完全验证。**

[Melobot 实现(施工中)](https://github.com/LiteyukiStudio/marshoai-melo)
## 🐱 设定
#### 基本信息

Expand Down
20 changes: 3 additions & 17 deletions nonebot_plugin_marshoai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,14 @@
from .azure import *
from nonebot import get_driver, logger
from .config import ConfigModel, config
from .constants import USAGE
import nonebot_plugin_localstore as store
usage = """MarshoAI Beta by Asankilp
用法:
marsho <聊天内容> : 与 Marsho 进行对话。当模型为 GPT-4o(-mini) 等时,可以带上图片进行对话。
nickname [昵称] : 为自己设定昵称,设置昵称后,Marsho 会根据你的昵称进行回答。使用'nickname reset'命令可清除自己设定的昵称。
reset : 重置当前会话的上下文。 ※需要加上命令前缀使用(默认为'/')。
超级用户命令(均需要加上命令前缀使用):
changemodel <模型名> : 切换全局 AI 模型。
contexts : 返回当前会话的上下文列表。 ※当上下文包含图片时,不要使用此命令。
praises : 返回夸赞名单的提示词。
usermsg <消息> : 往当前会话添加用户消息(UserMessage)。
assistantmsg <消息> : 往当前会话添加助手消息(AssistantMessage)。
savecontext <文件名> : 保存当前会话的上下文至插件数据目录下的contexts/<文件名>.json里。
loadcontext <文件名> : 从插件数据目录下的contexts/<文件名>.json里读取上下文并覆盖到当前会话。
※本AI的回答"按原样"提供,不提供任何担保。AI也会犯错,请仔细甄别回答的准确性。"""


__author__ = "Asankilp"
__plugin_meta__ = PluginMetadata(
name="Marsho AI插件",
description="接入Azure服务的AI聊天插件",
usage=usage,
usage=USAGE,
type="application",
config=ConfigModel,
homepage="https://github.com/LiteyukiStudio/nonebot-plugin-marshoai",
Expand All @@ -43,4 +29,4 @@ async def _():
logger.warning("token 未配置。可能无法进行聊天。")
else:
logger.info("token 已配置~!🐾")
pass
logger.info("マルショは、高性能ですから!")
8 changes: 0 additions & 8 deletions nonebot_plugin_marshoai/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,9 @@ async def marsho(
elif choice["finish_reason"] == CompletionsFinishReason.CONTENT_FILTERED:
await UniMessage("*已被内容过滤器过滤。请调整聊天内容后重试。").send(reply_to=True)
return
#await UniMessage(str(choice)).send()
await UniMessage(str(choice.message.content)).send(reply_to=True)
#requests_limit = response.headers.get('x-ratelimit-limit-requests')
#request_id = response.headers.get('x-request-id')
#remaining_requests = response.headers.get('x-ratelimit-remaining-requests')
#remaining_tokens = response.headers.get('x-ratelimit-remaining-tokens')
#await UniMessage(f""" 剩余token:{remaining_tokens}"""
# ).send()
except Exception as e:
await UniMessage(str(e)+suggest_solution(str(e))).send()
# await UniMessage(str(e.reason)).send()
traceback.print_exc()
return

Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_marshoai/azure_onebot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from nonebot import on_type, message
from nonebot import on_type
from nonebot.rule import to_me
from nonebot.adapters.onebot.v11 import PokeNotifyEvent
poke_notify = on_type(
Expand Down
19 changes: 18 additions & 1 deletion nonebot_plugin_marshoai/constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
__version__ = "0.3.3"
USAGE: str = f"""MarshoAI Beta v{__version__} by Asankilp
用法:
marsho <聊天内容> : 与 Marsho 进行对话。当模型为 GPT-4o(-mini) 等时,可以带上图片进行对话。
nickname [昵称] : 为自己设定昵称,设置昵称后,Marsho 会根据你的昵称进行回答。使用'nickname reset'命令可清除自己设定的昵称。
reset : 重置当前会话的上下文。 ※需要加上命令前缀使用(默认为'/')。
超级用户命令(均需要加上命令前缀使用):
changemodel <模型名> : 切换全局 AI 模型。
contexts : 返回当前会话的上下文列表。 ※当上下文包含图片时,不要使用此命令。
praises : 返回夸赞名单的提示词。
usermsg <消息> : 往当前会话添加用户消息(UserMessage)。
assistantmsg <消息> : 往当前会话添加助手消息(AssistantMessage)。
savecontext <文件名> : 保存当前会话的上下文至插件数据目录下的contexts/<文件名>.json里。
loadcontext <文件名> : 从插件数据目录下的contexts/<文件名>.json里读取上下文并覆盖到当前会话。
※本AI的回答"按原样"提供,不提供任何担保。AI也会犯错,请仔细甄别回答的准确性。"""

SUPPORT_IMAGE_MODELS: list = ["gpt-4o","gpt-4o-mini","llama-3.2-90b-vision-instruct","llama-3.2-11b-vision-instruct"]
REASONING_MODELS: list = ["o1-preview","o1-mini"]
INTRODUCTION: str = """你好喵~我是一只可爱的猫娘AI,名叫小棉~🐾!
我的代码在这里哦~↓↓↓
https://github.com/LiteyukiStudio/nonebot-plugin-marshoai
也可以关注一下还在成长中的 Melobot 酱喵~↓↓↓ https://github.com/Meloland/melobot """
也可以关注一下还在成长中的 Melobot 酱喵~↓↓↓
https://github.com/Meloland/melobot"""
7 changes: 3 additions & 4 deletions nonebot_plugin_marshoai/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import nonebot_plugin_localstore as store
from datetime import datetime
from zhDateTime import DateTime
from pathlib import Path
from azure.ai.inference.aio import ChatCompletionsClient
from azure.ai.inference.models import SystemMessage, UserMessage
from azure.ai.inference.models import SystemMessage
from .config import config
async def get_image_b64(url):
headers = {
Expand Down Expand Up @@ -80,10 +79,10 @@ async def set_nickname(user_id: str, name: str):
if not os.path.exists(filename):
data = {}
else:
with open(filename,'r') as f:
with open(filename,'r', encoding='utf-8') as f:
data = json.load(f)
data[user_id] = name
with open(filename, 'w') as f:
with open(filename, 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=4)

async def get_nicknames():
Expand Down
6 changes: 2 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "nonebot-plugin-marshoai"
version = "0.3.2"
dynamic = ["version"]
description = "Nonebot2插件,调用Azure OpenAI服务实现猫娘聊天"
readme = "README.md"
requires-python = "<4.0,>=3.9"
Expand All @@ -22,15 +22,13 @@ Homepage = "https://github.com/LiteyukiStudio/nonebot-plugin-marshoai"

[tool.nonebot]
plugins = ["nonebot_plugin_marshoai"]
adapters = [{name = "OneBot V11", module_name = "nonebot.adapters.onebot.v11"}]


[tool.pdm]
distribution = true

[tool.pdm.version]
source = "file"
path = "nonebot_plugin_marshoai/__init__.py"
path = "nonebot_plugin_marshoai/constants.py"

[tool.pdm.build]
includes = []
Expand Down

0 comments on commit eba300c

Please sign in to comment.