mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
feat: default model
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
// import type { Payment } from '@/components/columns'
|
// import type { Payment } from '@/components/columns'
|
||||||
import { h, computed, ref, provide, watch } from 'vue'
|
import { h, computed, ref, provide, watch, type ComputedRef, reactive } from 'vue'
|
||||||
import CreateModel from '@/components/CreateModel/index.vue'
|
import CreateModel from '@/components/CreateModel/index.vue'
|
||||||
import { useQuery, useMutation, useQueryCache } from '@pinia/colada'
|
import { useQuery, useMutation, useQueryCache } from '@pinia/colada'
|
||||||
import {
|
import {
|
||||||
@@ -10,16 +10,14 @@ import {
|
|||||||
PaginationEllipsis,
|
PaginationEllipsis,
|
||||||
PaginationItem,
|
PaginationItem,
|
||||||
PaginationNext,
|
PaginationNext,
|
||||||
PaginationPrevious
|
PaginationPrevious,
|
||||||
|
Checkbox
|
||||||
} from '@memoh/ui'
|
} from '@memoh/ui'
|
||||||
import DataTable from '@/components/DataTable/index.vue'
|
import DataTable from '@/components/DataTable/index.vue'
|
||||||
import request from '@/utils/request'
|
import request from '@/utils/request'
|
||||||
import { type ColumnDef } from '@tanstack/vue-table'
|
import { type ColumnDef } from '@tanstack/vue-table'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
interface ModelType {
|
interface ModelType {
|
||||||
apiKey: string,
|
apiKey: string,
|
||||||
baseUrl: string,
|
baseUrl: string,
|
||||||
@@ -27,7 +25,10 @@ interface ModelType {
|
|||||||
modelId: string,
|
modelId: string,
|
||||||
name: string,
|
name: string,
|
||||||
type: 'chat' | 'embedding',
|
type: 'chat' | 'embedding',
|
||||||
id: string
|
id: string,
|
||||||
|
defaultChatModel: boolean,
|
||||||
|
defaultEmbeddingModel: boolean,
|
||||||
|
defaultSummaryModel: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const openDialogModel = ref(false)
|
const openDialogModel = ref(false)
|
||||||
@@ -60,7 +61,48 @@ const {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const columns: ColumnDef<ModelType>[] = [
|
const {
|
||||||
|
mutate: setDefaultModel,
|
||||||
|
} = useMutation({
|
||||||
|
mutation: (payload: { id: string, type: string }) =>
|
||||||
|
request({
|
||||||
|
url: `/model/${payload.type}/default?userId=${payload.id}`,
|
||||||
|
method: 'get'
|
||||||
|
}),
|
||||||
|
onSettled: () => {
|
||||||
|
cacheQuery.invalidateQueries({
|
||||||
|
key: ['models']
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
const renderCheckDefault = () => {
|
||||||
|
return [...[{ title: 'Chat', key: 'chat', type: 'defaultChatModel' },
|
||||||
|
{ title: 'Summary', key: 'summary', type: 'defaultSummaryModel' },
|
||||||
|
{ title: 'Embedding', key: 'embedding', type: 'defaultEmbeddingModel' }].map((modelSetting) => (
|
||||||
|
{
|
||||||
|
accessorKey: `${modelSetting.key}`,
|
||||||
|
header: () => h('div', { class: 'text-left' }, modelSetting.title),
|
||||||
|
cell({ row }) {
|
||||||
|
return h(Checkbox, {
|
||||||
|
state: row.original[modelSetting.type as 'defaultChatModel' | 'defaultSummaryModel' | 'defaultEmbeddingModel'],
|
||||||
|
disabled: row.original[modelSetting.type as 'defaultChatModel' | 'defaultSummaryModel' | 'defaultEmbeddingModel'] ? true : false,
|
||||||
|
'onUpdate:modelValue'(val) {
|
||||||
|
row.original[modelSetting.type as 'defaultChatModel' | 'defaultSummaryModel' | 'defaultEmbeddingModel'] = val as boolean
|
||||||
|
setDefaultModel({
|
||||||
|
id: row.original.id,
|
||||||
|
type: modelSetting.key
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} as ColumnDef<ModelType>
|
||||||
|
))]
|
||||||
|
}
|
||||||
|
const checkDefaultModel=ref(renderCheckDefault())
|
||||||
|
|
||||||
|
const columns: ComputedRef<ColumnDef<ModelType>[]> = computed(() => [
|
||||||
{
|
{
|
||||||
accessorKey: 'modelId',
|
accessorKey: 'modelId',
|
||||||
header: () => h('div', { class: 'text-left py-4' }, 'Name'),
|
header: () => h('div', { class: 'text-left py-4' }, 'Name'),
|
||||||
@@ -88,10 +130,14 @@ const columns: ColumnDef<ModelType>[] = [
|
|||||||
accessorKey: 'type',
|
accessorKey: 'type',
|
||||||
header: () => h('div', { class: 'text-left' }, 'Type'),
|
header: () => h('div', { class: 'text-left' }, 'Type'),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
...checkDefaultModel.value
|
||||||
|
,
|
||||||
{
|
{
|
||||||
accessorKey: 'control',
|
accessorKey: 'control',
|
||||||
header: () => h('div', { class: 'text-center' }, '操作'),
|
header: () => h('div', { class: 'text-center' }, '操作'),
|
||||||
cell: ({ row }) => h('div', { class: ' w-full flex justify-around' }, [h(Button, {
|
cell: ({ row }) => h('div', { class: ' w-full flex justify-center gap-4' }, [h(Button, {
|
||||||
'onClick': () => {
|
'onClick': () => {
|
||||||
editModelInfo.value = row.original
|
editModelInfo.value = row.original
|
||||||
openDialogModel.value = true
|
openDialogModel.value = true
|
||||||
@@ -99,19 +145,39 @@ const columns: ColumnDef<ModelType>[] = [
|
|||||||
}, () => '编辑'), h(Button, {
|
}, () => '编辑'), h(Button, {
|
||||||
variant: 'destructive', onClick() {
|
variant: 'destructive', onClick() {
|
||||||
deleteModel(row.original.id)
|
deleteModel(row.original.id)
|
||||||
|
|
||||||
}
|
}
|
||||||
}, () => '删除')])
|
}, () => '删除')])
|
||||||
}
|
}
|
||||||
]
|
])
|
||||||
|
|
||||||
const { data: modelData } = useQuery({
|
const { data: modelData } = useQuery({
|
||||||
key: ['models'],
|
key: ['models'],
|
||||||
query() {
|
async query() {
|
||||||
return request({
|
|
||||||
|
const fetchModeData = await request({
|
||||||
url: '/model'
|
url: '/model'
|
||||||
})
|
})
|
||||||
|
const defaultModel = await request({
|
||||||
|
url: '/settings'
|
||||||
|
})
|
||||||
|
const defaultModelValue = defaultModel?.data?.data
|
||||||
|
fetchModeData.data.items = fetchModeData.data.items.map((item: { model: ModelType, id: 'string' }) => ({
|
||||||
|
id: item.id,
|
||||||
|
model: {
|
||||||
|
...item.model,
|
||||||
|
defaultChatModel: defaultModelValue?.defaultChatModel === item.id ? true : false,
|
||||||
|
defaultEmbeddingModel: defaultModelValue?.defaultEmbeddingModel === item.id ? true : false,
|
||||||
|
defaultSummaryModel: defaultModelValue?.defaultSummaryModel === item.id ? true : false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}))
|
||||||
|
|
||||||
|
return fetchModeData
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(modelData, () => {
|
||||||
|
checkDefaultModel.value=renderCheckDefault()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,46 @@
|
|||||||
<template>
|
<template>
|
||||||
<section>
|
<section>
|
||||||
<h1>Settings</h1>
|
<section class="max-w-187 m-auto">
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle class="text-2xl font-semibold tracking-tight">
|
||||||
|
Settings
|
||||||
|
</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Model Settings
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<!-- <CardHeader>
|
||||||
|
<CardTitle>
|
||||||
|
Setting
|
||||||
|
</CardTitle>
|
||||||
|
</CardHeader> -->
|
||||||
|
</Card>
|
||||||
|
</section>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { useQuery } from '@pinia/colada'
|
||||||
|
import request from '@/utils/request'
|
||||||
|
import { watch } from 'vue'
|
||||||
|
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardDescription,
|
||||||
|
CardHeader,
|
||||||
|
CardTitle
|
||||||
|
} from '@memoh/ui'
|
||||||
|
|
||||||
|
const { data: settingData } = useQuery({
|
||||||
|
key: ['Setting'],
|
||||||
|
query: () => request({
|
||||||
|
url: '/settings/',
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(settingData, () => {
|
||||||
|
console.log(settingData.value?.data)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||||
"types": ["vite/client"],
|
"types": ["vite/client"],
|
||||||
|
"lib": ["DOM","ESNext"],
|
||||||
/* Linting */
|
/* Linting */
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
|
|||||||
Reference in New Issue
Block a user