|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package cn.teammodel.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.teammodel.ai.JsonLoader;
|
|
|
|
|
import cn.teammodel.ai.SparkGptClient;
|
|
|
|
|
import cn.teammodel.ai.SseHelper;
|
|
|
|
|
import cn.teammodel.ai.cache.HistoryCache;
|
|
|
|
@ -55,6 +56,9 @@ public class ChatMessageServiceImpl implements ChatMessageService {
|
|
|
|
|
@Resource
|
|
|
|
|
private ChatAppRepository chatAppRepository;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private JsonLoader jsonLoader;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public SseEmitter chatCompletion(ChatCompletionReqDto chatCompletionReqDto, String userId) {
|
|
|
|
@ -310,7 +314,10 @@ public class ChatMessageServiceImpl implements ChatMessageService {
|
|
|
|
|
String strData = JSON.toJSONString(chatCommentsDto.getData());
|
|
|
|
|
List<ChatModelDto> chatModels = new ArrayList<>();
|
|
|
|
|
ChatModelDto chatModel = null;
|
|
|
|
|
// 获取模型数据
|
|
|
|
|
chatModels = jsonLoader.myJsonDataBean();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
//验证获取模型数据 异常问题
|
|
|
|
|
try {
|
|
|
|
|
String fileText = FileUtil.getFileText("Json/ChatModel.json");
|
|
|
|
@ -324,16 +331,6 @@ public class ChatMessageServiceImpl implements ChatMessageService {
|
|
|
|
|
log.info("获取地址fileText:"+fileText+"----文件内容Data:"+ jsonData +"----获取模型集合Object:" + obj +"----获取模型集合String:"+ jsonData01 +"----获取模型集合机构:"+chatModels);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new ServiceException(ErrorCode.OPERATION_ERROR.getCode(), "读取文件" + Arrays.toString(e.getStackTrace()) + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*try {
|
|
|
|
|
//File file = null;
|
|
|
|
|
//chatModels = readResourceFile("Json/ChatModel.json");
|
|
|
|
|
//file = new File(ClassLoader.getSystemResource("Json/ChatModel.json").getPath()); //相对路径获取文件信息
|
|
|
|
|
//File file = new File("src/main/resources/Json/ChatModel.json"); //绝对路径获取文件信息
|
|
|
|
|
chatModels = readerMethod(file);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new ServiceException(ErrorCode.OPERATION_ERROR.getCode(), "读取文件并转换实体类" + Arrays.toString(e.getStackTrace()));
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
//循环查找对应的模型数据
|
|
|
|
@ -498,73 +495,4 @@ public class ChatMessageServiceImpl implements ChatMessageService {
|
|
|
|
|
|
|
|
|
|
return builder.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 读取文件信息并转换为智能对话模型数组对象
|
|
|
|
|
*
|
|
|
|
|
* @param file
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private static List<ChatModelDto> readerMethod(File file) {
|
|
|
|
|
//读取文件信息,并返回string字符串 ,并改成json格式
|
|
|
|
|
String fileTxt = FileUtil.readFile(file);
|
|
|
|
|
String strData = JSON.toJSONString(fileTxt);
|
|
|
|
|
|
|
|
|
|
//获取聊天字段中的数据
|
|
|
|
|
Object str = JSON.parseObject(strData).get("chatModel");
|
|
|
|
|
String strData2 = JSON.toJSONString(str);
|
|
|
|
|
List<ChatModelDto> chatModelDtos = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
//转换问题
|
|
|
|
|
try {
|
|
|
|
|
//转换方式
|
|
|
|
|
chatModelDtos = JSON.parseObject(strData2, new TypeReference<List<ChatModelDto>>() {});
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new ServiceException(ErrorCode.OPERATION_ERROR.getCode(), "类型转换失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return chatModelDtos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 读取资源文件 并转换实体类
|
|
|
|
|
* 读取文件信息并转换为智能对话模型数组对象
|
|
|
|
|
* @param fileName
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static List<ChatModelDto> readResourceFile(String fileName) {
|
|
|
|
|
StringBuilder content = new StringBuilder();
|
|
|
|
|
URL resourceUrl = ChatMessageServiceImpl.class.getClassLoader().getResource(fileName);
|
|
|
|
|
|
|
|
|
|
if (resourceUrl != null) {
|
|
|
|
|
try {
|
|
|
|
|
String filePath = Paths.get(resourceUrl.toURI()).toString();
|
|
|
|
|
content.append(new String(Files.readAllBytes(Paths.get(filePath))));
|
|
|
|
|
} catch (IOException | IllegalArgumentException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (URISyntaxException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("Resource not found.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String strData = JSON.toJSONString(content);
|
|
|
|
|
//获取聊天字段中的数据
|
|
|
|
|
Object str = JSON.parseObject(strData).get("chatModel");
|
|
|
|
|
String strData2 = JSON.toJSONString(str);
|
|
|
|
|
List<ChatModelDto> chatModelDtos = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
//转换问题
|
|
|
|
|
try {
|
|
|
|
|
//转换方式
|
|
|
|
|
chatModelDtos = JSON.parseObject(strData2, new TypeReference<List<ChatModelDto>>() {
|
|
|
|
|
});
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new ServiceException(ErrorCode.OPERATION_ERROR.getCode(), "类型转换失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return chatModelDtos;
|
|
|
|
|
//return content.toString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|