Skip to content

Commit 8222427

Browse files
committed
fix: update video handling to return URLs instead of base64 encoding
1 parent 79b47bb commit 8222427

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

apps/application/flow/step_node/video_understand_step_node/impl/base_video_understand_node.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ def write_context(node_variable: Dict, workflow_variable: Dict, node: INode, wor
5959
_write_context(node_variable, workflow_variable, node, workflow, answer)
6060

6161

62-
def file_id_to_base64(file_id: str):
62+
def file_id_to_base64(file_id: str, video_model):
6363
file = QuerySet(File).filter(id=file_id).first()
6464
file_bytes = file.get_bytes()
65-
base64_video = base64.b64encode(file_bytes).decode("utf-8")
66-
return [base64_video, get_video_format(file.file_name)]
65+
url = video_model.upload_file_and_get_url(file_bytes, file.file_name)
66+
return url
6767

6868

6969
class BaseVideoUnderstandNode(IVideoUnderstandNode):
@@ -88,7 +88,8 @@ def execute(self, model_id, system, prompt, dialogue_number, dialogue_type, hist
8888
self.context['question'] = question.content
8989
# 生成消息列表, 真实的history_message
9090
message_list = self.generate_message_list(video_model, system, prompt,
91-
self.get_history_message(history_chat_record, dialogue_number), video)
91+
self.get_history_message(history_chat_record, dialogue_number,
92+
video_model), video)
9293
self.context['message_list'] = message_list
9394
self.generate_context_video(video)
9495
self.context['dialogue_type'] = dialogue_type
@@ -140,28 +141,28 @@ def generate_history_human_message_for_details(self, chat_record):
140141
])
141142
return HumanMessage(content=chat_record.problem_text)
142143

143-
def get_history_message(self, history_chat_record, dialogue_number):
144+
def get_history_message(self, history_chat_record, dialogue_number, video_model):
144145
start_index = len(history_chat_record) - dialogue_number
145146
history_message = reduce(lambda x, y: [*x, *y], [
146-
[self.generate_history_human_message(history_chat_record[index]),
147-
self.generate_history_ai_message(history_chat_record[index])]
147+
[self.generate_history_human_message(history_chat_record[index], video_model),
148+
self.generate_history_ai_message(history_chat_record[index]), video_model]
148149
for index in
149150
range(start_index if start_index > 0 else 0, len(history_chat_record))], [])
150151
return history_message
151152

152-
def generate_history_human_message(self, chat_record):
153+
def generate_history_human_message(self, chat_record, video_model):
153154

154155
for data in chat_record.details.values():
155156
if self.node.id == data['node_id'] and 'video_list' in data:
156157
video_list = data['video_list']
157158
if len(video_list) == 0 or data['dialogue_type'] == 'WORKFLOW':
158159
return HumanMessage(content=chat_record.problem_text)
159-
video_base64_list = [file_id_to_base64(video.get('file_id')) for video in video_list]
160+
video_base64_list = [file_id_to_base64(video.get('file_id'), video_model) for video in video_list]
160161
return HumanMessage(
161162
content=[
162163
{'type': 'text', 'text': data['question']},
163164
*[{'type': 'video_url',
164-
'video_url': {'url': f'data:{base64_video[1]};base64,{base64_video[0]}'}} for
165+
'video_url': {'url': f'{base64_video}'}} for
165166
base64_video in video_base64_list]
166167
])
167168
return HumanMessage(content=chat_record.problem_text)

0 commit comments

Comments
 (0)