TASK:LLM;

This commit is contained in:
shahaibo
2025-05-21 21:03:15 +08:00
parent 9614985690
commit 94e00459b6
3 changed files with 102 additions and 4 deletions

View File

@@ -58,9 +58,10 @@ public class LLMController {
@RequestParam Long projectId, @RequestParam Long projectId,
@RequestParam(required = false) String fileUrl, @RequestParam(required = false) String fileUrl,
@RequestParam(required = false) List<String> imageUrlList, @RequestParam(required = false) List<String> imageUrlList,
@RequestParam(required = false) String process,
@RequestParam String token, @RequestParam String token,
@RequestParam Boolean enableThinking) { @RequestParam Boolean enableThinking) {
return llmService.stream(prompt, projectId, fileUrl, imageUrlList, token, enableThinking); return llmService.stream(prompt, projectId, fileUrl, imageUrlList, token, enableThinking, process);
} }
@ApiOperation(value = "对话创建项目") @ApiOperation(value = "对话创建项目")

View File

@@ -31,7 +31,7 @@ import java.util.Set;
*/ */
public interface LLMService { public interface LLMService {
SseEmitter stream(String prompt, Long projectId, String fileUrl, List<String> imageUrlList, String token, Boolean enableThinking); SseEmitter stream(String prompt, Long projectId, String fileUrl, List<String> imageUrlList, String token, Boolean enableThinking, String process);
Long chatCreateProject(String prompt, String process, String fileUrl, List<String> imageUrlList); Long chatCreateProject(String prompt, String process, String fileUrl, List<String> imageUrlList);

View File

@@ -67,7 +67,7 @@ public class LLMServiceImpl implements LLMService {
private final ExecutorService executor = Executors.newCachedThreadPool(); private final ExecutorService executor = Executors.newCachedThreadPool();
@Override @Override
public SseEmitter stream(String prompt, Long projectId, String fileUrl, List<String> imageUrlList, String token, Boolean enableThinking) { public SseEmitter stream(String prompt, Long projectId, String fileUrl, List<String> imageUrlList, String token, Boolean enableThinking, String process) {
SseEmitter emitter = new SseEmitter(0L); // 永不超时 SseEmitter emitter = new SseEmitter(0L); // 永不超时
executor.submit(() -> { executor.submit(() -> {
@@ -92,6 +92,7 @@ public class LLMServiceImpl implements LLMService {
jsonBodyObject.put("file", !StringUtils.isEmpty(fileUrl) ? Collections.singletonList(fileUrl) : new ArrayList<>()); jsonBodyObject.put("file", !StringUtils.isEmpty(fileUrl) ? Collections.singletonList(fileUrl) : new ArrayList<>());
jsonBodyObject.put("message", prompt); jsonBodyObject.put("message", prompt);
jsonBodyObject.put("enable_thinking", enableThinking); jsonBodyObject.put("enable_thinking", enableThinking);
// jsonBodyObject.put("process", process);
// 1. 存储用户输入 // 1. 存储用户输入
ChatMessage userMessage = new ChatMessage(); ChatMessage userMessage = new ChatMessage();
@@ -150,7 +151,7 @@ public class LLMServiceImpl implements LLMService {
responseContentBuilder = new StringBuilder(); responseContentBuilder = new StringBuilder();
} }
JSONObject toolsData = json.getJSONObject("tools_data"); JSONObject toolsData = json.getJSONObject("tools_data");
if (Objects.nonNull(toolsData) && !status.equals("[DESIGN_SIGNAL]")) { if (Objects.nonNull(toolsData) && !status.equals("[DESIGN_SIGNAL]") && !status.equals("[PROJECT_CREATE_SIGNAL]")) {
boolean color = true; boolean color = true;
ReceiveDesignParam receiveDesignParam = JSONObject.parseObject(JSONObject.toJSONString(toolsData), ReceiveDesignParam.class); ReceiveDesignParam receiveDesignParam = JSONObject.parseObject(JSONObject.toJSONString(toolsData), ReceiveDesignParam.class);
receiveDesignParam.setProjectId(projectId); receiveDesignParam.setProjectId(projectId);
@@ -177,6 +178,102 @@ public class LLMServiceImpl implements LLMService {
systemImage.setAccountId(accountId); systemImage.setAccountId(accountId);
chatMessageMapper.insert(systemImage); chatMessageMapper.insert(systemImage);
} }
if (status.equals("[PROJECT_CREATE_SIGNAL]")) {
JSONObject data = toolsData;
Project project = new Project();
LocalDateTime now = LocalDateTime.now();
project.setUpdateTime(now);
project.setCreateTime(now);
project.setAccountId(accountId);
project.setName(data.getString("project_name"));
project.setOriginal(1);
// String process = data.getString("process");
// if (StringUtils.isEmpty(process)) {
// project.setProcess(DesignProcess.SERIES_DESIGN.name());
// }else {
// if (DesignProcess.isValidName(process)) {
// project.setProcess(process);
// }else {
// project.setProcess(DesignProcess.SERIES_DESIGN.name());
// }
// }
project.setProcess(process);
projectMapper.insert(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 (StringUtils.isEmpty(position)) {
workspace.setPosition("Overall");
}else {
if (Position.isValidName(position)) {
workspace.setPosition(position);
}else {
workspace.setPosition("Overall");
}
}
workspace.setSystemDesignerPercentage(30);
workspace.setProjectId(project.getId());
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", project.getId());
json.put("tools_data", toolsData.toJSONString());
}
emitter.send(json.toJSONString()); emitter.send(json.toJSONString());
} }
} }