186 lines
5.2 KiB
TypeScript
186 lines
5.2 KiB
TypeScript
import type { AiModel } from "./types"
|
|
import { mockResponse, type PaginatedResponse, type PaginationParams } from "./client"
|
|
|
|
// 模拟AI模型数据
|
|
const mockAiModels: AiModel[] = [
|
|
{
|
|
id: "AI001",
|
|
name: "洛天依语音合成模型V1",
|
|
version: "1.0.0",
|
|
type: "语音合成",
|
|
status: "已发布",
|
|
createdAt: "2023-01-15",
|
|
updatedAt: "2023-01-15",
|
|
description: "洛天依的基础语音合成模型,支持基本的歌声合成功能。",
|
|
},
|
|
{
|
|
id: "AI002",
|
|
name: "洛天依对话模型V1",
|
|
version: "1.0.0",
|
|
type: "对话模型",
|
|
status: "已发布",
|
|
createdAt: "2023-03-20",
|
|
updatedAt: "2023-03-20",
|
|
description: "洛天依的基础对话模型,支持简单的问答交互。",
|
|
},
|
|
{
|
|
id: "AI003",
|
|
name: "洛天依语音合成模型V2",
|
|
version: "2.0.0",
|
|
type: "语音合成",
|
|
status: "已发布",
|
|
createdAt: "2023-06-10",
|
|
updatedAt: "2023-06-10",
|
|
description: "洛天依的进阶语音合成模型,支持更自然的歌声合成和情感表达。",
|
|
},
|
|
{
|
|
id: "AI004",
|
|
name: "洛天依对话模型V2",
|
|
version: "2.0.0",
|
|
type: "对话模型",
|
|
status: "已发布",
|
|
createdAt: "2023-09-05",
|
|
updatedAt: "2023-09-05",
|
|
description: "洛天依的进阶对话模型,支持更复杂的对话和情感理解。",
|
|
},
|
|
{
|
|
id: "AI005",
|
|
name: "洛天依多模态模型V1",
|
|
version: "1.0.0",
|
|
type: "多模态模型",
|
|
status: "开发中",
|
|
createdAt: "2023-12-01",
|
|
updatedAt: "2023-12-01",
|
|
description: "洛天依的多模态模型,支持图像识别和生成,以及与语音、文本的交互。",
|
|
},
|
|
]
|
|
|
|
// 获取AI模型列表
|
|
export const getAiModels = async (params?: PaginationParams): Promise<PaginatedResponse<AiModel>> => {
|
|
let filteredModels = [...mockAiModels]
|
|
|
|
// 搜索过滤
|
|
if (params?.search) {
|
|
const search = params.search.toLowerCase()
|
|
filteredModels = filteredModels.filter(
|
|
(model) =>
|
|
model.name.toLowerCase().includes(search) ||
|
|
model.id.toLowerCase().includes(search) ||
|
|
model.type.toLowerCase().includes(search),
|
|
)
|
|
}
|
|
|
|
// 排序
|
|
if (params?.sortBy) {
|
|
filteredModels.sort((a: any, b: any) => {
|
|
const aValue = a[params.sortBy!]
|
|
const bValue = b[params.sortBy!]
|
|
|
|
if (typeof aValue === "string" && typeof bValue === "string") {
|
|
return params.sortOrder === "desc" ? bValue.localeCompare(aValue) : aValue.localeCompare(bValue)
|
|
}
|
|
|
|
return params.sortOrder === "desc" ? bValue - aValue : aValue - bValue
|
|
})
|
|
}
|
|
|
|
// 分页
|
|
const page = params?.page || 1
|
|
const pageSize = params?.pageSize || 10
|
|
const startIndex = (page - 1) * pageSize
|
|
const paginatedModels = filteredModels.slice(startIndex, startIndex + pageSize)
|
|
|
|
return mockResponse({
|
|
items: paginatedModels,
|
|
total: filteredModels.length,
|
|
page,
|
|
pageSize,
|
|
totalPages: Math.ceil(filteredModels.length / pageSize),
|
|
})
|
|
}
|
|
|
|
// 获取单个AI模型
|
|
export const getAiModel = async (id: string): Promise<AiModel> => {
|
|
const model = mockAiModels.find((model) => model.id === id)
|
|
|
|
if (!model) {
|
|
return mockResponse({} as AiModel, "AI模型不存在")
|
|
}
|
|
|
|
return mockResponse(model)
|
|
}
|
|
|
|
// 创建AI模型
|
|
export const createAiModel = async (modelData: Partial<AiModel>): Promise<AiModel> => {
|
|
// 生成新的AI模型ID
|
|
const modelId = "AI" + String(mockAiModels.length + 1).padStart(3, "0")
|
|
|
|
const now = new Date().toISOString().split("T")[0]
|
|
|
|
const newModel: AiModel = {
|
|
id: modelId,
|
|
name: modelData.name || "",
|
|
version: modelData.version || "1.0.0",
|
|
type: modelData.type || "",
|
|
status: modelData.status || "开发中",
|
|
createdAt: now,
|
|
updatedAt: now,
|
|
description: modelData.description || "",
|
|
}
|
|
|
|
mockAiModels.push(newModel)
|
|
|
|
return mockResponse(newModel)
|
|
}
|
|
|
|
// 更新AI模型
|
|
export const updateAiModel = async (id: string, modelData: Partial<AiModel>): Promise<AiModel> => {
|
|
const modelIndex = mockAiModels.findIndex((model) => model.id === id)
|
|
|
|
if (modelIndex === -1) {
|
|
return mockResponse({} as AiModel, "AI模型不存在")
|
|
}
|
|
|
|
const updatedModel = {
|
|
...mockAiModels[modelIndex],
|
|
...modelData,
|
|
updatedAt: new Date().toISOString().split("T")[0],
|
|
}
|
|
|
|
mockAiModels[modelIndex] = updatedModel
|
|
|
|
return mockResponse(updatedModel)
|
|
}
|
|
|
|
// 删除AI模型
|
|
export const deleteAiModel = async (id: string): Promise<boolean> => {
|
|
const modelIndex = mockAiModels.findIndex((model) => model.id === id)
|
|
|
|
if (modelIndex === -1) {
|
|
return mockResponse(false, "AI模型不存在")
|
|
}
|
|
|
|
// 已发布的AI模型不能删除
|
|
if (mockAiModels[modelIndex].status === "已发布") {
|
|
return mockResponse(false, "已发布的AI模型不能删除")
|
|
}
|
|
|
|
mockAiModels.splice(modelIndex, 1)
|
|
|
|
return mockResponse(true)
|
|
}
|
|
|
|
// 发布AI模型
|
|
export const publishAiModel = async (id: string): Promise<AiModel> => {
|
|
const modelIndex = mockAiModels.findIndex((model) => model.id === id)
|
|
|
|
if (modelIndex === -1) {
|
|
return mockResponse({} as AiModel, "AI模型不存在")
|
|
}
|
|
|
|
mockAiModels[modelIndex].status = "已发布"
|
|
mockAiModels[modelIndex].updatedAt = new Date().toISOString().split("T")[0]
|
|
|
|
return mockResponse(mockAiModels[modelIndex])
|
|
}
|