Skip to content

Commit d32f7d3

Browse files
committed
feat: add support for uploading other file types and extend file upload settings
--story=1018411 --user=刘瑞斌 【工作流应用】文件上传可以支持其它文件类型 https://www.tapd.cn/57709429/s/1688679
1 parent 54c9d4e commit d32f7d3

File tree

11 files changed

+185
-27
lines changed

11 files changed

+185
-27
lines changed

apps/application/flow/step_node/start_node/impl/base_start_node.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def save_context(self, details, workflow_manage):
4040
self.context['document'] = details.get('document_list')
4141
self.context['image'] = details.get('image_list')
4242
self.context['audio'] = details.get('audio_list')
43+
self.context['other'] = details.get('other_list')
4344
self.status = details.get('status')
4445
self.err_message = details.get('err_message')
4546
for key, value in workflow_variable.items():
@@ -59,7 +60,8 @@ def execute(self, question, **kwargs) -> NodeResult:
5960
'question': question,
6061
'image': self.workflow_manage.image_list,
6162
'document': self.workflow_manage.document_list,
62-
'audio': self.workflow_manage.audio_list
63+
'audio': self.workflow_manage.audio_list,
64+
'other': self.workflow_manage.other_list,
6365
}
6466
return NodeResult(node_variable, workflow_variable)
6567

@@ -83,5 +85,6 @@ def get_details(self, index: int, **kwargs):
8385
'image_list': self.context.get('image'),
8486
'document_list': self.context.get('document'),
8587
'audio_list': self.context.get('audio'),
88+
'other_list': self.context.get('other'),
8689
'global_fields': global_fields
8790
}

apps/application/flow/workflow_manage.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ def __init__(self, flow: Flow, params, work_flow_post_handler: WorkFlowPostHandl
238238
base_to_response: BaseToResponse = SystemToResponse(), form_data=None, image_list=None,
239239
document_list=None,
240240
audio_list=None,
241+
other_list=None,
241242
start_node_id=None,
242243
start_node_data=None, chat_record=None, child_node=None):
243244
if form_data is None:
@@ -248,12 +249,15 @@ def __init__(self, flow: Flow, params, work_flow_post_handler: WorkFlowPostHandl
248249
document_list = []
249250
if audio_list is None:
250251
audio_list = []
252+
if other_list is None:
253+
other_list = []
251254
self.start_node_id = start_node_id
252255
self.start_node = None
253256
self.form_data = form_data
254257
self.image_list = image_list
255258
self.document_list = document_list
256259
self.audio_list = audio_list
260+
self.other_list = other_list
257261
self.params = params
258262
self.flow = flow
259263
self.context = {}

apps/application/serializers/chat_message_serializers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ def chat(self, instance: Dict, with_valid=True):
245245
'image_list': instance.get('image_list', []),
246246
'document_list': instance.get('document_list', []),
247247
'audio_list': instance.get('audio_list', []),
248+
'other_list': instance.get('other_list', []),
248249
}
249250
).chat(base_to_response=OpenaiToResponse())
250251

@@ -274,6 +275,7 @@ class ChatMessageSerializer(serializers.Serializer):
274275
image_list = serializers.ListField(required=False, error_messages=ErrMessage.list(_("picture")))
275276
document_list = serializers.ListField(required=False, error_messages=ErrMessage.list(_("document")))
276277
audio_list = serializers.ListField(required=False, error_messages=ErrMessage.list(_("Audio")))
278+
other_list = serializers.ListField(required=False, error_messages=ErrMessage.list(_("Other")))
277279
child_node = serializers.DictField(required=False, allow_null=True,
278280
error_messages=ErrMessage.dict(_("Child Nodes")))
279281

@@ -372,6 +374,7 @@ def chat_work_flow(self, chat_info: ChatInfo, base_to_response):
372374
image_list = self.data.get('image_list')
373375
document_list = self.data.get('document_list')
374376
audio_list = self.data.get('audio_list')
377+
other_list = self.data.get('other_list')
375378
user_id = chat_info.application.user_id
376379
chat_record_id = self.data.get('chat_record_id')
377380
chat_record = None
@@ -388,7 +391,7 @@ def chat_work_flow(self, chat_info: ChatInfo, base_to_response):
388391
'client_id': client_id,
389392
'client_type': client_type,
390393
'user_id': user_id}, WorkFlowPostHandler(chat_info, client_id, client_type),
391-
base_to_response, form_data, image_list, document_list, audio_list,
394+
base_to_response, form_data, image_list, document_list, audio_list, other_list,
392395
self.data.get('runtime_node_id'),
393396
self.data.get('node_data'), chat_record, self.data.get('child_node'))
394397
r = work_flow_manage.run()

