From cc078ec35312e10f7fd7fe56b146b5a4294b5672 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Thu, 19 Dec 2024 17:27:55 +0800 Subject: [PATCH] refactor: optimize the display of SST nodes --- .../impl/base_document_extract_node.py | 2 +- .../impl/base_speech_to_text_node.py | 16 ++++++++++++---- .../ai-chat/ExecutionDetailDialog.vue | 17 ++++++++++++----- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/apps/application/flow/step_node/document_extract_node/impl/base_document_extract_node.py b/apps/application/flow/step_node/document_extract_node/impl/base_document_extract_node.py index 620763aef..8bec59636 100644 --- a/apps/application/flow/step_node/document_extract_node/impl/base_document_extract_node.py +++ b/apps/application/flow/step_node/document_extract_node/impl/base_document_extract_node.py @@ -70,7 +70,7 @@ class BaseDocumentExtractNode(IDocumentExtractNode): # 回到文件头 buffer.seek(0) file_content = split_handle.get_content(buffer, save_image) - content.append('## ' + doc['name'] + '\n' + file_content) + content.append('### ' + doc['name'] + '\n' + file_content) break return NodeResult({'content': splitter.join(content)}, {}) diff --git a/apps/application/flow/step_node/speech_to_text_step_node/impl/base_speech_to_text_node.py b/apps/application/flow/step_node/speech_to_text_step_node/impl/base_speech_to_text_node.py index 1660fe1ef..c85588cd4 100644 --- a/apps/application/flow/step_node/speech_to_text_step_node/impl/base_speech_to_text_node.py +++ b/apps/application/flow/step_node/speech_to_text_step_node/impl/base_speech_to_text_node.py @@ -14,7 +14,6 @@ from common.util.common import split_and_transcribe, any_to_mp3 from dataset.models import File from setting.models_provider.tools import get_model_instance_by_model_user_id - class BaseSpeechToTextNode(ISpeechToTextNode): def save_context(self, details, workflow_manage): @@ -37,7 +36,8 @@ class BaseSpeechToTextNode(ISpeechToTextNode): temp_mp3_path = temp_amr_file.name any_to_mp3(temp_file_path, temp_mp3_path) try: - return split_and_transcribe(temp_mp3_path, model) + transcription = split_and_transcribe(temp_mp3_path, model) + return {file.file_name: transcription} finally: os.remove(temp_file_path) os.remove(temp_mp3_path) @@ -45,10 +45,17 @@ class BaseSpeechToTextNode(ISpeechToTextNode): def process_audio_items(audio_list, model): with ThreadPoolExecutor(max_workers=5) as executor: results = list(executor.map(lambda item: process_audio_item(item, model), audio_list)) - return '\n\n'.join(results) + return results result = process_audio_items(audio_list, stt_model) - return NodeResult({'answer': result, 'result': result}, {}) + content = [] + result_content = [] + for item in result: + for key, value in item.items(): + content.append(f'### {key}\n{value}') + result_content.append(value) + return NodeResult({'answer': '\n'.join(result_content), 'result': '\n'.join(result_content), + 'content': content}, {}) def get_details(self, index: int, **kwargs): return { @@ -56,6 +63,7 @@ class BaseSpeechToTextNode(ISpeechToTextNode): "index": index, 'run_time': self.context.get('run_time'), 'answer': self.context.get('answer'), + 'content': self.context.get('content'), 'type': self.node.type, 'status': self.status, 'err_message': self.err_message, diff --git a/ui/src/components/ai-chat/ExecutionDetailDialog.vue b/ui/src/components/ai-chat/ExecutionDetailDialog.vue index f0bd346f6..870868dd1 100644 --- a/ui/src/components/ai-chat/ExecutionDetailDialog.vue +++ b/ui/src/components/ai-chat/ExecutionDetailDialog.vue @@ -293,15 +293,22 @@
文本内容:
-