mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-06-03 06:41:54 +08:00
feat(model): 增加模型管理和测试功能
- 新增模型删除功能 - 实现模型测试连接功能 - 优化模型选择器组件 - 更新模型相关API和数据库操作
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { create } from 'zustand'
|
||||
import { devtools } from 'zustand/middleware'
|
||||
import { fetchModels, addModel, fetchEnableModels } from '@/services/model.ts'
|
||||
import { fetchModels, addModel, fetchEnableModels, fetchEnableModelById, deleteModelById } from '@/services/model.ts'
|
||||
|
||||
interface IModel {
|
||||
id: string
|
||||
@@ -18,8 +18,10 @@ interface ModelStore {
|
||||
selectedModel: string
|
||||
loadModels: (providerId: string) => Promise<void>
|
||||
loadEnabledModels: () => Promise<void>
|
||||
loadModelsById : (providerId: string) => Promise<void>
|
||||
addNewModel: (providerId: string, modelId: string) => Promise<void>
|
||||
setSelectedModel: (modelId: string) => void
|
||||
deleteModel: (modelId: number) => Promise<void>
|
||||
clearModels: () => void
|
||||
}
|
||||
|
||||
@@ -45,6 +47,10 @@ export const useModelStore = create<ModelStore>()(
|
||||
console.error('加载模型出错', error)
|
||||
}
|
||||
},
|
||||
|
||||
deleteModel: async (modelId: number) => {
|
||||
await deleteModelById( modelId)
|
||||
},
|
||||
// 加载模型列表
|
||||
loadModels: async (providerId: string) => {
|
||||
try {
|
||||
@@ -65,7 +71,13 @@ export const useModelStore = create<ModelStore>()(
|
||||
set({ loading: false })
|
||||
}
|
||||
},
|
||||
|
||||
loadModelsById: async (providerId: string)=>{
|
||||
const models = await fetchEnableModelById(providerId)
|
||||
if (models.data.code === 0) {
|
||||
console.log('模型列表加载成功:', models.data)
|
||||
return models.data.data
|
||||
}
|
||||
},
|
||||
// 新增模型
|
||||
addNewModel: async (providerId: string, modelId: string) => {
|
||||
try {
|
||||
|
||||
@@ -66,7 +66,9 @@ export const useProviderStore = create<ProviderStore>((set, get) => ({
|
||||
if (res.data.code === 0) {
|
||||
const item = res.data.data
|
||||
console.log('Provider ', item)
|
||||
|
||||
await get().fetchProviderList()
|
||||
return item
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching provider:', error)
|
||||
|
||||
Reference in New Issue
Block a user