apps/application/views/chat_views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ def post(self, request: Request, chat_id: str):
144144
'document_list') if 'document_list' in request.data else [],
145145
'audio_list': request.data.get(
146146
'audio_list') if 'audio_list' in request.data else [],
147+
'other_list': request.data.get(
148+
'other_list') if 'other_list' in request.data else [],
147149
'client_type': request.auth.client_type,
148150
'node_id': request.data.get('node_id', None),
149151
'runtime_node_id': request.data.get('runtime_node_id', None),

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

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
uploadDocumentList.length ||
1111
uploadImageList.length ||
1212
uploadAudioList.length ||
13-
uploadVideoList.length
13+
uploadVideoList.length ||
14+
uploadOtherList.length
1415
"
1516
>
1617
<el-row :gutter="10">
@@ -50,6 +51,42 @@
5051
</div>
5152
</el-card>
5253
</el-col>
54+
<el-col
55+
v-for="(item, index) in uploadOtherList"
56+
:key="index"
57+
:xs="24"
58+
:sm="props.type === 'debug-ai-chat' ? 24 : 12"
59+
:md="props.type === 'debug-ai-chat' ? 24 : 12"
60+
:lg="props.type === 'debug-ai-chat' ? 24 : 12"
61+
:xl="props.type === 'debug-ai-chat' ? 24 : 12"
62+
class="mb-8"
63+
>
64+
<el-card
65+
shadow="never"
66+
style="--el-card-padding: 8px; max-width: 100%"
67+
class="file cursor"
68+
>
69+
<div
70+
class="flex align-center"
71+
@mouseenter.stop="mouseenter(item)"
72+
@mouseleave.stop="mouseleave()"
73+
>
74+
<div
75+
@click="deleteFile(index, 'document')"
76+
class="delete-icon color-secondary"
77+
v-if="showDelete === item.url"
78+
>
79+
<el-icon>
80+
<CircleCloseFilled />
81+
</el-icon>
82+
</div>
83+
<img :src="getImgUrl(item && item?.name)" alt="" width="24" />
84+
<div class="ml-4 ellipsis-1" :title="item && item?.name">
85+
{{ item && item?.name }}
86+
</div>
87+
</div>
88+
</el-card>
89+
</el-col>
5390

