Merge remote-tracking branch 'origin/dev/dev' into dev/dev
This commit is contained in:
72
src/main/java/com/ai/da/common/enums/PoseEnum.java
Normal file
72
src/main/java/com/ai/da/common/enums/PoseEnum.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package com.ai.da.common.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum PoseEnum {
|
||||
|
||||
POSE_1(1L, "aida-sys-image/pose/pose-1.mp4", "aida-sys-image/pose/pose-1.gif", "aida-sys-image/pose/pose-1-first_frame.jpeg", "AACT.8090e67b.-E3pujumEfCbDTI_rjSH-A.LwIlGT3j"),
|
||||
POSE_2(2L, "aida-sys-image/pose/pose-2.mp4", "aida-sys-image/pose/pose-2.gif", "aida-sys-image/pose/pose-2-first_frame.jpeg", "AACT.8090e67b.TwJLxEv3EfCbDTI_rjSH-A.IOQZCYhf"),
|
||||
POSE_3(3L, "aida-sys-image/pose/pose-3.mp4", "aida-sys-image/pose/pose-3.gif", "aida-sys-image/pose/pose-3-first_frame.jpeg", "AACT.8090e67b.gd3OCkv4EfCxyZo8eQGF2Q.qMm-a1XI"),
|
||||
POSE_4(4L, "aida-sys-image/pose/pose-4.mp4", "aida-sys-image/pose/pose-4.gif", "aida-sys-image/pose/pose-4-first_frame.jpeg", "AACT.8090e67b.AUDnuEwDEfCEHBaRJeW4dg.rlx36xEY"),
|
||||
POSE_5(5L, "aida-sys-image/pose/pose-5.mp4", "aida-sys-image/pose/pose-5.gif", "aida-sys-image/pose/pose-5-first_frame.jpeg", "AACT.8090e67b.G8BvkEwEEfCxyZo8eQGF2Q.fo4ryrgR"),
|
||||
POSE_6(6L, "aida-sys-image/pose/pose-6.mp4", "aida-sys-image/pose/pose-6.gif", "aida-sys-image/pose/pose-6-first_frame.jpeg", "AACT.8090e67b.yBIPnEwEEfCxyZo8eQGF2Q.boSFwTG9");
|
||||
|
||||
|
||||
private final Long id;
|
||||
|
||||
private final String videoPath;
|
||||
|
||||
private final String gifPath;
|
||||
|
||||
private final String firstFramePath;
|
||||
|
||||
private final String templateId;
|
||||
|
||||
private static final List<Map<String, String>> PROPERTY_LIST;
|
||||
|
||||
static {
|
||||
PROPERTY_LIST = Arrays.stream(values())
|
||||
.map(PoseEnum::toMap)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static final Map<Long, PoseEnum> BY_ID = Arrays.stream(values())
|
||||
.collect(Collectors.toMap(PoseEnum::getId, Function.identity()));
|
||||
|
||||
private static final Map<String, PoseEnum> BY_VIDEO_PATH = Arrays.stream(values())
|
||||
.collect(Collectors.toMap(PoseEnum::getVideoPath, Function.identity()));
|
||||
|
||||
private static final List<String> VIDEO_PATH = Arrays.stream(values())
|
||||
.map(PoseEnum::getVideoPath).collect(Collectors.toList());
|
||||
|
||||
public static PoseEnum getById(Long id) {
|
||||
return BY_ID.get(id);
|
||||
}
|
||||
|
||||
public static PoseEnum getByVideoPath(String videoPath) {
|
||||
return BY_VIDEO_PATH.get(videoPath);
|
||||
}
|
||||
|
||||
private Map<String, String> toMap() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("id", String.valueOf(id));
|
||||
map.put("gif", gifPath);
|
||||
map.put("firstFrame", firstFramePath);
|
||||
return map;
|
||||
}
|
||||
|
||||
public static List<Map<String, String>> getPropertyList() {
|
||||
return new ArrayList<>(PROPERTY_LIST); // 返回副本以保证不可变性
|
||||
}
|
||||
|
||||
public static List<String> getVideoList() {
|
||||
return new ArrayList<>(VIDEO_PATH); // 返回副本以保证不可变性
|
||||
}
|
||||
}
|
||||
@@ -498,8 +498,6 @@ public class RedisUtil {
|
||||
|
||||
public final static String STRIPE_EXCEPTION_LOG = "StripeException:";
|
||||
|
||||
public final static String ANIMATE_ANYONE_TEMPLATE_ID = "AnimateAnyoneTemplateId:";
|
||||
|
||||
public void batchDeleteKeysWithSamePrefix(String prefix){
|
||||
Set<String> keys = redisTemplate.keys(prefix + "*");
|
||||
assert keys != null;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.ai.da.controller;
|
||||
|
||||
import com.ai.da.common.constant.CommonConstant;
|
||||
import com.ai.da.common.response.Response;
|
||||
import com.ai.da.common.utils.MinioUtil;
|
||||
import com.ai.da.mapper.primary.entity.GoogleUser;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.AccountLoginVO;
|
||||
@@ -35,6 +37,9 @@ public class ThirdPartyController {
|
||||
@Resource
|
||||
private DesignService designService;
|
||||
|
||||
@Resource
|
||||
private MinioUtil minioUtil;
|
||||
|
||||
/*@ApiOperation(value = "Add user information")
|
||||
@PostMapping("/addUser")
|
||||
public Response<Boolean> addUser(@Valid @RequestBody AccountAddDTO accountAddDTO) {
|
||||
@@ -153,4 +158,10 @@ public class ThirdPartyController {
|
||||
public Response<Boolean> receiveDesignParams(@Valid @RequestBody ReceiveDesignParam receiveDesignParam) {
|
||||
return Response.success(designService.receiveDesignParams(receiveDesignParam));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "刷新minio预签名地址")
|
||||
@GetMapping("/refreshMinioUrl")
|
||||
public Response<String> refreshMinioUrl(@RequestParam("path") String path){
|
||||
return Response.success(minioUtil.getPreSignedUrl(path, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,9 @@ public class Workspace implements Serializable {
|
||||
*/
|
||||
@ApiModelProperty(value = "用户ID")
|
||||
private Long accountId;
|
||||
|
||||
/**
|
||||
* 年龄段 Adult || Child
|
||||
*/
|
||||
private String ageGroup;
|
||||
/**
|
||||
* 性别
|
||||
|
||||
@@ -1416,13 +1416,12 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
}
|
||||
|
||||
public List<Map<String, String>> getAllPose(){
|
||||
String posePath = "aida-sys-image/pose/pose-1.gif";
|
||||
String firstFramePath = "aida-sys-image/pose/pose-1-first_frame.jpeg";
|
||||
HashMap<String, String> resp = new HashMap<>();
|
||||
// todo 以后要返回poseId
|
||||
resp.put("gif", minioUtil.getPreSignedUrl(posePath, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
resp.put("firstFrame", minioUtil.getPreSignedUrl(firstFramePath, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
return Arrays.asList(resp);
|
||||
List<Map<String, String>> propertyList = PoseEnum.getPropertyList();
|
||||
propertyList.forEach(item -> {
|
||||
item.put("gif", minioUtil.getPreSignedUrl(item.get("gif"), CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
item.put("firstFrame", minioUtil.getPreSignedUrl(item.get("firstFrame"), CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
});
|
||||
return propertyList;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1688,13 +1687,13 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
|
||||
// 轮询配置
|
||||
private static final int MAX_RETRIES = 30; // 最大重试次数
|
||||
private static final int POLL_INTERVAL = 2000; // 轮询间隔(毫秒)
|
||||
private static final int POLL_INTERVAL = 20000; // 轮询间隔(毫秒)
|
||||
|
||||
public String getVideoTemplateId(String videoPath){
|
||||
String key = RedisUtil.ANIMATE_ANYONE_TEMPLATE_ID + videoPath;
|
||||
String templateId = redisUtil.getFromString(key);
|
||||
boolean contains = PoseEnum.getVideoList().contains(videoPath);
|
||||
|
||||
if (StringUtil.isNullOrEmpty(templateId)){
|
||||
String templateId;
|
||||
if (!contains){
|
||||
String videoUrl = minioUtil.getPreSignedUrl(videoPath, CommonConstant.MINIO_IMAGE_EXPIRE_TIME);
|
||||
JSONObject requestBody = new JSONObject();
|
||||
requestBody.set("model", "animate-anyone-template-gen2");
|
||||
@@ -1704,8 +1703,8 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
requestBody.set("input", input);
|
||||
requestBody.set("parameters", parameters);
|
||||
|
||||
String resp = sendRequestUtil.sendPost(TEMPLATE_ID_GEN, requestBody.toString());
|
||||
|
||||
log.info("获取pose的模板id 请求数据:{}", requestBody);
|
||||
String resp = sendRequestUtil.sendAliYunPostAsync(TEMPLATE_ID_GEN, requestBody.toString());
|
||||
if (StringUtil.isNullOrEmpty(resp)){
|
||||
throw new BusinessException("请求获取video template id失败");
|
||||
}
|
||||
@@ -1720,7 +1719,8 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
throw new BusinessException("获取动作模板失败");
|
||||
}
|
||||
// templateId = "AACT.8090e67b.-E3pujumEfCbDTI_rjSH-A.LwIlGT3j";
|
||||
redisUtil.addToString(key, templateId);
|
||||
} else {
|
||||
templateId = PoseEnum.getByVideoPath(videoPath).getTemplateId();
|
||||
}
|
||||
|
||||
return templateId;
|
||||
@@ -2043,7 +2043,9 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
&& func.equals(CreditsEventsEnum.POSE_TRANSFORMATION.getValue())){
|
||||
List<PoseTransformation> poseTransformations = poseTransformationMapper.selectList(
|
||||
new QueryWrapper<PoseTransformation>().eq("unique_id", taskId));
|
||||
if (!poseTransformations.isEmpty() && poseTransformations.get(0).getModelName().equals("wx")){
|
||||
if (!poseTransformations.isEmpty()
|
||||
&& !StringUtil.isNullOrEmpty(poseTransformations.get(0).getModelName())
|
||||
&& poseTransformations.get(0).getModelName().equals("wx")){
|
||||
return "wx";
|
||||
}else {
|
||||
return "local";
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
import com.ai.da.common.constant.CommonConstant;
|
||||
import com.ai.da.common.context.UserContext;
|
||||
import com.ai.da.common.enums.CollectionLevel1TypeEnum;
|
||||
@@ -20,11 +21,16 @@ import com.ai.da.python.PythonService;
|
||||
import com.ai.da.service.DesignService;
|
||||
import com.ai.da.service.LLMService;
|
||||
import com.ai.da.service.SysFileService;
|
||||
import com.ai.da.service.WorkspaceService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
import org.checkerframework.checker.units.qual.C;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -71,6 +77,8 @@ public class LLMServiceImpl implements LLMService {
|
||||
private CollectionElementMapper collectionElementMapper;
|
||||
@Resource
|
||||
private CollectionElementRelModelMapper collectionElementRelModelMapper;
|
||||
@Value("${minio.bucketName.sysImage}")
|
||||
private String sysImage;
|
||||
|
||||
@Override
|
||||
public SseEmitter stream(String prompt, Long projectParamId, String fileUrl, List<String> imageUrlList, String token, Boolean enableThinking, String process) {
|
||||
@@ -78,12 +86,12 @@ public class LLMServiceImpl implements LLMService {
|
||||
|
||||
executor.submit(() -> {
|
||||
try {
|
||||
boolean validate = jwtTokenHelper.validateToken(token);
|
||||
boolean validate = jwtTokenHelper.validateToken(token); //
|
||||
if (validate) {
|
||||
AuthPrincipalVo principal = jwtTokenHelper.parserToUser(token);
|
||||
Long accountId = principal.getId();
|
||||
String url = "http://18.167.251.121:10002/chat-stream";
|
||||
// String url = "http://10.1.1.240:1013/chat-stream";
|
||||
// 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);
|
||||
@@ -222,10 +230,12 @@ public class LLMServiceImpl implements LLMService {
|
||||
@Override
|
||||
public SseEmitter streamNew(String prompt, Long projectParamId, String fileUrl, List<String> imageUrlList, String token, Boolean enableThinking, String process) {
|
||||
SseEmitter emitter = new SseEmitter(0L); // 永不超时
|
||||
List<String> designTools = Arrays.asList("moodboard", "printboard", "generate_color_code", "sketchboard");
|
||||
|
||||
executor.submit(() -> {
|
||||
try {
|
||||
boolean validate = jwtTokenHelper.validateToken(token);
|
||||
// boolean validate = jwtTokenHelper.validateToken(token);
|
||||
boolean validate = true;
|
||||
if (validate) {
|
||||
AuthPrincipalVo principal = jwtTokenHelper.parserToUser(token);
|
||||
Long accountId = principal.getId();
|
||||
@@ -327,7 +337,9 @@ public class LLMServiceImpl implements LLMService {
|
||||
}
|
||||
String toolsName = json.getString("tools_name");
|
||||
JSONObject toolsData = json.getJSONObject("content");
|
||||
if (Objects.nonNull(toolsName) && !toolsName.equals("design_control_signal") && !toolsName.equals("generate_project_info")) {
|
||||
/*&& !toolsName.equals("design_control_signal")
|
||||
&& !toolsName.equals("generate_project_info")*/
|
||||
if (Objects.nonNull(toolsName) && designTools.contains(toolsName)) {
|
||||
boolean color = true;
|
||||
ReceiveDesignParam receiveDesignParam = JSONObject.parseObject(JSONObject.toJSONString(toolsData), ReceiveDesignParam.class);
|
||||
receiveDesignParam.setProjectId(projectId);
|
||||
@@ -354,6 +366,11 @@ public class LLMServiceImpl implements LLMService {
|
||||
systemImage.setContent(contentSave);
|
||||
systemImage.setAccountId(accountId);
|
||||
chatMessageMapper.insert(systemImage);
|
||||
} else if (Objects.nonNull(toolsName) && toolsName.equals("search_sketch_img")) {
|
||||
json.put("content", processSearchSketchToolCon(toolsData));
|
||||
} else if (Objects.nonNull(toolsName)
|
||||
&& toolsName.equals("update_project_info")) {
|
||||
updateProjectParams(projectId, toolsData);
|
||||
}
|
||||
emitter.send(json.toJSONString());
|
||||
}
|
||||
@@ -368,7 +385,6 @@ public class LLMServiceImpl implements LLMService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
emitter.complete();
|
||||
} catch (Exception e) {
|
||||
System.out.println("走进异常");
|
||||
@@ -379,6 +395,72 @@ public class LLMServiceImpl implements LLMService {
|
||||
return emitter;
|
||||
}
|
||||
|
||||
private String processSearchSketchToolCon(JSONObject content){
|
||||
// content内容 "{\"sketch_list\": [\"\\\\female\\\\blouse\\\\blouse_645.jpg\", \"\\\\female\\\\dress\\\\0902004968.jpg\"]}"
|
||||
JSONArray sketchList = content.getJSONArray("sketch_list");
|
||||
if (sketchList.isEmpty()){
|
||||
return null;
|
||||
}
|
||||
ArrayList<ReceiveCollectionElement> dataList = new ArrayList<>();
|
||||
sketchList.forEach(sketch -> {
|
||||
ReceiveCollectionElement receiveCollectionElement = new ReceiveCollectionElement();
|
||||
receiveCollectionElement.setUrl((String) sketch);
|
||||
receiveCollectionElement.setMinioUrl(minioUtil.getPreSignedUrl(sysImage + "/images" + sketch, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
dataList.add(receiveCollectionElement);
|
||||
});
|
||||
ReceiveDesignParam receiveDesignParam = new ReceiveDesignParam();
|
||||
receiveDesignParam.setReceiveCollectionElementList(dataList);
|
||||
return JSONArray.toJSONString(receiveDesignParam);
|
||||
}
|
||||
|
||||
@Resource
|
||||
private WorkspaceService workspaceService;
|
||||
private String updateProjectParams(Long projectId, JSONObject jsonObject){
|
||||
// 1. 获取 project_info 并转换为 List<Map<String, String>>
|
||||
List<Map<String, String>> projectInfoList = (List<Map<String, String>>) jsonObject.get("project_info");
|
||||
|
||||
Long workspaceId = workspaceService.getByProjectId(projectId);
|
||||
if (Objects.isNull(workspaceId)){
|
||||
throw new BusinessException("未知projectId");
|
||||
}
|
||||
Workspace workspace = workspaceService.getBaseMapper().selectOne(new QueryWrapper<Workspace>().eq("project_id", projectId));
|
||||
if (!projectInfoList.isEmpty()){
|
||||
projectInfoList.forEach(info ->
|
||||
info.forEach((key, value) -> {
|
||||
switch (key){
|
||||
case "project_name":
|
||||
Project project = projectMapper.selectById(projectId);
|
||||
project.setName(value);
|
||||
project.setUpdateTime(LocalDateTime.now());
|
||||
projectMapper.updateById(project);
|
||||
break;
|
||||
case "ageGroup":
|
||||
workspace.setAgeGroup(value);
|
||||
break;
|
||||
case "gender":
|
||||
workspace.setSex(value);
|
||||
break;
|
||||
case "position":
|
||||
workspace.setPosition(value);
|
||||
break;
|
||||
case "style":
|
||||
QueryWrapper<Style> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(Style::getName, value);
|
||||
Style style = styleMapper.selectOne(qw);
|
||||
if (Objects.nonNull(style)) {
|
||||
WorkspaceRelStyle workspaceRelStyle = workspaceRelStyleMapper.selectOne(new QueryWrapper<WorkspaceRelStyle>().eq("workspace_id", workspaceId));
|
||||
workspaceRelStyle.setStyleId(style.getId());
|
||||
workspaceRelStyleMapper.updateById(workspaceRelStyle);
|
||||
}
|
||||
break;
|
||||
}
|
||||
})
|
||||
);
|
||||
workspaceMapper.updateById(workspace);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long chatCreateProject(String prompt, String process, String fileUrl, List<String> imageUrlList) {
|
||||
AuthPrincipalVo userHolder = UserContext.getUserHolder();
|
||||
|
||||
Reference in New Issue
Block a user