From b28e6921c59b7e7d064c43943b25ebf8663e1dbd Mon Sep 17 00:00:00 2001 From: Asankilp Date: Thu, 30 Jan 2025 15:24:49 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E4=BC=98=E5=8C=96OpenAI=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E5=8F=82=E6=95=B0=EF=BC=8C=E9=BB=98=E8=AE=A4=E4=BC=A0?= =?UTF-8?q?=E5=85=A5NotGiven?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_plugin_marshoai/marsho.py | 6 +++++- nonebot_plugin_marshoai/util.py | 14 ++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/nonebot_plugin_marshoai/marsho.py b/nonebot_plugin_marshoai/marsho.py index b127aec..d12e0cf 100644 --- a/nonebot_plugin_marshoai/marsho.py +++ b/nonebot_plugin_marshoai/marsho.py @@ -449,7 +449,11 @@ with contextlib.suppress(ImportError): # 优化先不做() client=client, model_name=model_name, msg=[ - get_prompt(), + ( + get_prompt() + if model_name.lower() not in NO_SYSPROMPT_MODELS + else None + ), UserMessage( content=f"*{user_nickname}{config.marshoai_poke_suffix}" ), diff --git a/nonebot_plugin_marshoai/util.py b/nonebot_plugin_marshoai/util.py index a4a04d4..904c9ee 100755 --- a/nonebot_plugin_marshoai/util.py +++ b/nonebot_plugin_marshoai/util.py @@ -14,7 +14,7 @@ from nonebot.log import logger from nonebot_plugin_alconna import Image as ImageMsg from nonebot_plugin_alconna import Text as TextMsg from nonebot_plugin_alconna import UniMessage -from openai import AsyncOpenAI +from openai import AsyncOpenAI, NotGiven from zhDateTime import DateTime from .config import config @@ -25,6 +25,8 @@ nickname_json = None # 记录昵称 praises_json = None # 记录夸赞名单 loaded_target_list = [] # 记录已恢复备份的上下文的列表 +NOT_GIVEN = NotGiven() + # 时间参数相关 if config.marshoai_enable_time_prompt: _weekdays = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"] @@ -141,13 +143,13 @@ async def make_chat_openai( model_name: 指定AI模型名 tools: 工具列表 """ - return await client.chat.completions.create( + return await client.chat.completions.create( # type: ignore messages=msg, model=model_name, - tools=tools, - temperature=config.marshoai_temperature, - max_tokens=config.marshoai_max_tokens, - top_p=config.marshoai_top_p, + tools=tools or NOT_GIVEN, + temperature=config.marshoai_temperature or NOT_GIVEN, + max_tokens=config.marshoai_max_tokens or NOT_GIVEN, + top_p=config.marshoai_top_p or NOT_GIVEN, timeout=config.marshoai_timeout, )