TASK:collection sort;
This commit is contained in:
@@ -38,4 +38,6 @@ public interface LLMService {
|
||||
List<String> uploadFile(MultipartFile file);
|
||||
|
||||
PageBaseResponse<ChatMessage> getChatHistory(ChatHistoryDTO chatHistoryDTO);
|
||||
|
||||
SseEmitter streamNew(String prompt, Long projectId, String fileUrl, List<String> imageUrlList, String token, Boolean enableThinking, String process);
|
||||
}
|
||||
|
||||
@@ -188,103 +188,162 @@ public class LLMServiceImpl implements LLMService {
|
||||
systemImage.setAccountId(accountId);
|
||||
chatMessageMapper.insert(systemImage);
|
||||
}
|
||||
// if (status.equals("[PROJECT_CREATE_SIGNAL]")) {
|
||||
// JSONObject data = toolsData;
|
||||
// Project project = projectMapper.selectById(projectId);
|
||||
// LocalDateTime now = LocalDateTime.now();
|
||||
// project.setUpdateTime(now);
|
||||
// project.setAccountId(accountId);
|
||||
// project.setName(data.getString("project_name"));
|
||||
// project.setOriginal(1);
|
||||
// project.setProcess(process);
|
||||
// projectMapper.updateById(project);
|
||||
//
|
||||
// Workspace workspace = new Workspace();
|
||||
// workspace.setAccountId(accountId);
|
||||
// workspace.setCreateTime(now);
|
||||
// String ageGroup = data.getString("ageGroup");
|
||||
// if (StringUtils.isEmpty(ageGroup)) {
|
||||
// workspace.setAgeGroup("Adult");
|
||||
// }else {
|
||||
// if (AgeGroup.isValidName(process)) {
|
||||
// workspace.setAgeGroup(ageGroup);
|
||||
// }else {
|
||||
// workspace.setAgeGroup("Adult");
|
||||
// }
|
||||
// }
|
||||
// String gender = data.getString("gender");
|
||||
// if (StringUtils.isEmpty(gender)) {
|
||||
// workspace.setSex("Female");
|
||||
// }else {
|
||||
// if (Sex.isValidName(gender)) {
|
||||
// workspace.setSex(gender);
|
||||
// }else {
|
||||
// workspace.setSex("Female");
|
||||
// }
|
||||
// }
|
||||
// String position = data.getString("position");
|
||||
// if (process.equals(DesignProcess.SERIES_DESIGN.name())) {
|
||||
// workspace.setPosition("Overall");
|
||||
// }else {
|
||||
// if (StringUtils.isEmpty(position)) {
|
||||
// if (workspace.getSex().equals("Female")) {
|
||||
// workspace.setPosition(Position.BLOUSE.getValue());
|
||||
// }else {
|
||||
// workspace.setPosition(Position.TOPS.getValue());
|
||||
// }
|
||||
// }else {
|
||||
// if (Position.isValidName(position)) {
|
||||
// workspace.setPosition(position);
|
||||
// }else {
|
||||
// if (workspace.getSex().equals("Female")) {
|
||||
// workspace.setPosition(Position.BLOUSE.getValue());
|
||||
// }else {
|
||||
// workspace.setPosition(Position.TOPS.getValue());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// workspace.setSystemDesignerPercentage(30);
|
||||
// workspace.setProjectId(project.getId());
|
||||
// workspace.setAccountId(accountId);
|
||||
// String style = data.getString("style");
|
||||
// String styleName = null;
|
||||
// if (StringUtils.isEmpty(style)) {
|
||||
// styleName = StyleEnum.NEW_CHINESE.name();
|
||||
// }else {
|
||||
// if (StyleEnum.isValidName(style)) {
|
||||
// styleName = style;
|
||||
// }else {
|
||||
// styleName = StyleEnum.NEW_CHINESE.name();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// SysFile sysFile = sysFileService.getOneBySex(styleName, workspace.getSex(), workspace.getAgeGroup());
|
||||
//
|
||||
// if (workspace.getSex().equals(Sex.FEMALE.getValue())) {
|
||||
// workspace.setMannequinFemaleId(sysFile.getId());
|
||||
// workspace.setMannequinFemaleType("System");
|
||||
// }else {
|
||||
// workspace.setMannequinMaleId(sysFile.getId());
|
||||
// workspace.setMannequinMaleType("System");
|
||||
// }
|
||||
//
|
||||
// workspaceMapper.insert(workspace);
|
||||
//
|
||||
// if (!StringUtils.isEmpty(styleName)) {
|
||||
// QueryWrapper<Style> qw = new QueryWrapper<>();
|
||||
// qw.lambda().eq(Style::getName, styleName);
|
||||
// Style style1 = styleMapper.selectOne(qw);
|
||||
// if (Objects.nonNull(style1)) {
|
||||
// WorkspaceRelStyle rel = new WorkspaceRelStyle();
|
||||
// rel.setWorkspaceId(workspace.getId());
|
||||
// rel.setStyleId(style1.getId());
|
||||
// workspaceRelStyleMapper.insert(rel);
|
||||
// }
|
||||
// }
|
||||
// toolsData.put("projectId", projectId);
|
||||
// json.put("tools_data", toolsData.toJSONString());
|
||||
// }
|
||||
|
||||
emitter.send(json.toJSONString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (responseContentBuilder.length() != 0) {
|
||||
systemMessage.setSeq(getNextSeq(projectId));
|
||||
systemMessage.setCreateTime(LocalDateTime.now());
|
||||
systemMessage.setContent(responseContentBuilder.toString());
|
||||
chatMessageMapper.insert(systemMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
emitter.complete();
|
||||
} catch (Exception e) {
|
||||
System.out.println("走进异常");
|
||||
emitter.completeWithError(e);
|
||||
}
|
||||
});
|
||||
|
||||
return emitter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SseEmitter streamNew(String prompt, Long projectParamId, String fileUrl, List<String> imageUrlList, String token, Boolean enableThinking, String process) {
|
||||
SseEmitter emitter = new SseEmitter(0L); // 永不超时
|
||||
|
||||
executor.submit(() -> {
|
||||
try {
|
||||
boolean validate = jwtTokenHelper.validateToken(token);
|
||||
if (validate) {
|
||||
AuthPrincipalVo principal = jwtTokenHelper.parserToUser(token);
|
||||
Long accountId = principal.getId();
|
||||
// String url = "http://18.167.251.121:10002/chat-stream";
|
||||
String url = "http://18.167.251.121:10002/api/chat_stream";
|
||||
// String url = "http://10.1.1.240:1013/chat-stream";
|
||||
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setDoOutput(true);
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
Long projectId = null;
|
||||
if (null == projectParamId) {
|
||||
Project project = new Project();
|
||||
project.setCreateTime(LocalDateTime.now());
|
||||
projectMapper.insert(project);
|
||||
projectId = project.getId();
|
||||
}else {
|
||||
projectId = projectParamId;
|
||||
}
|
||||
|
||||
JSONObject jsonBodyObject = new JSONObject();
|
||||
jsonBodyObject.put("project_id", projectId.toString());
|
||||
jsonBodyObject.put("role", "user");
|
||||
jsonBodyObject.put("image", !CollectionUtils.isEmpty(imageUrlList) ? imageUrlList : new ArrayList<>()); // 可扩展
|
||||
// jsonBodyObject.put("image", ""); // 可扩展
|
||||
jsonBodyObject.put("file", !StringUtils.isEmpty(fileUrl) ? Collections.singletonList(fileUrl) : new ArrayList<>());
|
||||
jsonBodyObject.put("message", prompt);
|
||||
jsonBodyObject.put("enable_thinking", enableThinking);
|
||||
jsonBodyObject.put("process", !StringUtils.isEmpty(process) ? process : "");
|
||||
jsonBodyObject.put("is_create_project", false);
|
||||
|
||||
// 1. 存储用户输入
|
||||
ChatMessage userMessage = new ChatMessage();
|
||||
userMessage.setRole("user");
|
||||
userMessage.setProjectId(projectId);
|
||||
userMessage.setSeq(getNextSeq(projectId));
|
||||
userMessage.setCreateTime(LocalDateTime.now());
|
||||
userMessage.setContent(jsonBodyObject.toJSONString());
|
||||
userMessage.setAccountId(accountId);
|
||||
chatMessageMapper.insert(userMessage);
|
||||
|
||||
try (OutputStream os = conn.getOutputStream()) {
|
||||
System.out.println(jsonBodyObject.toJSONString());
|
||||
byte[] input = jsonBodyObject.toJSONString().getBytes(StandardCharsets.UTF_8);
|
||||
os.write(input, 0, input.length);
|
||||
}
|
||||
|
||||
// 2. 流式接收并累积内容
|
||||
// 3. 存储系统回复
|
||||
ChatMessage systemMessage = new ChatMessage();
|
||||
systemMessage.setRole("system");
|
||||
systemMessage.setIsImage(0);
|
||||
systemMessage.setProjectId(projectId);
|
||||
systemMessage.setAccountId(accountId);
|
||||
StringBuilder responseContentBuilder = new StringBuilder();
|
||||
String contentType = "";
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
line = line.trim();
|
||||
if (!line.isEmpty() && line.startsWith("data: ")) {
|
||||
String jsonStr = line.substring(12);
|
||||
System.out.println(jsonStr);
|
||||
JSONObject json = JSON.parseObject(jsonStr);
|
||||
String type = json.getString("type");
|
||||
if (!StringUtils.isEmpty(type)) {
|
||||
String content = json.getString("content");
|
||||
// 结束标识
|
||||
if ("done".equals(type)) {
|
||||
break;
|
||||
}
|
||||
if ("text".equals(type) || "think".equals(type)) {
|
||||
if (StringUtils.isEmpty(contentType)) {
|
||||
contentType = type;
|
||||
}
|
||||
if (!contentType.equals(type)) {
|
||||
systemMessage.setSeq(getNextSeq(projectId));
|
||||
systemMessage.setCreateTime(LocalDateTime.now());
|
||||
systemMessage.setContent(responseContentBuilder.toString());
|
||||
chatMessageMapper.insert(systemMessage);
|
||||
systemMessage.setId(null);
|
||||
responseContentBuilder = new StringBuilder();
|
||||
contentType = type;
|
||||
}
|
||||
responseContentBuilder.append(content);
|
||||
emitter.send(json.toJSONString());
|
||||
}else if ("tools_response".equals(type)){
|
||||
if (responseContentBuilder.length() != 0) {
|
||||
systemMessage.setSeq(getNextSeq(projectId));
|
||||
systemMessage.setCreateTime(LocalDateTime.now());
|
||||
systemMessage.setContent(responseContentBuilder.toString());
|
||||
chatMessageMapper.insert(systemMessage);
|
||||
systemMessage.setId(null);
|
||||
responseContentBuilder = new StringBuilder();
|
||||
}
|
||||
String toolsName = json.getString("tools_name");
|
||||
JSONObject toolsData = json.getJSONObject("content");
|
||||
if (Objects.nonNull(toolsName) && !toolsName.equals("design_control_signal") && !toolsName.equals("generate_project_info")) {
|
||||
boolean color = true;
|
||||
ReceiveDesignParam receiveDesignParam = JSONObject.parseObject(JSONObject.toJSONString(toolsData), ReceiveDesignParam.class);
|
||||
receiveDesignParam.setProjectId(projectId);
|
||||
designService.receiveDesignParams(receiveDesignParam);
|
||||
for (ReceiveCollectionElement receiveCollectionElement : receiveDesignParam.getReceiveCollectionElementList()) {
|
||||
if (!StringUtils.isEmpty(receiveCollectionElement.getUrl())) {
|
||||
color = false;
|
||||
receiveCollectionElement.setMinioUrl(minioUtil.getPreSignedUrl(receiveCollectionElement.getUrl(), 24 * 60));
|
||||
}
|
||||
}
|
||||
String jsonString = JSONObject.toJSONString(receiveDesignParam);
|
||||
json.put("content", jsonString);
|
||||
ChatMessage systemImage = new ChatMessage();
|
||||
systemImage.setRole("system");
|
||||
if (color) {
|
||||
systemImage.setIsImage(1);
|
||||
}else {
|
||||
systemImage.setIsImage(2);
|
||||
}
|
||||
systemImage.setProjectId(projectId);
|
||||
systemImage.setSeq(getNextSeq(projectId));
|
||||
systemImage.setCreateTime(LocalDateTime.now());
|
||||
systemImage.setContent(JSONObject.toJSONString(receiveDesignParam.getReceiveCollectionElementList()));
|
||||
systemImage.setAccountId(accountId);
|
||||
chatMessageMapper.insert(systemImage);
|
||||
}
|
||||
emitter.send(json.toJSONString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -590,10 +590,11 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
ToProductImageResult toProductImageResult = new ToProductImageResult();
|
||||
toProductImageResult.setIsLike(1);
|
||||
toProductImageResultMapper.update(toProductImageResult, qw);
|
||||
if (toProductImageResult.getResultType().equals("Relight")) {
|
||||
designService.addCollectionSort(toProductImageResult.getId(), CollectionType.RELIGHT.getValue(), productImageLikeDTO.getProjectId());
|
||||
ToProductImageResult toProductImageResult1 = toProductImageResultMapper.selectById(toProductImageResultId.get(0));
|
||||
if (toProductImageResult1.getResultType().equals("Relight")) {
|
||||
designService.addCollectionSort(toProductImageResult1.getId(), CollectionType.RELIGHT.getValue(), productImageLikeDTO.getProjectId());
|
||||
}else {
|
||||
designService.addCollectionSort(toProductImageResult.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(), productImageLikeDTO.getProjectId());
|
||||
designService.addCollectionSort(toProductImageResult1.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(), productImageLikeDTO.getProjectId());
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user