🐱v0.3.4,优化marsho命令参数的获取,自我介绍文本更新

This commit is contained in:
Asankilp 2024-10-23 18:41:40 +08:00
parent eba300cdd1
commit 1eb1ad3c8e
4 changed files with 17 additions and 21 deletions

View File

@ -136,4 +136,4 @@ _✨ 使用 Azure OpenAI 推理服务的聊天机器人插件 ✨_
## 🕊️ TODO ## 🕊️ TODO
- [x] 对聊天发起者的认知(认出是谁在问 Marsho初步实现 - [x] 对聊天发起者的认知(认出是谁在问 Marsho初步实现
- [ ] 上下文通过数据库持久化存储 - [ ] 上下文通过数据库持久化存储
- [ ] [Melobot](https://github.com/Meloland/melobot) 实现 - [ ] [Melobot](https://github.com/Meloland/melobot) 实现(施工中)

View File

@ -11,6 +11,7 @@ import contextlib
from azure.ai.inference.aio import ChatCompletionsClient from azure.ai.inference.aio import ChatCompletionsClient
from azure.ai.inference.models import UserMessage, AssistantMessage, TextContentItem, ImageContentItem, ImageUrl, CompletionsFinishReason from azure.ai.inference.models import UserMessage, AssistantMessage, TextContentItem, ImageContentItem, ImageUrl, CompletionsFinishReason
from azure.core.credentials import AzureKeyCredential from azure.core.credentials import AzureKeyCredential
from typing import Optional
from .__init__ import __plugin_meta__ from .__init__ import __plugin_meta__
from .config import config from .config import config
from .models import MarshoContext from .models import MarshoContext
@ -109,15 +110,14 @@ async def nickname(
async def marsho( async def marsho(
target: MsgTarget, target: MsgTarget,
event: Event, event: Event,
message: UniMsg, text: Optional[UniMsg] = None
text = None
): ):
if not text: if not text:
await UniMessage( await UniMessage(
__plugin_meta__.usage+"\n当前使用的模型:"+model_name).send() __plugin_meta__.usage+"\n当前使用的模型:"+model_name).send()
await marsho_cmd.finish(INTRODUCTION) await marsho_cmd.finish(INTRODUCTION)
return return
# await UniMessage(str(text)).send()
try: try:
is_support_image_model = model_name.lower() in SUPPORT_IMAGE_MODELS is_support_image_model = model_name.lower() in SUPPORT_IMAGE_MODELS
usermsg = [] if is_support_image_model else "" usermsg = [] if is_support_image_model else ""
@ -129,8 +129,7 @@ async def marsho(
else: else:
nickname_prompt = "" nickname_prompt = ""
await UniMessage("*你未设置自己的昵称。推荐使用'nickname [昵称]'命令设置昵称来获得个性化(可能)回答。").send() await UniMessage("*你未设置自己的昵称。推荐使用'nickname [昵称]'命令设置昵称来获得个性化(可能)回答。").send()
marsho_string_removed = False for i in text:
for i in message:
if i.type == "image": if i.type == "image":
if is_support_image_model: if is_support_image_model:
imgurl = i.data["url"] imgurl = i.data["url"]
@ -141,12 +140,7 @@ async def marsho(
else: else:
await UniMessage("*此模型不支持图片处理。").send() await UniMessage("*此模型不支持图片处理。").send()
elif i.type == "text": elif i.type == "text":
if not marsho_string_removed: clean_text = i.data["text"]
# 去掉最前面的"marsho "字符串
clean_text = i.data["text"].lstrip("marsho ")
marsho_string_removed = True # 标记文本已处理
else:
clean_text = i.data["text"]
if is_support_image_model: if is_support_image_model:
usermsg.append(TextContentItem(text=clean_text+nickname_prompt)) usermsg.append(TextContentItem(text=clean_text+nickname_prompt))
else: else:

View File

@ -1,4 +1,4 @@
__version__ = "0.3.3" __version__ = "0.3.4"
USAGE: str = f"""MarshoAI Beta v{__version__} by Asankilp USAGE: str = f"""MarshoAI Beta v{__version__} by Asankilp
用法 用法
marsho <聊天内容> : Marsho 进行对话当模型为 GPT-4o(-mini) 等时可以带上图片进行对话 marsho <聊天内容> : Marsho 进行对话当模型为 GPT-4o(-mini) 等时可以带上图片进行对话
@ -21,4 +21,6 @@ INTRODUCTION: str = """你好喵~我是一只可爱的猫娘AI名叫小棉~
https://github.com/LiteyukiStudio/nonebot-plugin-marshoai https://github.com/LiteyukiStudio/nonebot-plugin-marshoai
也可以关注一下还在成长中的 Melobot 酱喵~ 也可以关注一下还在成长中的 Melobot 酱喵~
https://github.com/Meloland/melobot""" https://github.com/Meloland/melobot
我与 Melobot 酱贴贴的代码在这里喵~
https://github.com/LiteyukiStudio/marshoai-melo"""

View File

@ -30,13 +30,13 @@ async def get_image_b64(url):
return None return None
async def make_chat(client: ChatCompletionsClient, msg, model_name: str): async def make_chat(client: ChatCompletionsClient, msg, model_name: str):
return await client.complete( return await client.complete(
messages=msg, messages=msg,
model=model_name, model=model_name,
temperature=config.marshoai_temperature, temperature=config.marshoai_temperature,
max_tokens=config.marshoai_max_tokens, max_tokens=config.marshoai_max_tokens,
top_p=config.marshoai_top_p top_p=config.marshoai_top_p
) )
def get_praises(): def get_praises():
praises_file = store.get_plugin_data_file("praises.json") # 夸赞名单文件使用localstore存储 praises_file = store.get_plugin_data_file("praises.json") # 夸赞名单文件使用localstore存储
if not os.path.exists(praises_file): if not os.path.exists(praises_file):