From 3d85ea90ef3d84cc885477b68726eb32c65fa1e2 Mon Sep 17 00:00:00 2001 From: FuQuan233 Date: Tue, 13 May 2025 13:41:28 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E5=A4=9A?= =?UTF-8?q?=E6=9D=A1=E6=B6=88=E6=81=AF=E4=B8=AD=E5=8F=AA=E5=A4=84=E7=90=86?= =?UTF-8?q?=E6=9C=80=E5=90=8E=E4=B8=80=E6=9D=A1=E6=B6=88=E6=81=AF=E7=9A=84?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_plugin_llmchat/__init__.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/nonebot_plugin_llmchat/__init__.py b/nonebot_plugin_llmchat/__init__.py index dbaad07..600ae9e 100755 --- a/nonebot_plugin_llmchat/__init__.py +++ b/nonebot_plugin_llmchat/__init__.py @@ -40,8 +40,7 @@ from nonebot_plugin_apscheduler import scheduler if TYPE_CHECKING: from openai.types.chat import ( - ChatCompletionContentPartImageParam, - ChatCompletionContentPartTextParam, + ChatCompletionContentPartParam, ChatCompletionMessageParam, ) @@ -311,18 +310,17 @@ async def process_messages(group_id: int): if state.past_events.__len__() < 1: break - # 将消息中的图片转成 base64 - base64_images = [] - if preset.support_image: - base64_images = await process_images(event) + content: list[ChatCompletionContentPartParam] = [] # 将机器人错过的消息推送给LLM - text_content = ",".join([format_message(ev) for ev in state.past_events]) - content: list[ChatCompletionContentPartTextParam | ChatCompletionContentPartImageParam] = [ - {"type": "text", "text": text_content} - ] - for base64_image in base64_images: - content.append({"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{base64_image}"}}) + for ev in state.past_events: + content.append({"type": "text", "text": format_message(ev)}) + + # 将消息中的图片转成 base64 + if preset.support_image: + base64_images = await process_images(ev) + for base64_image in base64_images: + content.append({"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{base64_image}"}}) new_messages: list[ChatCompletionMessageParam] = [ {"role": "user", "content": content}