5491
<el-col
5592
:xs="24"
@@ -310,9 +347,10 @@ const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp']
310347
const documentExtensions = ['pdf', 'docx', 'txt', 'xls', 'xlsx', 'md', 'html', 'csv']
311348
const videoExtensions = ['mp4', 'avi', 'mov', 'mkv', 'flv']
312349
const audioExtensions = ['mp3', 'wav', 'ogg', 'aac', 'm4a']
350+
let otherExtensions = ['ppt', 'doc']
313351
314352
const getAcceptList = () => {
315-
const { image, document, audio, video } = props.applicationDetails.file_upload_setting
353+
const { image, document, audio, video, other } = props.applicationDetails.file_upload_setting
316354
let accepts: any = []
317355
if (image) {
318356
accepts = [...imageExtensions]
@@ -326,6 +364,11 @@ const getAcceptList = () => {
326364
if (video) {
327365
accepts = [...accepts, ...videoExtensions]
328366
}
367+
if (other) {
368+
// 其他文件类型
369+
otherExtensions = props.applicationDetails.file_upload_setting.otherExtensions
370+
accepts = [...accepts, ...otherExtensions]
371+
}
329372
330373
if (accepts.length === 0) {
331374
return `.${t('chat.uploadFile.tipMessage')}`
@@ -339,7 +382,8 @@ const checkMaxFilesLimit = () => {
339382
uploadImageList.value.length +
340383
uploadDocumentList.value.length +
341384
uploadAudioList.value.length +
342-
uploadVideoList.value.length
385+
uploadVideoList.value.length +
386+
uploadOtherList.value.length
343387
)
344388
}
345389
@@ -350,7 +394,8 @@ const uploadFile = async (file: any, fileList: any) => {
350394
uploadImageList.value.length +
351395
uploadDocumentList.value.length +
352396
uploadAudioList.value.length +
353-
uploadVideoList.value.length
397+
uploadVideoList.value.length +
398+
uploadOtherList.value.length
354399
if (file_limit_once >= maxFiles) {
355400
MsgWarning(t('chat.uploadFile.limitMessage1') + maxFiles + t('chat.uploadFile.limitMessage2'))
356401
fileList.splice(0, fileList.length)
@@ -376,6 +421,8 @@ const uploadFile = async (file: any, fileList: any) => {
376421
uploadVideoList.value.push(file)
377422
} else if (audioExtensions.includes(extension)) {
378423
uploadAudioList.value.push(file)
424+
} else if (otherExtensions.includes(extension)) {
425+
uploadOtherList.value.push(file)
379426
}
380427
381428
if (!chatId_context.value) {
@@ -434,6 +481,15 @@ const uploadFile = async (file: any, fileList: any) => {
434481
file.file_id = f[0].file_id
435482
}
436483
})
484+
uploadOtherList.value.forEach((file: any) => {
485+
const f = response.data.filter(
486+
(f: any) => f.name.replaceAll(' ', '') === file.name.replaceAll(' ', '')
487+
)
488+
if (f.length > 0) {
489+
file.url = f[0].url
490+
file.file_id = f[0].file_id
491+
}
492+
})
437493
if (!inputValue.value && uploadImageList.value.length > 0) {
438494
inputValue.value = t('chat.uploadFile.imageMessage')
439495
}
@@ -499,6 +555,7 @@ const uploadImageList = ref<Array<any>>([])
499555
const uploadDocumentList = ref<Array<any>>([])
500556
const uploadVideoList = ref<Array<any>>([])
501557
const uploadAudioList = ref<Array<any>>([])
558+
const uploadOtherList = ref<Array<any>>([])
502559
503560
const showDelete = ref('')
504561
@@ -709,13 +766,15 @@ function autoSendMessage() {
709766
image_list: uploadImageList.value,
710767
document_list: uploadDocumentList.value,
711768
audio_list: uploadAudioList.value,
712-
video_list: uploadVideoList.value
769+
video_list: uploadVideoList.value,
770+
other_list: uploadOtherList.value,
713771
})
714772
inputValue.value = ''
715773
uploadImageList.value = []
716774
uploadDocumentList.value = []
717775
uploadAudioList.value = []
718776
uploadVideoList.value = []
777+
uploadOtherList.value = []
719778
if (quickInputRef.value) {
720779
quickInputRef.value.textareaStyle.height = '45px'
721780
}
@@ -771,6 +830,8 @@ function deleteFile(index: number, val: string) {
771830
uploadVideoList.value.splice(index, 1)
772831
} else if (val === 'audio') {
773832
uploadAudioList.value.splice(index, 1)
833+
} else if (val === 'other') {
834+
uploadOtherList.value.splice(index, 1)
774835
}
775836
}
776837

ui/src/locales/lang/en-US/common.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ export default {
4545
document: 'Documents',
4646
image: 'Image',
4747
audio: 'Audio',
48-
video: 'Video'
48+
video: 'Video',
49+
other: 'Other file',
50+
addExtensions: 'Add file extensions',
4951
},
5052
status: {
5153
label: 'Status',
@@ -55,7 +57,7 @@ export default {
5557
param: {
5658
outputParam: 'Output Parameters',
5759
inputParam: 'Input Parameters',
58-
initParam: 'Startup Parameters',
60+
initParam: 'Startup Parameters'
5961
},
6062

6163
inputPlaceholder: 'Please input',

ui/src/locales/lang/zh-CN/common.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ export default {
4545
document: '文档',
4646
image: '图片',
4747
audio: '音频',
48-
video: '视频'
48+
video: '视频',
49+
other: '其他文件',
50+
addExtensions: '添加文件扩展名',
4951
},
5052
status: {
5153
label: '状态',

ui/src/locales/lang/zh-Hant/common.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ export default {
4545
document: '文檔',
4646
image: '圖片',
4747
audio: '音頻',
48-
video: '視頻'
48+
video: '視頻',
49+
other: '其他文件',
50+
addExtensions: '添加文件擴展名'
4951
},
5052
status: {
5153
label: '狀態',

0 commit comments

Comments
 (0)