Skip to content

Commit a66851e

Browse files
committed
refactor: 处理多张图片的HumanMessage
1 parent 547b2bd commit a66851e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

apps/application/flow/step_node/image_understand_step_node/impl/base_image_understand_node.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,17 @@ def generate_prompt_question(self, prompt):
116116

117117
def generate_message_list(self, image_model, system: str, prompt: str, history_message, image):
118118
if image is not None and len(image) > 0:
119-
file_id = image[0]['file_id']
120-
file = QuerySet(File).filter(id=file_id).first()
121-
base64_image = base64.b64encode(file.get_byte()).decode("utf-8")
119+
# 处理多张图片
120+
images = []
121+
for img in image:
122+
file_id = img['file_id']
123+
file = QuerySet(File).filter(id=file_id).first()
124+
base64_image = base64.b64encode(file.get_byte()).decode("utf-8")
125+
images.append({'type': 'image_url', 'image_url': {'url': f'data:image/jpeg;base64,{base64_image}'}})
122126
messages = [HumanMessage(
123127
content=[
124128
{'type': 'text', 'text': self.workflow_manage.generate_prompt(prompt)},
125-
{'type': 'image_url', 'image_url': {'url': f'data:image/jpeg;base64,{base64_image}'}},
129+
*images
126130
])]
127131
else:
128132
messages = [HumanMessage(self.workflow_manage.generate_prompt(prompt))]

0 commit comments

Comments
 (0)