Skip to content

Commit a329770

Browse files
committed
fix: 修复图片理解携带历史会话
1 parent 10fc464 commit a329770

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import List, Dict
77

88
from django.db.models import QuerySet
9-
from langchain_core.messages import BaseMessage, HumanMessage, SystemMessage
9+
from langchain_core.messages import BaseMessage, HumanMessage, SystemMessage, AIMessage
1010

1111
from application.flow.i_step_node import NodeResult, INode
1212
from application.flow.step_node.image_understand_step_node.i_image_understand_node import IImageUnderstandNode
@@ -96,11 +96,19 @@ def execute(self, model_id, system, prompt, dialogue_number, dialogue_type, hist
9696
def get_history_message_for_details(self, history_chat_record, dialogue_number):
9797
start_index = len(history_chat_record) - dialogue_number
9898
history_message = reduce(lambda x, y: [*x, *y], [
99-
[self.generate_history_human_message_for_details(history_chat_record[index]), history_chat_record[index].get_ai_message()]
99+
[self.generate_history_human_message_for_details(history_chat_record[index]), self.generate_history_ai_message(history_chat_record[index])]
100100
for index in
101101
range(start_index if start_index > 0 else 0, len(history_chat_record))], [])
102102
return history_message
103103

104+
def generate_history_ai_message(self, chat_record):
105+
for val in chat_record.details.values():
106+
if self.node.id == val['node_id'] and 'image_list' in val:
107+
if val['dialogue_type'] == 'WORKFLOW':
108+
return chat_record.get_ai_message()
109+
return AIMessage(content=val['answer'])
110+
return chat_record.get_ai_message()
111+
104112
def generate_history_human_message_for_details(self, chat_record):
105113
for data in chat_record.details.values():
106114
if self.node.id == data['node_id'] and 'image_list' in data:
@@ -113,7 +121,7 @@ def generate_history_human_message_for_details(self, chat_record):
113121
def get_history_message(self, history_chat_record, dialogue_number):
114122
start_index = len(history_chat_record) - dialogue_number
115123
history_message = reduce(lambda x, y: [*x, *y], [
116-
[self.generate_history_human_message(history_chat_record[index]), history_chat_record[index].get_ai_message()]
124+
[self.generate_history_human_message(history_chat_record[index]), self.generate_history_ai_message(history_chat_record[index])]
117125
for index in
118126
range(start_index if start_index > 0 else 0, len(history_chat_record))], [])
119127
return history_message

0 commit comments

Comments
 (0)