Skip to content

Commit

Permalink
refactor: optimize the display of SST nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
wxg0103 committed Dec 19, 2024
1 parent c000ee4 commit 1823a7f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def save_image(image_list):
# 回到文件头
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)}, {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from dataset.models import File
from setting.models_provider.tools import get_model_instance_by_model_user_id

splitter = '\n`-----------------------------------`\n'


class BaseSpeechToTextNode(ISpeechToTextNode):

Expand All @@ -37,25 +39,34 @@ def process_audio_item(audio_item, model):
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)

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 {
'name': self.node.properties.get('stepName'),
"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,
Expand Down
17 changes: 12 additions & 5 deletions ui/src/components/ai-chat/ExecutionDetailDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,22 @@
<div class="card-never border-r-4">
<h5 class="p-8-12">参数输出</h5>
<div class="p-8-12 border-t-dashed lighter">
<p class="mb-8 color-secondary">文本内容:</p>
<div v-if="item.answer">
<el-card
shadow="never"
style="--el-card-padding: 8px"
v-for="(file_content, index) in item.content"
:key="index"
class="mb-8"
>
<MdPreview
v-if="file_content"
ref="editorRef"
editorId="preview-only"
:modelValue="item.answer"
:modelValue="file_content"
style="background: none"
/>
</div>
<template v-else> -</template>
</el-card>
</div>
</div>
</template>
Expand Down Expand Up @@ -544,7 +551,7 @@
:modelValue="item.answer"
style="background: none"
/>
<template v-else> - </template>
<template v-else> -</template>
</div>
</div>
</template>
Expand Down

0 comments on commit 1823a7f

Please sign in to comment.