Skip to content

Commit 5c64d63

Browse files
committed
feat: 支持上传mp3文件
1 parent 28a2c98 commit 5c64d63

File tree

3 files changed

+75
-8
lines changed

3 files changed

+75
-8
lines changed

ui/src/components/ai-chat/component/chat-input-operate/index.vue

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<div
77
class="p-8-12"
88
v-loading="localLoading"
9-
v-if="uploadDocumentList.length || uploadImageList.length"
9+
v-if="uploadDocumentList.length || uploadImageList.length || uploadAudioList.length || uploadVideoList.length"
1010
>
1111
<el-space wrap>
1212
<template v-for="(item, index) in uploadDocumentList" :key="index">
@@ -53,6 +53,27 @@
5353
/>
5454
</div>
5555
</template>
56+
<template v-for="(item, index) in uploadAudioList" :key="index">
57+
<el-card shadow="never" style="--el-card-padding: 8px" class="file cursor">
58+
<div
59+
class="flex align-center"
60+
@mouseenter.stop="mouseenter(item)"
61+
@mouseleave.stop="mouseleave()"
62+
>
63+
<div
64+
@click="deleteFile(index, 'audio')"
65+
class="delete-icon color-secondary"
66+
v-if="showDelete === item.url"
67+
>
68+
<el-icon><CircleCloseFilled /></el-icon>
69+
</div>
70+
<img :src="getImgUrl(item && item?.name)" alt="" width="24" />
71+
<div class="ml-4 ellipsis" style="max-width: 160px" :title="item && item?.name">
72+
{{ item && item?.name }}
73+
</div>
74+
</div>
75+
</el-card>
76+
</template>
5677
</el-space>
5778
</div>
5879
</el-scrollbar>
@@ -200,7 +221,7 @@ const localLoading = computed({
200221
const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp']
201222
const documentExtensions = ['pdf', 'docx', 'txt', 'xls', 'xlsx', 'md', 'html', 'csv']
202223
const videoExtensions = ['mp4', 'avi', 'mov', 'mkv', 'flv']
203-
const audioExtensions = ['mp3', 'wav', 'aac', 'flac']
224+
const audioExtensions = ['mp3']
204225
205226
const getAcceptList = () => {
206227
const { image, document, audio, video } = props.applicationDetails.file_upload_setting
@@ -227,14 +248,14 @@ const getAcceptList = () => {
227248
const checkMaxFilesLimit = () => {
228249
return (
229250
props.applicationDetails.file_upload_setting.maxFiles <=
230-
uploadImageList.value.length + uploadDocumentList.value.length
251+
uploadImageList.value.length + uploadDocumentList.value.length + uploadAudioList.value.length + uploadVideoList.value.length
231252
)
232253
}
233254
234255
const uploadFile = async (file: any, fileList: any) => {
235256
const { maxFiles, fileLimit } = props.applicationDetails.file_upload_setting
236257
// 单次上传文件数量限制
237-
const file_limit_once = uploadImageList.value.length + uploadDocumentList.value.length
258+
const file_limit_once = uploadImageList.value.length + uploadDocumentList.value.length + uploadAudioList.value.length + uploadVideoList.value.length
238259
if (file_limit_once >= maxFiles) {
239260
MsgWarning('最多上传' + maxFiles + '个文件')
240261
fileList.splice(0, fileList.length)
@@ -257,9 +278,9 @@ const uploadFile = async (file: any, fileList: any) => {
257278
} else if (documentExtensions.includes(extension)) {
258279
uploadDocumentList.value.push(file)
259280
} else if (videoExtensions.includes(extension)) {
260-
// videos.push(file)
281+
uploadVideoList.value.push(file)
261282
} else if (audioExtensions.includes(extension)) {
262-
// audios.push(file)
283+
uploadAudioList.value.push(file)
263284
}
264285
265286
@@ -297,7 +318,20 @@ const uploadFile = async (file: any, fileList: any) => {
297318
file.file_id = f[0].file_id
298319
}
299320
})
300-
console.log(uploadDocumentList.value, uploadImageList.value)
321+
uploadAudioList.value.forEach((file: any) => {
322+
const f = response.data.filter((f: any) => f.name === file.name)
323+
if (f.length > 0) {
324+
file.url = f[0].url
325+
file.file_id = f[0].file_id
326+
}
327+
})
328+
uploadVideoList.value.forEach((file: any) => {
329+
const f = response.data.filter((f: any) => f.name === file.name)
330+
if (f.length > 0) {
331+
file.url = f[0].url
332+
file.file_id = f[0].file_id
333+
}
334+
})
301335
})
302336
}
303337
const recorderTime = ref(0)
@@ -306,6 +340,8 @@ const recorderLoading = ref(false)
306340
const inputValue = ref<string>('')
307341
const uploadImageList = ref<Array<any>>([])
308342
const uploadDocumentList = ref<Array<any>>([])
343+
const uploadVideoList = ref<Array<any>>([])
344+
const uploadAudioList = ref<Array<any>>([])
309345
const mediaRecorderStatus = ref(true)
310346
const showDelete = ref('')
311347
@@ -433,11 +469,15 @@ function sendChatHandle(event: any) {
433469
if (inputValue.value.trim()) {
434470
props.sendMessage(inputValue.value, {
435471
image_list: uploadImageList.value,
436-
document_list: uploadDocumentList.value
472+
document_list: uploadDocumentList.value,
473+
audio_list: uploadAudioList.value,
474+
video_list: uploadVideoList.value,
437475
})
438476
inputValue.value = ''
439477
uploadImageList.value = []
440478
uploadDocumentList.value = []
479+
uploadAudioList.value = []
480+
uploadVideoList.value = []
441481
quickInputRef.value.textareaStyle.height = '45px'
442482
}
443483
}
@@ -452,6 +492,10 @@ function deleteFile(index: number, val: string) {
452492
uploadImageList.value.splice(index, 1)
453493
} else if (val === 'document') {
454494
uploadDocumentList.value.splice(index, 1)
495+
} else if (val === 'video') {
496+
uploadVideoList.value.splice(index, 1)
497+
} else if (val === 'audio') {
498+
uploadAudioList.value.splice(index, 1)
455499
}
456500
}
457501
function mouseenter(row: any) {

ui/src/workflow/nodes/base-node/component/FileUploadSettingDialog.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@
6868
<el-checkbox v-model="form_data.image" />
6969
</div>
7070
</el-card>
71+
<el-card
72+
shadow="hover"
73+
class="card-checkbox cursor w-full mb-8"
74+
:class="form_data.audio ? 'active' : ''"
75+
style="--el-card-padding: 8px 16px"
76+
>
77+
<div class="flex-between">
78+
<div class="flex align-center">
79+
<img class="mr-12" src="@/assets/icon_file-image.svg" alt="" />
80+
<div>
81+
<p class="line-height-22 mt-4">音频(MP3)</p>
82+
<el-text class="color-secondary">所选模型支持接收音频或与语音转文本节点配合使用</el-text>
83+
</div>
84+
</div>
85+
<el-checkbox v-model="form_data.audio" />
86+
</div>
87+
</el-card>
7188
</el-form-item>
7289
</el-form>
7390
<template #footer>

ui/src/workflow/nodes/start-node/index.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ const refreshFileUploadConfig = () => {
8282
if (form_data[0].image) {
8383
fileUploadFields.push({ label: '图片', value: 'image' })
8484
}
85+
if (form_data[0].audio) {
86+
fileUploadFields.push({ label: '音频', value: 'audio' })
87+
}
88+
if (form_data[0].video) {
89+
fileUploadFields.push({ label: '视频', value: 'video' })
90+
}
8591
8692
set(props.nodeModel.properties.config, 'fields', [...fields, ...fileUploadFields])
8793
}

0 commit comments

Comments
 (0)