feat: 知识库设置增加embedding模型
This commit is contained in:
parent
18cdd44d75
commit
73937746f9
@ -129,11 +129,12 @@ const getDatasetDetail: (dataset_id: string, loading?: Ref<boolean>) => Promise<
|
|||||||
"desc": true
|
"desc": true
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
const putDataset: (dataset_id: string, data: any) => Promise<Result<any>> = (
|
const putDataset: (
|
||||||
dataset_id,
|
dataset_id: string,
|
||||||
data: any
|
data: any,
|
||||||
) => {
|
loading?: Ref<boolean>
|
||||||
return put(`${prefix}/${dataset_id}`, data)
|
) => Promise<Result<any>> = (dataset_id, data, loading) => {
|
||||||
|
return put(`${prefix}/${dataset_id}`, data, undefined, loading)
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 获取知识库 可关联的应用列表
|
* 获取知识库 可关联的应用列表
|
||||||
|
|||||||
@ -105,7 +105,7 @@ import { useRoute } from 'vue-router'
|
|||||||
import BaseForm from '@/views/dataset/component/BaseForm.vue'
|
import BaseForm from '@/views/dataset/component/BaseForm.vue'
|
||||||
import datasetApi from '@/api/dataset'
|
import datasetApi from '@/api/dataset'
|
||||||
import type { ApplicationFormType } from '@/api/type/application'
|
import type { ApplicationFormType } from '@/api/type/application'
|
||||||
import { MsgSuccess } from '@/utils/message'
|
import { MsgSuccess, MsgConfirm } from '@/utils/message'
|
||||||
import { isAppIcon } from '@/utils/application'
|
import { isAppIcon } from '@/utils/application'
|
||||||
import useStore from '@/stores'
|
import useStore from '@/stores'
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
@ -120,6 +120,8 @@ const loading = ref(false)
|
|||||||
const detail = ref<any>({})
|
const detail = ref<any>({})
|
||||||
const application_list = ref<Array<ApplicationFormType>>([])
|
const application_list = ref<Array<ApplicationFormType>>([])
|
||||||
const application_id_list = ref([])
|
const application_id_list = ref([])
|
||||||
|
const cloneModelId = ref('')
|
||||||
|
|
||||||
const form = ref<any>({
|
const form = ref<any>({
|
||||||
source_url: '',
|
source_url: '',
|
||||||
selector: ''
|
selector: ''
|
||||||
@ -133,7 +135,6 @@ async function submit() {
|
|||||||
if (await BaseFormRef.value?.validate()) {
|
if (await BaseFormRef.value?.validate()) {
|
||||||
await webFormRef.value.validate((valid: any) => {
|
await webFormRef.value.validate((valid: any) => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
loading.value = true
|
|
||||||
const obj =
|
const obj =
|
||||||
detail.value.type === '1'
|
detail.value.type === '1'
|
||||||
? {
|
? {
|
||||||
@ -145,27 +146,49 @@ async function submit() {
|
|||||||
application_id_list: application_id_list.value,
|
application_id_list: application_id_list.value,
|
||||||
...BaseFormRef.value.form
|
...BaseFormRef.value.form
|
||||||
}
|
}
|
||||||
datasetApi
|
|
||||||
.putDataset(id, obj)
|
if (cloneModelId.value !== BaseFormRef.value.form.embedding_mode_id) {
|
||||||
.then((res) => {
|
MsgConfirm(`提示`, `修改知识库向量模型后,需要对知识库重新向量化,是否继续保存?`, {
|
||||||
|
confirmButtonText: '重新向量化',
|
||||||
|
confirmButtonClass: 'primary'
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
datasetApi.putDataset(id, obj, loading).then((res) => {
|
||||||
|
datasetApi.putReEmbeddingDataset(id).then(() => {
|
||||||
MsgSuccess('保存成功')
|
MsgSuccess('保存成功')
|
||||||
loading.value = false
|
|
||||||
})
|
})
|
||||||
.catch(() => {
|
|
||||||
loading.value = false
|
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
.catch(() => {})
|
||||||
|
} else {
|
||||||
|
datasetApi.putDataset(id, obj, loading).then((res) => {
|
||||||
|
MsgSuccess('保存成功')
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function reEmbeddingDataset(row: any) {
|
||||||
|
datasetApi.putReEmbeddingDataset(row.id).then(() => {
|
||||||
|
MsgSuccess('提交成功')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveDataset(data: any) {
|
||||||
|
datasetApi.putDataset(id, data, loading).then((res) => {
|
||||||
|
MsgSuccess('保存成功')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function getDetail() {
|
function getDetail() {
|
||||||
dataset.asyncGetDatasetDetail(id, loading).then((res: any) => {
|
dataset.asyncGetDatasetDetail(id, loading).then((res: any) => {
|
||||||
detail.value = res.data
|
detail.value = res.data
|
||||||
|
cloneModelId.value = res.data?.embedding_mode_id
|
||||||
if (detail.value.type === '1') {
|
if (detail.value.type === '1') {
|
||||||
form.value = res.data.meta
|
form.value = res.data.meta
|
||||||
}
|
}
|
||||||
|
|
||||||
application_id_list.value = res.data?.application_id_list
|
application_id_list.value = res.data?.application_id_list
|
||||||
datasetApi.listUsableApplication(id, loading).then((ok) => {
|
datasetApi.listUsableApplication(id, loading).then((ok) => {
|
||||||
application_list.value = ok.data
|
application_list.value = ok.data
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
:rules="rules"
|
:rules="rules"
|
||||||
label-position="top"
|
label-position="top"
|
||||||
require-asterisk-position="right"
|
require-asterisk-position="right"
|
||||||
|
v-loading="loading"
|
||||||
>
|
>
|
||||||
<el-form-item label="知识库名称" prop="name">
|
<el-form-item label="知识库名称" prop="name">
|
||||||
<el-input
|
<el-input
|
||||||
@ -29,23 +30,69 @@
|
|||||||
<el-form-item label="Embedding模型" prop="embedding_mode_id">
|
<el-form-item label="Embedding模型" prop="embedding_mode_id">
|
||||||
<el-select
|
<el-select
|
||||||
v-model="form.embedding_mode_id"
|
v-model="form.embedding_mode_id"
|
||||||
class="w-full m-2"
|
|
||||||
placeholder="请选择Embedding模型"
|
placeholder="请选择Embedding模型"
|
||||||
|
class="w-full"
|
||||||
|
popper-class="select-model"
|
||||||
|
:clearable="true"
|
||||||
|
>
|
||||||
|
<el-option-group
|
||||||
|
v-for="(value, label) in modelOptions"
|
||||||
|
:key="value"
|
||||||
|
:label="relatedObject(providerOptions, label, 'provider')?.name"
|
||||||
>
|
>
|
||||||
<el-option
|
<el-option
|
||||||
v-for="item in modelOptions"
|
v-for="item in value.filter((v: any) => v.status === 'SUCCESS')"
|
||||||
:key="item.id"
|
:key="item.id"
|
||||||
:label="item.name"
|
:label="item.name"
|
||||||
:value="item.id"
|
:value="item.id"
|
||||||
></el-option>
|
class="flex-between"
|
||||||
|
>
|
||||||
|
<div class="flex">
|
||||||
|
<span
|
||||||
|
v-html="relatedObject(providerOptions, label, 'provider')?.icon"
|
||||||
|
class="model-icon mr-8"
|
||||||
|
></span>
|
||||||
|
<span>{{ item.name }}</span>
|
||||||
|
</div>
|
||||||
|
<el-icon class="check-icon" v-if="item.id === form.embedding_mode_id"
|
||||||
|
><Check
|
||||||
|
/></el-icon>
|
||||||
|
</el-option>
|
||||||
|
<!-- 不可用 -->
|
||||||
|
<el-option
|
||||||
|
v-for="item in value.filter((v: any) => v.status !== 'SUCCESS')"
|
||||||
|
:key="item.id"
|
||||||
|
:label="item.name"
|
||||||
|
:value="item.id"
|
||||||
|
class="flex-between"
|
||||||
|
disabled
|
||||||
|
>
|
||||||
|
<div class="flex">
|
||||||
|
<span
|
||||||
|
v-html="relatedObject(providerOptions, label, 'provider')?.icon"
|
||||||
|
class="model-icon mr-8"
|
||||||
|
></span>
|
||||||
|
<span>{{ item.name }}</span>
|
||||||
|
<span class="danger">{{
|
||||||
|
$t('views.application.applicationForm.form.aiModel.unavailable')
|
||||||
|
}}</span>
|
||||||
|
</div>
|
||||||
|
<el-icon class="check-icon" v-if="item.id === form.embedding_mode_id"
|
||||||
|
><Check
|
||||||
|
/></el-icon>
|
||||||
|
</el-option>
|
||||||
|
</el-option-group>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, reactive, onMounted, onUnmounted, computed, watch } from 'vue'
|
import { ref, reactive, onMounted, onUnmounted, computed, watch } from 'vue'
|
||||||
|
import { groupBy } from 'lodash'
|
||||||
import useStore from '@/stores'
|
import useStore from '@/stores'
|
||||||
import type { datasetData } from '@/api/type/dataset'
|
import type { datasetData } from '@/api/type/dataset'
|
||||||
|
import { relatedObject } from '@/utils/utils'
|
||||||
|
import type { Provider } from '@/api/type/model'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
data: {
|
data: {
|
||||||
@ -65,8 +112,11 @@ const rules = reactive({
|
|||||||
desc: [{ required: true, message: '请输入知识库描述', trigger: 'blur' }],
|
desc: [{ required: true, message: '请输入知识库描述', trigger: 'blur' }],
|
||||||
embedding_mode_id: [{ required: true, message: '请输入Embedding模型', trigger: 'change' }]
|
embedding_mode_id: [{ required: true, message: '请输入Embedding模型', trigger: 'change' }]
|
||||||
})
|
})
|
||||||
|
|
||||||
const FormRef = ref()
|
const FormRef = ref()
|
||||||
const modelOptions = ref([])
|
const loading = ref(false)
|
||||||
|
const modelOptions = ref<any>([])
|
||||||
|
const providerOptions = ref<Array<Provider>>([])
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.data,
|
() => props.data,
|
||||||
@ -91,12 +141,33 @@ function validate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getModel() {
|
function getModel() {
|
||||||
model.asyncGetModel({ model_type: 'EMBEDDING' }).then((res: any) => {
|
loading.value = true
|
||||||
modelOptions.value = res?.data
|
model
|
||||||
|
.asyncGetModel({ model_type: 'EMBEDDING' })
|
||||||
|
.then((res: any) => {
|
||||||
|
modelOptions.value = groupBy(res?.data, 'provider')
|
||||||
|
loading.value = false
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
loading.value = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function getProvider() {
|
||||||
|
loading.value = true
|
||||||
|
model
|
||||||
|
.asyncGetProvider()
|
||||||
|
.then((res: any) => {
|
||||||
|
providerOptions.value = res?.data
|
||||||
|
loading.value = false
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
loading.value = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
getProvider()
|
||||||
getModel()
|
getModel()
|
||||||
})
|
})
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user