UnisKB/ui/src/views/application/component/CreateApplicationDialog.vue

256 lines
7.2 KiB
Vue
Raw Normal View History

2025-06-03 08:08:49 +00:00
<template>
<el-dialog
2025-06-03 12:45:12 +00:00
:title="
isWorkFlow(applicationForm.type)
? $t('views.application.createWorkFlowApplication')
: $t('views.application.createApplication')
"
2025-06-03 08:08:49 +00:00
v-model="dialogVisible"
width="650"
append-to-body
:close-on-click-modal="false"
:close-on-press-escape="false"
>
<el-form
ref="applicationFormRef"
:model="applicationForm"
:rules="rules"
label-position="top"
require-asterisk-position="right"
@submit.prevent
>
2025-06-03 12:45:12 +00:00
<el-form-item :label="$t('views.application.form.appName.label')" prop="name">
2025-06-03 08:08:49 +00:00
<el-input
v-model="applicationForm.name"
maxlength="64"
2025-06-03 12:45:12 +00:00
:placeholder="$t('views.application.form.appName.placeholder')"
2025-06-03 08:08:49 +00:00
show-word-limit
@blur="applicationForm.name = applicationForm.name?.trim()"
/>
</el-form-item>
2025-06-03 12:45:12 +00:00
<el-form-item :label="$t('views.application.form.appDescription.label')">
2025-06-03 08:08:49 +00:00
<el-input
v-model="applicationForm.desc"
type="textarea"
2025-06-03 12:45:12 +00:00
:placeholder="$t('views.application.form.appDescription.placeholder')"
2025-06-03 08:08:49 +00:00
:rows="3"
maxlength="256"
show-word-limit
/>
</el-form-item>
2025-06-03 12:45:12 +00:00
2025-06-03 08:08:49 +00:00
<el-form-item
:label="$t('views.document.upload.template')"
v-if="applicationForm.type === 'WORK_FLOW'"
>
<div class="w-full">
<el-row :gutter="16">
<el-col :span="12">
<el-card
class="radio-card cursor"
shadow="never"
@click="selectedType('blank')"
:class="appTemplate === 'blank' ? 'active' : ''"
>
2025-06-03 12:45:12 +00:00
{{ $t('views.application.form.appTemplate.blankApp') }}
2025-06-03 08:08:49 +00:00
</el-card>
</el-col>
<el-col :span="12">
<el-card
class="radio-card cursor"
shadow="never"
:class="appTemplate === 'assistant' ? 'active' : ''"
@click="selectedType('assistant')"
>
2025-06-03 12:45:12 +00:00
{{ $t('views.application.form.appTemplate.assistantApp') }}
2025-06-03 08:08:49 +00:00
</el-card>
</el-col>
</el-row>
</div>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click.prevent="dialogVisible = false" :loading="loading">
{{ $t('common.cancel') }}
</el-button>
<el-button type="primary" @click="submitHandle(applicationFormRef)" :loading="loading">
{{ $t('common.create') }}
</el-button>
</span>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import { ref, watch, reactive } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import type { ApplicationFormType } from '@/api/type/application'
import type { FormInstance, FormRules } from 'element-plus'
2025-06-03 09:29:33 +00:00
import applicationApi from '@/api/application/application'
2025-06-03 08:08:49 +00:00
import { MsgSuccess, MsgAlert } from '@/utils/message'
import { isWorkFlow } from '@/utils/application'
import { baseNodes } from '@/workflow/common/data'
import { t } from '@/locales'
const router = useRouter()
const emit = defineEmits(['refresh'])
// @ts-ignore
2025-06-03 12:45:12 +00:00
const defaultPrompt = t('views.application.form.prompt.defaultPrompt', {
2025-06-03 08:08:49 +00:00
data: '{data}',
2025-06-03 12:45:12 +00:00
question: '{question}',
2025-06-03 08:08:49 +00:00
})
const optimizationPrompt =
2025-06-03 12:45:12 +00:00
t('views.application.dialog.defaultPrompt1', {
question: '{question}',
2025-06-03 08:08:49 +00:00
}) +
'<data></data>' +
2025-06-03 12:45:12 +00:00
t('views.application.dialog.defaultPrompt2')
2025-06-03 08:08:49 +00:00
const workflowDefault = ref<any>({
edges: [],
2025-06-03 12:45:12 +00:00
nodes: baseNodes,
2025-06-03 08:08:49 +00:00
})
const appTemplate = ref('blank')
const applicationFormRef = ref()
const loading = ref(false)
const dialogVisible = ref<boolean>(false)
const applicationForm = ref<ApplicationFormType>({
name: '',
desc: '',
model_id: '',
dialogue_number: 1,
2025-06-03 12:45:12 +00:00
prologue: t('views.application.form.defaultPrologue'),
2025-06-03 08:08:49 +00:00
dataset_id_list: [],
dataset_setting: {
top_n: 3,
similarity: 0.6,
max_paragraph_char_number: 5000,
search_mode: 'embedding',
no_references_setting: {
status: 'ai_questioning',
2025-06-03 12:45:12 +00:00
value: '{question}',
},
2025-06-03 08:08:49 +00:00
},
model_setting: {
prompt: defaultPrompt,
2025-06-03 12:45:12 +00:00
system: t('views.application.form.roleSettings.placeholder'),
no_references_prompt: '{question}',
2025-06-03 08:08:49 +00:00
},
model_params_setting: {},
problem_optimization: false,
problem_optimization_prompt: optimizationPrompt,
stt_model_id: '',
tts_model_id: '',
stt_model_enable: false,
tts_model_enable: false,
tts_type: 'BROWSER',
2025-06-03 12:45:12 +00:00
type: 'SIMPLE',
2025-06-03 08:08:49 +00:00
})
const rules = reactive<FormRules<ApplicationFormType>>({
name: [
{
required: true,
2025-06-03 12:45:12 +00:00
message: t('views.application.form.appName.placeholder'),
trigger: 'blur',
},
2025-06-03 08:08:49 +00:00
],
model_id: [
{
required: false,
2025-06-03 12:45:12 +00:00
message: t('views.application.form.aiModel.placeholder'),
trigger: 'change',
},
],
2025-06-03 08:08:49 +00:00
})
2025-06-03 12:45:12 +00:00
const currentFolder = ref('')
2025-06-03 08:08:49 +00:00
watch(dialogVisible, (bool) => {
if (!bool) {
applicationForm.value = {
name: '',
desc: '',
model_id: '',
dialogue_number: 1,
2025-06-03 12:45:12 +00:00
prologue: t('views.application.form.defaultPrologue'),
2025-06-03 08:08:49 +00:00
dataset_id_list: [],
dataset_setting: {
top_n: 3,
similarity: 0.6,
max_paragraph_char_number: 5000,
search_mode: 'embedding',
no_references_setting: {
status: 'ai_questioning',
2025-06-03 12:45:12 +00:00
value: '{question}',
},
2025-06-03 08:08:49 +00:00
},
model_setting: {
prompt: defaultPrompt,
2025-06-03 12:45:12 +00:00
system: t('views.application.form.roleSettings.placeholder'),
no_references_prompt: '{question}',
2025-06-03 08:08:49 +00:00
},
model_params_setting: {},
problem_optimization: false,
problem_optimization_prompt: optimizationPrompt,
stt_model_id: '',
tts_model_id: '',
stt_model_enable: false,
tts_model_enable: false,
tts_type: 'BROWSER',
2025-06-03 12:45:12 +00:00
type: 'SIMPLE',
2025-06-03 08:08:49 +00:00
}
applicationFormRef.value?.clearValidate()
}
})
2025-06-03 12:45:12 +00:00
const open = (folder: string, type?: sting) => {
currentFolder.value = folder
applicationForm.value.type = type || 'SIMPLE'
2025-06-03 08:08:49 +00:00
dialogVisible.value = true
}
const submitHandle = async (formEl: FormInstance | undefined) => {
if (!formEl) return
await formEl.validate((valid) => {
if (valid) {
2025-06-03 12:45:12 +00:00
applicationForm.value['folder_id'] = currentFolder.value
2025-06-03 08:08:49 +00:00
if (isWorkFlow(applicationForm.value.type) && appTemplate.value === 'blank') {
workflowDefault.value.nodes[0].properties.node_data.desc = applicationForm.value.desc
workflowDefault.value.nodes[0].properties.node_data.name = applicationForm.value.name
applicationForm.value['work_flow'] = workflowDefault.value
}
2025-06-03 12:45:12 +00:00
applicationApi.postApplication('default', applicationForm.value, loading).then((res) => {
2025-06-03 08:08:49 +00:00
MsgSuccess(t('common.createSuccess'))
emit('refresh')
if (isWorkFlow(applicationForm.value.type)) {
router.push({ path: `/application/${res.data.id}/workflow` })
} else {
router.push({ path: `/application/${res.data.id}/${res.data.type}/setting` })
}
dialogVisible.value = false
})
}
})
}
function selectedType(type: string) {
appTemplate.value = type
}
defineExpose({ open })
</script>
<style lang="scss" scoped>
.radio-card {
line-height: 22px;
&.active {
border-color: var(--el-color-primary);
color: var(--el-color-primary);
}
}
</style>