2026-05-06 19:46:12 +08:00
|
|
|
|
import request from '/@/utils/request';
|
|
|
|
|
|
|
|
|
|
|
|
export interface ModelModuleListParams {
|
|
|
|
|
|
pageNum?: number;
|
|
|
|
|
|
pageSize?: number;
|
2026-05-11 13:48:20 +08:00
|
|
|
|
modelName?: string;
|
2026-05-12 16:43:46 +08:00
|
|
|
|
modelType?: number | string;
|
2026-05-06 19:46:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface ModelFormItem {
|
|
|
|
|
|
field: string;
|
|
|
|
|
|
label: string;
|
|
|
|
|
|
required: boolean;
|
|
|
|
|
|
type: 'input' | 'number' | 'textarea' | 'switch' | string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-11 13:48:20 +08:00
|
|
|
|
export interface ModelFormEntry {
|
|
|
|
|
|
key: string;
|
|
|
|
|
|
value: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 模型类型(listType 接口项,字段名以后端为准,前端做兼容解析) */
|
|
|
|
|
|
export interface ModelTypeListItem {
|
|
|
|
|
|
id?: number | string;
|
|
|
|
|
|
typeId?: number | string;
|
2026-05-12 16:43:46 +08:00
|
|
|
|
modelType?: number | string;
|
2026-05-11 13:48:20 +08:00
|
|
|
|
name?: string;
|
|
|
|
|
|
typeName?: string;
|
|
|
|
|
|
label?: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** listType 标准返回:data.type 为 Record<id, 名称>,如 { "1": "推理模型", "2": "图片模型" } */
|
|
|
|
|
|
export function normalizeModelTypeOptions(res: { data?: unknown }): Array<{ id: number | string; label: string }> {
|
|
|
|
|
|
const data = res?.data as { type?: Record<string, string> } | undefined;
|
|
|
|
|
|
const typeMap = data?.type;
|
|
|
|
|
|
if (typeMap && typeof typeMap === 'object' && !Array.isArray(typeMap)) {
|
|
|
|
|
|
return Object.entries(typeMap)
|
|
|
|
|
|
.map(([key, label]) => {
|
|
|
|
|
|
const n = Number(key);
|
|
|
|
|
|
const id = Number.isNaN(n) ? key : n;
|
|
|
|
|
|
return { id, label: String(label ?? '') };
|
|
|
|
|
|
})
|
|
|
|
|
|
.sort((a, b) => {
|
|
|
|
|
|
const na = Number(a.id);
|
|
|
|
|
|
const nb = Number(b.id);
|
|
|
|
|
|
if (!Number.isNaN(na) && !Number.isNaN(nb)) {
|
|
|
|
|
|
return na - nb;
|
|
|
|
|
|
}
|
|
|
|
|
|
return String(a.id).localeCompare(String(b.id));
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 兼容旧结构:data 为数组或 data.list */
|
|
|
|
|
|
const raw = res?.data;
|
|
|
|
|
|
const arr: ModelTypeListItem[] = Array.isArray(raw) ? raw : ((raw as { list?: ModelTypeListItem[] })?.list ?? []);
|
|
|
|
|
|
return arr
|
|
|
|
|
|
.map((item) => {
|
2026-05-12 16:43:46 +08:00
|
|
|
|
const id = item.id ?? item.typeId ?? item.modelType;
|
2026-05-11 13:48:20 +08:00
|
|
|
|
const label = item.name ?? item.typeName ?? item.label ?? (id != null && id !== '' ? String(id) : '');
|
|
|
|
|
|
return { id: id as number | string, label: label || String(id) };
|
|
|
|
|
|
})
|
|
|
|
|
|
.filter((x) => x.id !== undefined && x.id !== null && x.id !== '');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-06 19:46:12 +08:00
|
|
|
|
export interface ModelModuleItem {
|
|
|
|
|
|
id: number | string;
|
|
|
|
|
|
tenantId?: number;
|
|
|
|
|
|
creator?: string;
|
|
|
|
|
|
createdAt?: string;
|
|
|
|
|
|
updater?: string;
|
|
|
|
|
|
updatedAt?: string;
|
|
|
|
|
|
deletedAt?: string | null;
|
|
|
|
|
|
isDeleted?: boolean;
|
|
|
|
|
|
modelName: string;
|
2026-05-11 13:48:20 +08:00
|
|
|
|
/** 模型类型 ID,与 listType 返回项对应 */
|
2026-05-12 16:43:46 +08:00
|
|
|
|
modelType?: number | string;
|
2026-05-06 19:46:12 +08:00
|
|
|
|
baseUrl: string;
|
2026-05-11 13:48:20 +08:00
|
|
|
|
route?: string;
|
2026-05-06 19:46:12 +08:00
|
|
|
|
httpMethod: string;
|
|
|
|
|
|
apiKey?: string;
|
2026-05-11 13:48:20 +08:00
|
|
|
|
isPrivate?: number;
|
|
|
|
|
|
isChatModel?: number;
|
2026-05-11 20:01:03 +08:00
|
|
|
|
/** 会话开关状态(列表接口返回,0 关 1 开;会话开关接口就绪后生效) */
|
|
|
|
|
|
chatSessionEnabled?: number;
|
2026-05-06 19:46:12 +08:00
|
|
|
|
enabled: number;
|
|
|
|
|
|
maxConcurrency: number;
|
|
|
|
|
|
queueLimit: number;
|
2026-05-11 13:48:20 +08:00
|
|
|
|
timeoutMs?: number;
|
|
|
|
|
|
timeoutSeconds?: number;
|
|
|
|
|
|
expectedSeconds?: number;
|
2026-05-06 19:46:12 +08:00
|
|
|
|
retryTimes: number;
|
|
|
|
|
|
retryQueueMaxSeconds: number;
|
|
|
|
|
|
autoCleanSeconds: number;
|
|
|
|
|
|
remark?: string;
|
2026-05-11 13:48:20 +08:00
|
|
|
|
headMsg?: string;
|
|
|
|
|
|
form?: ModelFormEntry[] | Record<string, { value: string }>;
|
|
|
|
|
|
requestMapping?: Record<string, unknown>;
|
|
|
|
|
|
responseMapping?: Record<string, unknown>;
|
2026-05-06 19:46:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface ModelModuleListResponse {
|
|
|
|
|
|
code: number;
|
|
|
|
|
|
message: string;
|
|
|
|
|
|
data: {
|
|
|
|
|
|
list: ModelModuleItem[];
|
|
|
|
|
|
total: number;
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface CreateModelParams {
|
|
|
|
|
|
modelName: string;
|
2026-05-11 13:48:20 +08:00
|
|
|
|
/** 与 listType 返回的类型 id 一致,可能为数字或字符串 */
|
2026-05-12 16:43:46 +08:00
|
|
|
|
modelType: number | string;
|
2026-05-06 19:46:12 +08:00
|
|
|
|
baseUrl: string;
|
2026-05-11 13:48:20 +08:00
|
|
|
|
httpMethod?: string;
|
2026-05-06 19:46:12 +08:00
|
|
|
|
headMsg?: string;
|
2026-05-11 13:48:20 +08:00
|
|
|
|
isPrivate: number;
|
2026-05-06 19:46:12 +08:00
|
|
|
|
enabled: number;
|
2026-05-11 13:48:20 +08:00
|
|
|
|
isChatModel: number;
|
|
|
|
|
|
apiKey?: string;
|
|
|
|
|
|
form: ModelFormEntry[];
|
|
|
|
|
|
requestMapping?: Record<string, unknown>;
|
|
|
|
|
|
responseMapping?: Record<string, unknown>;
|
|
|
|
|
|
maxConcurrency?: number;
|
|
|
|
|
|
queueLimit?: number;
|
2026-05-06 19:46:12 +08:00
|
|
|
|
timeoutSeconds: number;
|
|
|
|
|
|
expectedSeconds: number;
|
2026-05-11 13:48:20 +08:00
|
|
|
|
retryTimes?: number;
|
2026-05-06 19:46:12 +08:00
|
|
|
|
retryQueueMaxSeconds: number;
|
|
|
|
|
|
autoCleanSeconds: number;
|
|
|
|
|
|
remark?: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface ModelConfigTypeItem {
|
|
|
|
|
|
id: number | string;
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
form: ModelFormItem[];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface ModelConfigGroup {
|
|
|
|
|
|
typeId: number;
|
|
|
|
|
|
type: string;
|
|
|
|
|
|
items: ModelConfigTypeItem[];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface ModelConfigResponse {
|
|
|
|
|
|
code: number;
|
|
|
|
|
|
message: string;
|
|
|
|
|
|
data: ModelConfigGroup[];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取模型列表
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function getModelModuleList(params?: ModelModuleListParams) {
|
|
|
|
|
|
return request({
|
|
|
|
|
|
url: '/model-gateway/model/listModel',
|
|
|
|
|
|
method: 'get',
|
|
|
|
|
|
params,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-11 13:48:20 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 获取模型类型列表(用于下拉与列表回显)
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function getModelTypeList() {
|
|
|
|
|
|
return request({
|
|
|
|
|
|
url: '/model-gateway/model/listType',
|
|
|
|
|
|
method: 'get',
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-06 19:46:12 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 新增模型配置
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function addModelModule(data: CreateModelParams) {
|
|
|
|
|
|
return request({
|
|
|
|
|
|
url: '/model-gateway/model/createModel',
|
|
|
|
|
|
method: 'post',
|
|
|
|
|
|
data,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 修改模型配置
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function updateModelModule(data: Partial<CreateModelParams> & { id: number | string }) {
|
|
|
|
|
|
return request({
|
|
|
|
|
|
url: '/model-gateway/model/updateModel',
|
2026-05-11 13:48:20 +08:00
|
|
|
|
method: 'put',
|
2026-05-06 19:46:12 +08:00
|
|
|
|
data,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 删除模型配置
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function deleteModelModule(id: number | string) {
|
|
|
|
|
|
return request({
|
|
|
|
|
|
url: '/model-gateway/model/deleteModel',
|
2026-05-11 13:48:20 +08:00
|
|
|
|
method: 'delete',
|
2026-05-06 19:46:12 +08:00
|
|
|
|
data: { id },
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2026-05-11 13:48:20 +08:00
|
|
|
|
* 获取单条模型配置详情(编辑用,需传 id)
|
2026-05-06 19:46:12 +08:00
|
|
|
|
*/
|
2026-05-11 13:48:20 +08:00
|
|
|
|
export function getModelModuleDetail(id: number | string) {
|
2026-05-06 19:46:12 +08:00
|
|
|
|
return request({
|
|
|
|
|
|
url: '/model-gateway/model/getModel',
|
|
|
|
|
|
method: 'get',
|
2026-05-11 13:48:20 +08:00
|
|
|
|
params: { id },
|
2026-05-06 19:46:12 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
2026-05-11 20:01:03 +08:00
|
|
|
|
|
2026-05-11 21:06:35 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 更新模型会话开关状态
|
|
|
|
|
|
*/
|
2026-05-11 22:40:58 +08:00
|
|
|
|
export function updateChatModel(data: { id: number | string; isChatModel: 0 | 1 }) {
|
2026-05-11 21:06:35 +08:00
|
|
|
|
return request({
|
|
|
|
|
|
url: '/model-gateway/model/updateChatModel',
|
|
|
|
|
|
method: 'post',
|
|
|
|
|
|
data,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2026-05-11 22:40:58 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取当前会话模型
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function getIsChatModel() {
|
|
|
|
|
|
return request({
|
|
|
|
|
|
url: '/model-gateway/model/getIsChatModel',
|
|
|
|
|
|
method: 'get',
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|