优化
This commit is contained in:
@@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.tik.dify.service;
|
||||
import cn.iocoder.yudao.module.tik.dify.client.DifyClient;
|
||||
import cn.iocoder.yudao.module.tik.dify.vo.DifyChatReqVO;
|
||||
import cn.iocoder.yudao.module.tik.dify.vo.DifyChatRespVO;
|
||||
import cn.iocoder.yudao.module.tik.enums.AiModelTypeEnum;
|
||||
import cn.iocoder.yudao.module.tik.enums.AiPlatformEnum;
|
||||
import cn.iocoder.yudao.module.tik.muye.aiagent.dal.AiAgentDO;
|
||||
import cn.iocoder.yudao.module.tik.muye.aiagent.service.AiAgentService;
|
||||
import cn.iocoder.yudao.module.tik.muye.aimodelconfig.dal.AiModelConfigDO;
|
||||
@@ -27,13 +29,6 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
@Slf4j
|
||||
public class DifyServiceImpl implements DifyService {
|
||||
|
||||
/** Dify 平台标识 */
|
||||
private static final String PLATFORM_DIFY = "dify";
|
||||
/** Dify 模型类型 - Pro深度版 */
|
||||
private static final String MODEL_TYPE_WRITING_PRO = "writing_pro";
|
||||
/** Dify 模型类型 - 标准版 */
|
||||
private static final String MODEL_TYPE_WRITING_STANDARD = "writing_standard";
|
||||
|
||||
@Resource
|
||||
private AiAgentService aiAgentService;
|
||||
|
||||
@@ -58,10 +53,12 @@ public class DifyServiceImpl implements DifyService {
|
||||
}
|
||||
|
||||
// 2. 根据 modelMode 获取对应的积分配置
|
||||
String modelType = "standard".equals(reqVO.getModelMode())
|
||||
? MODEL_TYPE_WRITING_STANDARD
|
||||
: MODEL_TYPE_WRITING_PRO;
|
||||
AiModelConfigDO config = pointsService.getConfig(PLATFORM_DIFY, modelType);
|
||||
AiModelTypeEnum modelTypeEnum = "standard".equals(reqVO.getModelMode())
|
||||
? AiModelTypeEnum.DIFY_WRITING_STANDARD
|
||||
: AiModelTypeEnum.DIFY_WRITING_PRO;
|
||||
AiModelConfigDO config = pointsService.getConfig(
|
||||
AiPlatformEnum.DIFY.getPlatform(),
|
||||
modelTypeEnum.getModelType());
|
||||
|
||||
// 3. 预检积分
|
||||
pointsService.checkPoints(userId, config.getConsumePoints());
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package cn.iocoder.yudao.module.tik.enums;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.core.ArrayValuable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* AI 模型类型枚举
|
||||
* 统一管理所有 AI 服务的模型类型标识
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum AiModelTypeEnum implements ArrayValuable<String> {
|
||||
|
||||
// ========== Dify 写作模型 ==========
|
||||
DIFY_WRITING_PRO("writing_pro", "Pro深度版", AiPlatformEnum.DIFY),
|
||||
DIFY_WRITING_STANDARD("writing_standard", "标准版", AiPlatformEnum.DIFY),
|
||||
|
||||
// ========== 数字人模型 ==========
|
||||
DIGITAL_HUMAN_LATENTSYNC("latentsync", "LatentSync", AiPlatformEnum.DIGITAL_HUMAN),
|
||||
DIGITAL_HUMAN_KLING("kling", "可灵", AiPlatformEnum.DIGITAL_HUMAN),
|
||||
;
|
||||
|
||||
/**
|
||||
* 模型类型标识
|
||||
*/
|
||||
private final String modelType;
|
||||
/**
|
||||
* 模型类型名称
|
||||
*/
|
||||
private final String name;
|
||||
/**
|
||||
* 所属平台
|
||||
*/
|
||||
private final AiPlatformEnum platform;
|
||||
|
||||
public static final String[] ARRAYS = Arrays.stream(values()).map(AiModelTypeEnum::getModelType).toArray(String[]::new);
|
||||
|
||||
@Override
|
||||
public String[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据模型类型标识获取枚举
|
||||
*/
|
||||
public static AiModelTypeEnum valueOfModelType(String modelType) {
|
||||
return Arrays.stream(values())
|
||||
.filter(e -> e.getModelType().equals(modelType))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据平台获取该平台下所有模型类型
|
||||
*/
|
||||
public static AiModelTypeEnum[] valuesByPlatform(AiPlatformEnum platform) {
|
||||
return Arrays.stream(values())
|
||||
.filter(e -> e.getPlatform() == platform)
|
||||
.toArray(AiModelTypeEnum[]::new);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package cn.iocoder.yudao.module.tik.enums;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.core.ArrayValuable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* AI 平台枚举
|
||||
* 统一管理所有 AI 服务的平台标识
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum AiPlatformEnum implements ArrayValuable<String> {
|
||||
|
||||
DIFY("dify", "Dify 平台"),
|
||||
DIGITAL_HUMAN("digital_human", "数字人平台"),
|
||||
;
|
||||
|
||||
/**
|
||||
* 平台标识
|
||||
*/
|
||||
private final String platform;
|
||||
/**
|
||||
* 平台名称
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
public static final String[] ARRAYS = Arrays.stream(values()).map(AiPlatformEnum::getPlatform).toArray(String[]::new);
|
||||
|
||||
@Override
|
||||
public String[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据平台标识获取枚举
|
||||
*/
|
||||
public static AiPlatformEnum valueOfPlatform(String platform) {
|
||||
return Arrays.stream(values())
|
||||
.filter(e -> e.getPlatform().equals(platform))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user