TASK:LLM;
This commit is contained in:
@@ -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);
|
SseEmitter stream(String prompt, Long projectId, String fileUrl, List<String> imageUrlList, String token, Boolean enableThinking);
|
||||||
|
|
||||||
Long chatCreateProject(String prompt, String process);
|
Long chatCreateProject(String prompt, String process);
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import com.ai.da.service.DesignService;
|
|||||||
import com.ai.da.service.LLMService;
|
import com.ai.da.service.LLMService;
|
||||||
import com.ai.da.service.SysFileService;
|
import com.ai.da.service.SysFileService;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
@@ -36,10 +37,7 @@ import java.net.HttpURLConnection;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
@@ -69,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) {
|
public SseEmitter stream(String prompt, Long projectId, String fileUrl, List<String> imageUrlList, String token, Boolean enableThinking) {
|
||||||
SseEmitter emitter = new SseEmitter(0L); // 永不超时
|
SseEmitter emitter = new SseEmitter(0L); // 永不超时
|
||||||
|
|
||||||
executor.submit(() -> {
|
executor.submit(() -> {
|
||||||
@@ -89,11 +87,11 @@ public class LLMServiceImpl implements LLMService {
|
|||||||
JSONObject jsonBodyObject = new JSONObject();
|
JSONObject jsonBodyObject = new JSONObject();
|
||||||
jsonBodyObject.put("project_id", projectId.toString());
|
jsonBodyObject.put("project_id", projectId.toString());
|
||||||
jsonBodyObject.put("role", "user");
|
jsonBodyObject.put("role", "user");
|
||||||
// jsonBodyObject.put("image", !CollectionUtils.isEmpty(imageUrlList) ? imageUrlList : ""); // 可扩展
|
jsonBodyObject.put("image", !CollectionUtils.isEmpty(imageUrlList) ? imageUrlList : null); // 可扩展
|
||||||
jsonBodyObject.put("image", ""); // 可扩展
|
// jsonBodyObject.put("image", ""); // 可扩展
|
||||||
jsonBodyObject.put("file", fileUrl != null ? fileUrl : "");
|
jsonBodyObject.put("file", fileUrl != null ? Collections.singletonList(fileUrl) : null);
|
||||||
jsonBodyObject.put("message", prompt);
|
jsonBodyObject.put("message", prompt);
|
||||||
jsonBodyObject.put("enable_thinking", false);
|
jsonBodyObject.put("enable_thinking", enableThinking);
|
||||||
|
|
||||||
// 1. 存储用户输入
|
// 1. 存储用户输入
|
||||||
ChatMessage userMessage = new ChatMessage();
|
ChatMessage userMessage = new ChatMessage();
|
||||||
@@ -334,11 +332,29 @@ public class LLMServiceImpl implements LLMService {
|
|||||||
if (record.getRole().equals("user")) {
|
if (record.getRole().equals("user")) {
|
||||||
String content = record.getContent();
|
String content = record.getContent();
|
||||||
JSONObject jsonObject = JSONObject.parseObject(content);
|
JSONObject jsonObject = JSONObject.parseObject(content);
|
||||||
String file = jsonObject.getString("file");
|
JSONArray fileArray = jsonObject.getJSONArray("file");
|
||||||
if (!StringUtils.isEmpty(file)) {
|
if (!CollectionUtils.isEmpty(fileArray)) {
|
||||||
jsonObject.put("file", minioUtil.getPreSignedUrl(file, 24 * 60));
|
for (int i = 0; i < fileArray.size(); i++) {
|
||||||
|
String string = fileArray.getString(i);
|
||||||
|
if (!StringUtils.isEmpty(string)) {
|
||||||
|
fileArray.set(i, minioUtil.getPreSignedUrl(string, 24 * 60));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
jsonObject.put("file", fileArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONArray imageArray = jsonObject.getJSONArray("image");
|
||||||
|
if (!CollectionUtils.isEmpty(imageArray)) {
|
||||||
|
for (int i = 0; i < imageArray.size(); i++) {
|
||||||
|
String string = imageArray.getString(i);
|
||||||
|
if (!StringUtils.isEmpty(string)) {
|
||||||
|
imageArray.set(i, minioUtil.getPreSignedUrl(string, 24 * 60));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jsonObject.put("image", imageArray);
|
||||||
|
}
|
||||||
|
record.setContent(JSONObject.toJSONString(jsonObject));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return PageBaseResponse.success(chatMessagePage);
|
return PageBaseResponse.success(chatMessagePage);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user