TASK:LLM;
This commit is contained in:
@@ -55,7 +55,7 @@ public class LLMController {
|
|||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@GetMapping(value = "/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
@GetMapping(value = "/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||||
public SseEmitter streamPrompt(@RequestParam String prompt,
|
public SseEmitter streamPrompt(@RequestParam String prompt,
|
||||||
@RequestParam Long projectId,
|
@RequestParam(required = false) 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(required = false) String process,
|
||||||
|
|||||||
@@ -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, String process) {
|
public SseEmitter stream(String prompt, Long projectParamId, 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(() -> {
|
||||||
@@ -76,13 +76,21 @@ public class LLMServiceImpl implements LLMService {
|
|||||||
if (validate) {
|
if (validate) {
|
||||||
AuthPrincipalVo principal = jwtTokenHelper.parserToUser(token);
|
AuthPrincipalVo principal = jwtTokenHelper.parserToUser(token);
|
||||||
Long accountId = principal.getId();
|
Long accountId = principal.getId();
|
||||||
int userSeq = getNextSeq(projectId); // 获取当前session下一条消息序号
|
|
||||||
String url = "http://18.167.251.121:10002/chat-stream";
|
String url = "http://18.167.251.121:10002/chat-stream";
|
||||||
// String url = "http://10.1.1.240:1013/chat-stream";
|
// String url = "http://10.1.1.240:1013/chat-stream";
|
||||||
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
|
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
|
||||||
conn.setRequestMethod("POST");
|
conn.setRequestMethod("POST");
|
||||||
conn.setDoOutput(true);
|
conn.setDoOutput(true);
|
||||||
conn.setRequestProperty("Content-Type", "application/json");
|
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();
|
JSONObject jsonBodyObject = new JSONObject();
|
||||||
jsonBodyObject.put("project_id", projectId.toString());
|
jsonBodyObject.put("project_id", projectId.toString());
|
||||||
@@ -98,7 +106,7 @@ public class LLMServiceImpl implements LLMService {
|
|||||||
ChatMessage userMessage = new ChatMessage();
|
ChatMessage userMessage = new ChatMessage();
|
||||||
userMessage.setRole("user");
|
userMessage.setRole("user");
|
||||||
userMessage.setProjectId(projectId);
|
userMessage.setProjectId(projectId);
|
||||||
userMessage.setSeq(userSeq);
|
userMessage.setSeq(getNextSeq(projectId));
|
||||||
userMessage.setCreateTime(LocalDateTime.now());
|
userMessage.setCreateTime(LocalDateTime.now());
|
||||||
userMessage.setContent(jsonBodyObject.toJSONString());
|
userMessage.setContent(jsonBodyObject.toJSONString());
|
||||||
userMessage.setAccountId(accountId);
|
userMessage.setAccountId(accountId);
|
||||||
@@ -180,10 +188,9 @@ public class LLMServiceImpl implements LLMService {
|
|||||||
}
|
}
|
||||||
if (status.equals("[PROJECT_CREATE_SIGNAL]")) {
|
if (status.equals("[PROJECT_CREATE_SIGNAL]")) {
|
||||||
JSONObject data = toolsData;
|
JSONObject data = toolsData;
|
||||||
Project project = new Project();
|
Project project = projectMapper.selectById(projectId);
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
project.setUpdateTime(now);
|
project.setUpdateTime(now);
|
||||||
project.setCreateTime(now);
|
|
||||||
project.setAccountId(accountId);
|
project.setAccountId(accountId);
|
||||||
project.setName(data.getString("project_name"));
|
project.setName(data.getString("project_name"));
|
||||||
project.setOriginal(1);
|
project.setOriginal(1);
|
||||||
@@ -198,7 +205,7 @@ public class LLMServiceImpl implements LLMService {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
project.setProcess(process);
|
project.setProcess(process);
|
||||||
projectMapper.insert(project);
|
projectMapper.updateById(project);
|
||||||
|
|
||||||
Workspace workspace = new Workspace();
|
Workspace workspace = new Workspace();
|
||||||
workspace.setAccountId(accountId);
|
workspace.setAccountId(accountId);
|
||||||
@@ -235,7 +242,7 @@ public class LLMServiceImpl implements LLMService {
|
|||||||
}
|
}
|
||||||
workspace.setSystemDesignerPercentage(30);
|
workspace.setSystemDesignerPercentage(30);
|
||||||
workspace.setProjectId(project.getId());
|
workspace.setProjectId(project.getId());
|
||||||
|
workspace.setAccountId(accountId);
|
||||||
String style = data.getString("style");
|
String style = data.getString("style");
|
||||||
String styleName = null;
|
String styleName = null;
|
||||||
if (StringUtils.isEmpty(style)) {
|
if (StringUtils.isEmpty(style)) {
|
||||||
@@ -271,7 +278,7 @@ public class LLMServiceImpl implements LLMService {
|
|||||||
workspaceRelStyleMapper.insert(rel);
|
workspaceRelStyleMapper.insert(rel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
toolsData.put("projectId", project.getId());
|
toolsData.put("projectId", projectId);
|
||||||
json.put("tools_data", toolsData.toJSONString());
|
json.put("tools_data", toolsData.toJSONString());
|
||||||
}
|
}
|
||||||
emitter.send(json.toJSONString());
|
emitter.send(json.toJSONString());
|
||||||
|
|||||||
Reference in New Issue
Block a user