优化
This commit is contained in:
@@ -1,61 +1,64 @@
|
||||
/**
|
||||
* AI模型配置 API 服务
|
||||
* 用于获取模型积分消耗配置
|
||||
* AI第三方服务配置 API 服务
|
||||
* 用于获取服务积分消耗配置
|
||||
*/
|
||||
|
||||
import http from './http'
|
||||
|
||||
const BASE_URL = '/webApi/api/tik/ai-model-config'
|
||||
const BASE_URL = '/webApi/api/tik/ai-service-config'
|
||||
|
||||
/**
|
||||
* 模型配置 API 服务
|
||||
* 服务配置 API 服务
|
||||
*/
|
||||
export const ModelConfigService = {
|
||||
export const ServiceConfigService = {
|
||||
/**
|
||||
* 获取所有启用的模型配置列表(按平台分组)
|
||||
* @returns {Promise<Object>} 按平台分组的模型配置
|
||||
* 格式: { platform: [{ modelCode, modelName, consumePoints }] }
|
||||
* 获取所有启用的服务配置列表(按平台分组)
|
||||
* @returns {Promise<Object>} 按平台分组的服务配置
|
||||
* 格式: { platform: [{ serviceCode, serviceName, consumePoints }] }
|
||||
*/
|
||||
async getEnabledModelConfigList() {
|
||||
async getEnabledServiceConfigList() {
|
||||
const { data } = await http.get(`${BASE_URL}/list-enabled`)
|
||||
return data || {}
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据模型代码获取积分消耗
|
||||
* @param {Object} configMap - 配置映射(从 getEnabledModelConfigList 获取)
|
||||
* @param {string} modelCode - 模型代码
|
||||
* 根据服务代码获取积分消耗
|
||||
* @param {Object} configMap - 配置映射(从 getEnabledServiceConfigList 获取)
|
||||
* @param {string} serviceCode - 服务代码
|
||||
* @returns {number|null} 积分消耗,未找到返回 null
|
||||
*/
|
||||
getConsumePoints(configMap, modelCode) {
|
||||
if (!configMap || !modelCode) return null
|
||||
getConsumePoints(configMap, serviceCode) {
|
||||
if (!configMap || !serviceCode) return null
|
||||
|
||||
for (const platform of Object.values(configMap)) {
|
||||
const model = platform?.find(m => m.modelCode === modelCode)
|
||||
if (model) {
|
||||
return model.consumePoints
|
||||
const service = platform?.find(s => s.serviceCode === serviceCode)
|
||||
if (service) {
|
||||
return service.consumePoints
|
||||
}
|
||||
}
|
||||
return null
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据模型代码获取模型名称
|
||||
* 根据服务代码获取服务名称
|
||||
* @param {Object} configMap - 配置映射
|
||||
* @param {string} modelCode - 模型代码
|
||||
* @returns {string|null} 模型名称,未找到返回 null
|
||||
* @param {string} serviceCode - 服务代码
|
||||
* @returns {string|null} 服务名称,未找到返回 null
|
||||
*/
|
||||
getModelName(configMap, modelCode) {
|
||||
if (!configMap || !modelCode) return null
|
||||
getServiceName(configMap, serviceCode) {
|
||||
if (!configMap || !serviceCode) return null
|
||||
|
||||
for (const platform of Object.values(configMap)) {
|
||||
const model = platform?.find(m => m.modelCode === modelCode)
|
||||
if (model) {
|
||||
return model.modelName
|
||||
const service = platform?.find(s => s.serviceCode === serviceCode)
|
||||
if (service) {
|
||||
return service.serviceName
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export default ModelConfigService
|
||||
// 兼容旧名称(逐步废弃)
|
||||
export const ModelConfigService = ServiceConfigService
|
||||
|
||||
export default ServiceConfigService
|
||||
|
||||
Reference in New Issue
Block a user