diff --git a/src/main/java/com/ai/da/controller/LLMController.java b/src/main/java/com/ai/da/controller/LLMController.java index cf58932f..208ca947 100644 --- a/src/main/java/com/ai/da/controller/LLMController.java +++ b/src/main/java/com/ai/da/controller/LLMController.java @@ -55,7 +55,7 @@ public class LLMController { @CrossOrigin @GetMapping(value = "/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE) public SseEmitter streamPrompt(@RequestParam String prompt, - @RequestParam Long projectId, + @RequestParam(required = false) Long projectId, @RequestParam(required = false) String fileUrl, @RequestParam(required = false) List imageUrlList, @RequestParam(required = false) String process, 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 72d973bc..33e010f8 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, String process) { + public SseEmitter stream(String prompt, Long projectParamId, String fileUrl, List imageUrlList, String token, Boolean enableThinking, String process) { SseEmitter emitter = new SseEmitter(0L); // 永不超时 executor.submit(() -> { @@ -76,13 +76,21 @@ public class LLMServiceImpl implements LLMService { if (validate) { AuthPrincipalVo principal = jwtTokenHelper.parserToUser(token); Long accountId = principal.getId(); - int userSeq = getNextSeq(projectId); // 获取当前session下一条消息序号 String url = "http://18.167.251.121:10002/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()); @@ -98,7 +106,7 @@ public class LLMServiceImpl implements LLMService { ChatMessage userMessage = new ChatMessage(); userMessage.setRole("user"); userMessage.setProjectId(projectId); - userMessage.setSeq(userSeq); + userMessage.setSeq(getNextSeq(projectId)); userMessage.setCreateTime(LocalDateTime.now()); userMessage.setContent(jsonBodyObject.toJSONString()); userMessage.setAccountId(accountId); @@ -180,10 +188,9 @@ public class LLMServiceImpl implements LLMService { } if (status.equals("[PROJECT_CREATE_SIGNAL]")) { JSONObject data = toolsData; - Project project = new Project(); + Project project = projectMapper.selectById(projectId); LocalDateTime now = LocalDateTime.now(); project.setUpdateTime(now); - project.setCreateTime(now); project.setAccountId(accountId); project.setName(data.getString("project_name")); project.setOriginal(1); @@ -198,7 +205,7 @@ public class LLMServiceImpl implements LLMService { // } // } project.setProcess(process); - projectMapper.insert(project); + projectMapper.updateById(project); Workspace workspace = new Workspace(); workspace.setAccountId(accountId); @@ -235,7 +242,7 @@ public class LLMServiceImpl implements LLMService { } workspace.setSystemDesignerPercentage(30); workspace.setProjectId(project.getId()); - + workspace.setAccountId(accountId); String style = data.getString("style"); String styleName = null; if (StringUtils.isEmpty(style)) { @@ -271,7 +278,7 @@ public class LLMServiceImpl implements LLMService { workspaceRelStyleMapper.insert(rel); } } - toolsData.put("projectId", project.getId()); + toolsData.put("projectId", projectId); json.put("tools_data", toolsData.toJSONString()); } emitter.send(json.toJSONString());