diff --git a/ui/src/api/application.ts b/ui/src/api/application.ts index d7e7e0a2..e3db1488 100644 --- a/ui/src/api/application.ts +++ b/ui/src/api/application.ts @@ -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 +) => Promise> = (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> = (ap * 应用详情 * @param 参数 applicaiton_id */ -const getApplicationDetail: (applicaiton_id: string) => Promise> = (applicaiton_id) => { - return get(`${prefix}/${applicaiton_id}`) +const getApplicationDetail: ( + applicaiton_id: string, + loading?: Ref +) => Promise> = (applicaiton_id, loading) => { + return get(`${prefix}/${applicaiton_id}`, undefined, loading) +} + +/** + * 获得当前应用可使用的数据集 + * @param 参数 applicaiton_id + */ +const getApplicationDataset: ( + applicaiton_id: string, + loading?: Ref +) => Promise> = (applicaiton_id, loading) => { + return get(`${prefix}/${applicaiton_id}/list_dataset`, undefined, loading) } export default { getAllAppilcation, getApplication, postApplication, + putApplication, postChatOpen, postChatMessage, delApplication, - getApplicationDetail + getApplicationDetail, + getApplicationDataset } diff --git a/ui/src/components/ai-dialog/index.vue b/ui/src/components/ai-dialog/index.vue index 27e5e51d..9f95b7d2 100644 --- a/ui/src/components/ai-dialog/index.vue +++ b/ui/src/components/ai-dialog/index.vue @@ -55,8 +55,8 @@
-
- {{ '回答中...' }} +
+ 回答中...
diff --git a/ui/src/stores/modules/application.ts b/ui/src/stores/modules/application.ts index 9eda8aa8..c6ce9dec 100644 --- a/ui/src/stores/modules/application.ts +++ b/ui/src/stores/modules/application.ts @@ -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) { return new Promise((resolve, reject) => { applicationApi - .getApplicationDetail(id) + .getApplicationDetail(id, loading) .then((data) => { resolve(data) }) diff --git a/ui/src/views/application/CreateAndSetting.vue b/ui/src/views/application/CreateAndSetting.vue index 854e5bc8..98f15cf3 100644 --- a/ui/src/views/application/CreateAndSetting.vue +++ b/ui/src/views/application/CreateAndSetting.vue @@ -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({ +const applicationForm = ref({ name: '', desc: '', model_id: '', @@ -209,62 +209,63 @@ const providerOptions = ref>([]) 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) { - 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() + } })