mirror of
https://github.com/FuQuan233/nonebot-plugin-llmchat.git
synced 2025-09-04 10:20:45 +00:00
🐛 修复多条消息中只处理最后一条消息的图片的问题
This commit is contained in:
parent
7edd7c913e
commit
3d85ea90ef
1 changed files with 10 additions and 12 deletions
|
@ -40,8 +40,7 @@ from nonebot_plugin_apscheduler import scheduler
|
|||
|
||||
if TYPE_CHECKING:
|
||||
from openai.types.chat import (
|
||||
ChatCompletionContentPartImageParam,
|
||||
ChatCompletionContentPartTextParam,
|
||||
ChatCompletionContentPartParam,
|
||||
ChatCompletionMessageParam,
|
||||
)
|
||||
|
||||
|
@ -311,16 +310,15 @@ 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 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}"}})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue