【代码重构】AI:“聊天模型”重构为“模型”,支持 type 模型类型
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package cn.iocoder.yudao.framework.ai.core.enums;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.core.ArrayValuable;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* AI 模型类型的枚举
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum AiModelTypeEnum implements ArrayValuable<Integer> {
|
||||
|
||||
CHAT(1, "对话"),
|
||||
IMAGE(2, "图片"),
|
||||
VOICE(3, "语音"),
|
||||
VIDEO(4, "视频"),
|
||||
EMBEDDING(5, "向量"),
|
||||
RERANK(6, "重排序");
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private final Integer type;
|
||||
/**
|
||||
* 类型名
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
public static final Integer[] ARRAYS = Arrays.stream(values()).map(AiModelTypeEnum::getType).toArray(Integer[]::new);
|
||||
|
||||
@Override
|
||||
public Integer[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
|
||||
}
|
@@ -1,8 +1,11 @@
|
||||
package cn.iocoder.yudao.framework.ai.core.enums;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.core.ArrayValuable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* AI 模型平台
|
||||
*
|
||||
@@ -10,7 +13,7 @@ import lombok.Getter;
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum AiPlatformEnum {
|
||||
public enum AiPlatformEnum implements ArrayValuable<String> {
|
||||
|
||||
// ========== 国内平台 ==========
|
||||
|
||||
@@ -44,6 +47,8 @@ public enum AiPlatformEnum {
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
public static final String[] ARRAYS = Arrays.stream(values()).map(AiPlatformEnum::getPlatform).toArray(String[]::new);
|
||||
|
||||
public static AiPlatformEnum validatePlatform(String platform) {
|
||||
for (AiPlatformEnum platformEnum : AiPlatformEnum.values()) {
|
||||
if (platformEnum.getPlatform().equals(platform)) {
|
||||
@@ -53,4 +58,9 @@ public enum AiPlatformEnum {
|
||||
throw new IllegalArgumentException("非法平台: " + platform);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -456,25 +456,4 @@ public class AiModelFactoryImpl implements AiModelFactory {
|
||||
return vectorStore;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建向量存储文件
|
||||
*
|
||||
* @param embeddingModel 嵌入模型
|
||||
* @return 向量存储文件
|
||||
*/
|
||||
private File createVectorStoreFile(EmbeddingModel embeddingModel) {
|
||||
// 获取简单类名
|
||||
String simpleClassName = embeddingModel.getClass().getSimpleName();
|
||||
// 获取用户主目录
|
||||
String userHome = FileUtil.getUserHomePath();
|
||||
// 创建vector_store目录
|
||||
File vectorStoreDir = new File(userHome, "vector_store");
|
||||
if (!vectorStoreDir.exists()) {
|
||||
vectorStoreDir.mkdirs();
|
||||
}
|
||||
|
||||
// 创建文件
|
||||
return new File(vectorStoreDir, "simple_" + simpleClassName + ".json");
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user