feat: 应用设置
This commit is contained in:
parent
ab7c789e1b
commit
1420f6278b
@ -79,6 +79,31 @@ const postApplication: (
|
||||
return post(`${prefix}`, data, undefined, loading)
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改应用
|
||||
* @param 参数
|
||||
* {
|
||||
"name": "string",
|
||||
"desc": "string",
|
||||
"model_id": "string",
|
||||
"multiple_rounds_dialogue": true,
|
||||
"prologue": "string",
|
||||
"example": [
|
||||
"string"
|
||||
],
|
||||
"dataset_id_list": [
|
||||
"string"
|
||||
]
|
||||
}
|
||||
*/
|
||||
const putApplication: (
|
||||
applicaiton_id: String,
|
||||
data: ApplicationFormType,
|
||||
loading?: Ref<boolean>
|
||||
) => Promise<Result<any>> = (applicaiton_id, data, loading) => {
|
||||
return put(`${prefix}/${applicaiton_id}`, data, undefined, loading)
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除应用
|
||||
* @param 参数 applicaiton_id
|
||||
@ -91,15 +116,31 @@ const delApplication: (applicaiton_id: String) => Promise<Result<boolean>> = (ap
|
||||
* 应用详情
|
||||
* @param 参数 applicaiton_id
|
||||
*/
|
||||
const getApplicationDetail: (applicaiton_id: string) => Promise<Result<any>> = (applicaiton_id) => {
|
||||
return get(`${prefix}/${applicaiton_id}`)
|
||||
const getApplicationDetail: (
|
||||
applicaiton_id: string,
|
||||
loading?: Ref<boolean>
|
||||
) => Promise<Result<any>> = (applicaiton_id, loading) => {
|
||||
return get(`${prefix}/${applicaiton_id}`, undefined, loading)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前应用可使用的数据集
|
||||
* @param 参数 applicaiton_id
|
||||
*/
|
||||
const getApplicationDataset: (
|
||||
applicaiton_id: string,
|
||||
loading?: Ref<boolean>
|
||||
) => Promise<Result<any>> = (applicaiton_id, loading) => {
|
||||
return get(`${prefix}/${applicaiton_id}/list_dataset`, undefined, loading)
|
||||
}
|
||||
export default {
|
||||
getAllAppilcation,
|
||||
getApplication,
|
||||
postApplication,
|
||||
putApplication,
|
||||
postChatOpen,
|
||||
postChatMessage,
|
||||
delApplication,
|
||||
getApplicationDetail
|
||||
getApplicationDetail,
|
||||
getApplicationDataset
|
||||
}
|
||||
|
||||
@ -55,8 +55,8 @@
|
||||
</AppAvatar>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="flex" v-if="!item.answer_text || item.problem_text.length === 0">
|
||||
<el-card shadow="always" class="dialog-card"> {{ '回答中...' }} </el-card>
|
||||
<div class="flex" v-if="!item.answer_text">
|
||||
<el-card shadow="always" class="dialog-card"> 回答中... </el-card>
|
||||
</div>
|
||||
<el-card v-else shadow="always" class="dialog-card">
|
||||
<MarkdownRenderer :source="item.answer_text"></MarkdownRenderer>
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import applicationApi from '@/api/application'
|
||||
import { type Ref } from 'vue'
|
||||
|
||||
const useApplicationStore = defineStore({
|
||||
id: 'application',
|
||||
@ -18,10 +19,10 @@ const useApplicationStore = defineStore({
|
||||
})
|
||||
},
|
||||
|
||||
async asyncGetApplicationDetail(id: string) {
|
||||
async asyncGetApplicationDetail(id: string, loading?: Ref<boolean>) {
|
||||
return new Promise((resolve, reject) => {
|
||||
applicationApi
|
||||
.getApplicationDetail(id)
|
||||
.getApplicationDetail(id, loading)
|
||||
.then((data) => {
|
||||
resolve(data)
|
||||
})
|
||||
|
||||
@ -171,7 +171,7 @@ import type { Provider } from '@/api/type/model'
|
||||
import { realatedObject } from '@/utils/utils'
|
||||
import { MsgSuccess } from '@/utils/message'
|
||||
import useStore from '@/stores'
|
||||
const { model, dataset, application } = useStore()
|
||||
const { model, dataset, application, user } = useStore()
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
@ -184,7 +184,7 @@ const AddDatasetDialogRef = ref()
|
||||
|
||||
const loading = ref(false)
|
||||
const exampleList = ref(['', ''])
|
||||
const applicationForm = reactive<ApplicationFormType>({
|
||||
const applicationForm = ref<ApplicationFormType>({
|
||||
name: '',
|
||||
desc: '',
|
||||
model_id: '',
|
||||
@ -209,62 +209,63 @@ const providerOptions = ref<Array<Provider>>([])
|
||||
const datasetList = ref([])
|
||||
|
||||
watch(exampleList.value, () => {
|
||||
applicationForm.example = exampleList.value.filter((v) => v)
|
||||
applicationForm.value.example = exampleList.value.filter((v) => v)
|
||||
})
|
||||
|
||||
const submit = async (formEl: FormInstance | undefined) => {
|
||||
if (!formEl) return
|
||||
await formEl.validate((valid, fields) => {
|
||||
if (valid) {
|
||||
applicationApi
|
||||
.postApplication(applicationForm, loading)
|
||||
.then((res) => {
|
||||
if (id) {
|
||||
applicationApi.putApplication(id, applicationForm.value, loading).then((res) => {
|
||||
MsgSuccess('保存成功')
|
||||
})
|
||||
} else {
|
||||
applicationApi.postApplication(applicationForm.value, loading).then((res) => {
|
||||
MsgSuccess('创建成功')
|
||||
router.push({ path: `/application` })
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false
|
||||
})
|
||||
}
|
||||
} else {
|
||||
console.log('error submit!')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function removeDataset(id: String) {
|
||||
applicationForm.dataset_id_list.splice(applicationForm.dataset_id_list.indexOf(id), 1)
|
||||
function removeDataset(id: string) {
|
||||
applicationForm.value.dataset_id_list.splice(applicationForm.value.dataset_id_list.indexOf(id), 1)
|
||||
}
|
||||
function addDataset(val: Array<string>) {
|
||||
applicationForm.dataset_id_list = val
|
||||
applicationForm.value.dataset_id_list = val
|
||||
}
|
||||
function openDatasetDialog() {
|
||||
AddDatasetDialogRef.value.open(applicationForm.dataset_id_list)
|
||||
AddDatasetDialogRef.value.open(applicationForm.value.dataset_id_list)
|
||||
}
|
||||
|
||||
function getDetail() {
|
||||
loading.value = true
|
||||
application
|
||||
.asyncGetApplicationDetail(id)
|
||||
.then((res) => {
|
||||
// detail.value = res.data
|
||||
loading.value = false
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false
|
||||
})
|
||||
application.asyncGetApplicationDetail(id, loading).then((res: any) => {
|
||||
applicationForm.value = res.data
|
||||
applicationForm.value.model_id = res.data.model
|
||||
})
|
||||
}
|
||||
|
||||
function getDataset() {
|
||||
loading.value = true
|
||||
dataset
|
||||
.asyncGetAllDateset()
|
||||
.then((res: any) => {
|
||||
if (id) {
|
||||
applicationApi.getApplicationDataset(id, loading).then((res) => {
|
||||
datasetList.value = res.data
|
||||
loading.value = false
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false
|
||||
})
|
||||
} else {
|
||||
dataset
|
||||
.asyncGetAllDateset()
|
||||
.then((res: any) => {
|
||||
datasetList.value = res.data?.filter((v) => v.user_id === user.userInfo?.id)
|
||||
loading.value = false
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function getModel() {
|
||||
@ -294,12 +295,12 @@ function getProvider() {
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
if (id) {
|
||||
getDetail()
|
||||
}
|
||||
getProvider()
|
||||
getModel()
|
||||
getDataset()
|
||||
if (id) {
|
||||
getDetail()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user