149 lines
4.6 KiB
TypeScript
149 lines
4.6 KiB
TypeScript
import { request } from './request'
|
|
import type {
|
|
AiCallLog,
|
|
AiCatalogModel,
|
|
AiChannel,
|
|
AiContentLog,
|
|
AiKey,
|
|
AiModel,
|
|
AiModelBlacklistItem,
|
|
AiModelCacheItem,
|
|
AiSettings,
|
|
} from '@/types/api'
|
|
|
|
// ---- 网关密钥 ----
|
|
|
|
export function listAiKeys(): Promise<AiKey[]> {
|
|
return request<{ items: AiKey[] }>('/ai-keys').then((r) => r.items)
|
|
}
|
|
|
|
export interface CreateAiKeyRequest {
|
|
name: string
|
|
value?: string
|
|
group?: string
|
|
/** 模型白名单;缺省/空 = 不限 */
|
|
models?: string[]
|
|
}
|
|
|
|
/** 创建密钥;key 为明文,仅本次响应返回 */
|
|
export function createAiKey(body: CreateAiKeyRequest): Promise<{ key: string; item: AiKey }> {
|
|
return request('/ai-keys', { method: 'POST', body })
|
|
}
|
|
|
|
export function updateAiKey(
|
|
id: number,
|
|
body: { name?: string; enabled?: boolean; group?: string; models?: string[] },
|
|
): Promise<void> {
|
|
return request(`/ai-keys/${id}`, { method: 'PUT', body })
|
|
}
|
|
|
|
export function deleteAiKey(id: number): Promise<void> {
|
|
return request(`/ai-keys/${id}`, { method: 'DELETE' })
|
|
}
|
|
|
|
/** 设置密钥内容日志窗口:0 关闭,>0 从现在起开启 N 小时(上限 168 = 7 天),返回最新密钥 */
|
|
export function updateAiKeyContentLog(id: number, hours: number): Promise<AiKey> {
|
|
return request(`/ai-keys/${id}/content-log`, { method: 'PUT', body: { hours } })
|
|
}
|
|
|
|
// ---- 渠道(号池)----
|
|
|
|
export function listAiChannels(): Promise<AiChannel[]> {
|
|
return request<{ items: AiChannel[] }>('/ai-channels').then((r) => r.items)
|
|
}
|
|
|
|
export interface AiChannelInput {
|
|
ociConfigId?: number
|
|
region?: string
|
|
name?: string
|
|
group?: string
|
|
enabled?: boolean
|
|
priority?: number
|
|
weight?: number
|
|
}
|
|
|
|
export function createAiChannel(body: AiChannelInput): Promise<AiChannel> {
|
|
return request('/ai-channels', { method: 'POST', body })
|
|
}
|
|
|
|
export function updateAiChannel(id: number, body: AiChannelInput): Promise<void> {
|
|
return request(`/ai-channels/${id}`, { method: 'PUT', body })
|
|
}
|
|
|
|
export function deleteAiChannel(id: number): Promise<void> {
|
|
return request(`/ai-channels/${id}`, { method: 'DELETE' })
|
|
}
|
|
|
|
export function probeAiChannel(id: number): Promise<AiChannel> {
|
|
return request(`/ai-channels/${id}/probe`, { method: 'POST' })
|
|
}
|
|
|
|
export function syncAiChannelModels(id: number): Promise<AiModelCacheItem[]> {
|
|
return request<{ items: AiModelCacheItem[] }>(`/ai-channels/${id}/sync-models`, {
|
|
method: 'POST',
|
|
}).then((r) => r.items)
|
|
}
|
|
|
|
export function listAiChannelModels(id: number): Promise<AiModelCacheItem[]> {
|
|
return request<{ items: AiModelCacheItem[] }>(`/ai-channels/${id}/models`).then((r) => r.items)
|
|
}
|
|
|
|
/** 单模型 max_tokens=16 试调;通过即设为该渠道探测验证模型并按需置渠道可用 */
|
|
export function testAiChannelModel(id: number, model: string): Promise<AiChannel> {
|
|
return request(`/ai-channels/${id}/test-model`, { method: 'POST', body: { model } })
|
|
}
|
|
|
|
// ---- 聚合模型与调用日志 ----
|
|
|
|
export function listAiModels(): Promise<AiModel[]> {
|
|
return request<{ items: AiModel[] }>('/ai-models').then((r) => r.items)
|
|
}
|
|
|
|
/** 聚合模型目录(含能力,启用渠道去重;不受「过滤弃用」影响),黑名单添加弹窗用 */
|
|
export function listAiModelCatalog(): Promise<AiCatalogModel[]> {
|
|
return request<{ items: AiCatalogModel[] }>('/ai-model-catalog').then((r) => r.items)
|
|
}
|
|
|
|
// ---- 网关全局设置 ----
|
|
|
|
export function getAiSettings(): Promise<AiSettings> {
|
|
return request<AiSettings>('/ai-settings')
|
|
}
|
|
|
|
export function updateAiSettings(body: AiSettings): Promise<AiSettings> {
|
|
return request<AiSettings>('/ai-settings', { method: 'PUT', body })
|
|
}
|
|
|
|
// ---- 模型黑名单 ----
|
|
|
|
export function listAiBlacklist(): Promise<AiModelBlacklistItem[]> {
|
|
return request<{ items: AiModelBlacklistItem[] }>('/ai-blacklist').then((r) => r.items)
|
|
}
|
|
|
|
/** 拉黑模型:删除全部渠道缓存中的同名条目,后续同步 / 探测均过滤 */
|
|
export function addAiBlacklist(name: string): Promise<void> {
|
|
return request('/ai-blacklist', { method: 'POST', body: { name } })
|
|
}
|
|
|
|
/** 移出黑名单:缓存不回填,重新同步 / 探测后恢复入池 */
|
|
export function removeAiBlacklist(id: number): Promise<void> {
|
|
return request(`/ai-blacklist/${id}`, { method: 'DELETE' })
|
|
}
|
|
|
|
export function listAiCallLogs(params: {
|
|
page: number
|
|
size: number
|
|
}): Promise<{ items: AiCallLog[]; total: number }> {
|
|
return request('/ai-logs', { query: params })
|
|
}
|
|
|
|
/** 内容日志(红线例外);keyId / callLogId 可选过滤 */
|
|
export function listAiContentLogs(params: {
|
|
page: number
|
|
size: number
|
|
keyId?: number
|
|
callLogId?: number
|
|
}): Promise<{ items: AiContentLog[]; total: number }> {
|
|
return request('/ai-content-logs', { query: params })
|
|
}
|