From 85cf197f27eb6580b5d301c323cb587d35c25912 Mon Sep 17 00:00:00 2001 From: Asankilp Date: Wed, 6 Nov 2024 01:10:34 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=E4=BF=AE=E5=A4=8D=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E5=85=BC=E5=AE=B9=E9=97=AE=E9=A2=98=EF=BC=8C=E5=85=BC?= =?UTF-8?q?=E5=AE=B9o1=E6=A8=A1=E5=9E=8B=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- nonebot_plugin_marshoai/azure.py | 29 ++++++++++++++++++---------- nonebot_plugin_marshoai/config.py | 1 + nonebot_plugin_marshoai/constants.py | 4 ++-- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index eb8d3cd7..8635f6fd 100644 --- a/README.md +++ b/README.md @@ -125,9 +125,10 @@ _✨ 使用 Azure OpenAI 推理服务的聊天机器人插件 ✨_ | MARSHOAI_DEFAULT_NAME | 否 | `marsho` | 调用 marsho 默认的命令前缀 | | MARSHOAI_ALIASES | 否 | `set{"小绵"}` | 调用 marsho 的命令别名 | | MARSHOAI_DEFAULT_MODEL | 否 | `gpt-4o-mini` | Marsho 默认调用的模型 | -| MARSHOAI_PROMPT | 否 | 猫娘 Marsho 人设提示词 | Marsho 的基本系统提示词 | +| MARSHOAI_PROMPT | 否 | 猫娘 Marsho 人设提示词 | Marsho 的基本系统提示词 **推理模型(o1等)不支持系统提示词。** | | MARSHOAI_ADDITIONAL_PROMPT | 否 | 无 | Marsho 的扩展系统提示词 | | MARSHOAI_POKE_SUFFIX | 否 | `揉了揉你的猫耳` | 对 Marsho 所连接的 OneBot 用户进行双击戳一戳时,构建的聊天内容。此配置项为空字符串时,戳一戳响应功能会被禁用。例如,默认值构建的聊天内容将为`*[昵称]揉了揉你的猫耳`。 | +| MARSHOAI_ENABLE_SUPPORT_IMAGE_TIP | 否 | `true` | 启用后用户发送带图请求时若模型不支持图片,则提示用户 | | MARSHOAI_ENABLE_NICKNAME_TIP | 否 | `true` | 启用后用户未设置昵称时提示用户设置 | | MARSHOAI_ENABLE_PRAISES | 否 | `true` | 是否启用夸赞名单功能 | | MARSHOAI_ENABLE_TIME_PROMPT | 否 | `true` | 是否启用实时更新的日期与时间(精确到秒)与农历日期系统提示词 | diff --git a/nonebot_plugin_marshoai/azure.py b/nonebot_plugin_marshoai/azure.py index 92bc7118..4ac4f1df 100644 --- a/nonebot_plugin_marshoai/azure.py +++ b/nonebot_plugin_marshoai/azure.py @@ -46,7 +46,7 @@ nickname_cmd = on_alconna( Alconna( "nickname", Args["name?", str], - ) + ) ) model_name = config.marshoai_default_model context = MarshoContext() @@ -147,21 +147,30 @@ async def marsho(target: MsgTarget, event: Event, text: Optional[UniMsg] = None) "*你未设置自己的昵称。推荐使用'nickname [昵称]'命令设置昵称来获得个性化(可能)回答。" ).send() - usermsg: list[ContentItem] = [] + is_support_image_model = model_name.lower() in SUPPORT_IMAGE_MODELS + is_reasoning_model = model_name.lower() in REASONING_MODELS + usermsg = [] if is_support_image_model else "" for i in text: if i.type == "text": - usermsg += [TextContentItem(text=i.data["text"] + nickname_prompt)] - elif i.type == "image" and model_name.lower() in SUPPORT_IMAGE_MODELS: - usermsg.append( - ImageContentItem( - image_url=ImageUrl(url=str(await get_image_b64(i.data["url"]))) + if is_support_image_model: + usermsg += [TextContentItem(text=i.data["text"] + nickname_prompt)] + else: + usermsg += str(i.data["text"] + nickname_prompt) + elif i.type == "image": + if is_support_image_model: + usermsg.append( + ImageContentItem( + image_url=ImageUrl(url=str(await get_image_b64(i.data["url"]))) + ) ) - ) - + elif config.marshoai_enable_support_image_tip: + await UniMessage("*此模型不支持图片处理。").send() + context_msg = context.build(target.id, target.private) + if is_reasoning_model: context_msg = context_msg[1:] #o1等推理模型不支持系统提示词,故截断 response = await make_chat( client=client, model_name=model_name, - msg=context.build(target.id, target.private) + msg=context_msg + [UserMessage(content=usermsg)], ) # await UniMessage(str(response)).send() diff --git a/nonebot_plugin_marshoai/config.py b/nonebot_plugin_marshoai/config.py index ecd57f4b..49a2a200 100644 --- a/nonebot_plugin_marshoai/config.py +++ b/nonebot_plugin_marshoai/config.py @@ -16,6 +16,7 @@ class ConfigModel(BaseModel): marshoai_additional_prompt: str = "" marshoai_poke_suffix: str = "揉了揉你的猫耳" marshoai_enable_nickname_tip: bool = True + marshoai_enable_support_image_tip: bool = True marshoai_enable_praises: bool = True marshoai_enable_time_prompt: bool = True marshoai_azure_endpoint: str = "https://models.inference.ai.azure.com" diff --git a/nonebot_plugin_marshoai/constants.py b/nonebot_plugin_marshoai/constants.py index 3fe7b1dd..9658de51 100644 --- a/nonebot_plugin_marshoai/constants.py +++ b/nonebot_plugin_marshoai/constants.py @@ -1,5 +1,5 @@ -__version__ = "0.3.4.1" -USAGE: str = f"""MarshoAI-NoneBot Beta v{__version__} by Asankilp + +USAGE: str = f"""MarshoAI-NoneBot Beta by Asankilp 用法: marsho <聊天内容> : 与 Marsho 进行对话。当模型为 GPT-4o(-mini) 等时,可以带上图片进行对话。 nickname [昵称] : 为自己设定昵称,设置昵称后,Marsho 会根据你的昵称进行回答。使用'nickname reset'命令可清除自己设定的昵称。