From 94e00459b6f6d2a3532e9c33c8962b03599b6451 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Wed, 21 May 2025 21:03:15 +0800 Subject: [PATCH] =?UTF-8?q?TASK:LLM=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ai/da/controller/LLMController.java | 3 +- .../java/com/ai/da/service/LLMService.java | 2 +- .../ai/da/service/impl/LLMServiceImpl.java | 101 +++++++++++++++++- 3 files changed, 102 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/ai/da/controller/LLMController.java b/src/main/java/com/ai/da/controller/LLMController.java index d54490be..cf58932f 100644 --- a/src/main/java/com/ai/da/controller/LLMController.java +++ b/src/main/java/com/ai/da/controller/LLMController.java @@ -58,9 +58,10 @@ public class LLMController { @RequestParam Long projectId, @RequestParam(required = false) String fileUrl, @RequestParam(required = false) List imageUrlList, + @RequestParam(required = false) String process, @RequestParam String token, @RequestParam Boolean enableThinking) { - return llmService.stream(prompt, projectId, fileUrl, imageUrlList, token, enableThinking); + return llmService.stream(prompt, projectId, fileUrl, imageUrlList, token, enableThinking, process); } @ApiOperation(value = "对话创建项目") diff --git a/src/main/java/com/ai/da/service/LLMService.java b/src/main/java/com/ai/da/service/LLMService.java index 5c370d32..5ecbe895 100644 --- a/src/main/java/com/ai/da/service/LLMService.java +++ b/src/main/java/com/ai/da/service/LLMService.java @@ -31,7 +31,7 @@ import java.util.Set; */ public interface LLMService { - SseEmitter stream(String prompt, Long projectId, String fileUrl, List imageUrlList, String token, Boolean enableThinking); + SseEmitter stream(String prompt, Long projectId, String fileUrl, List imageUrlList, String token, Boolean enableThinking, String process); Long chatCreateProject(String prompt, String process, String fileUrl, List imageUrlList); diff --git a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java index c6762cfc..68fd76fc 100644 --- a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java @@ -67,7 +67,7 @@ public class LLMServiceImpl implements LLMService { private final ExecutorService executor = Executors.newCachedThreadPool(); @Override - public SseEmitter stream(String prompt, Long projectId, String fileUrl, List imageUrlList, String token, Boolean enableThinking) { + public SseEmitter stream(String prompt, Long projectId, String fileUrl, List imageUrlList, String token, Boolean enableThinking, String process) { SseEmitter emitter = new SseEmitter(0L); // 永不超时 executor.submit(() -> { @@ -92,6 +92,7 @@ public class LLMServiceImpl implements LLMService { jsonBodyObject.put("file", !StringUtils.isEmpty(fileUrl) ? Collections.singletonList(fileUrl) : new ArrayList<>()); jsonBodyObject.put("message", prompt); jsonBodyObject.put("enable_thinking", enableThinking); +// jsonBodyObject.put("process", process); // 1. 存储用户输入 ChatMessage userMessage = new ChatMessage(); @@ -150,7 +151,7 @@ public class LLMServiceImpl implements LLMService { responseContentBuilder = new StringBuilder(); } 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; ReceiveDesignParam receiveDesignParam = JSONObject.parseObject(JSONObject.toJSONString(toolsData), ReceiveDesignParam.class); receiveDesignParam.setProjectId(projectId); @@ -177,6 +178,102 @@ public class LLMServiceImpl implements LLMService { systemImage.setAccountId(accountId); 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