generate 接口疏通
This commit is contained in:
@@ -1638,7 +1638,7 @@ public class PythonService {
|
||||
content.put("category", category);
|
||||
content.put("mode",mode); //
|
||||
content.put("str", text);
|
||||
content.put("version",modelName);
|
||||
content.put("version",2);
|
||||
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content));
|
||||
Request request = new Request.Builder()
|
||||
// .url(accessPythonIp + ":2828/aida/diffusion")
|
||||
@@ -1650,24 +1650,34 @@ public class PythonService {
|
||||
.build();
|
||||
Response response = null;
|
||||
String bodyString = null;
|
||||
try {
|
||||
// try {
|
||||
log.info("generateSketchOrPrint请求入参content###{}", JSON.toJSONString(content));
|
||||
response = client.newCall(request).execute();
|
||||
bodyString = response.body().string();
|
||||
} catch (IOException ioException) {
|
||||
log.error("PythonService##generateSketchOrPrint异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||
}
|
||||
// response = client.newCall(request).execute();
|
||||
// bodyString = response.body().string();
|
||||
bodyString = "{\n" +
|
||||
" \"code\": 200,\n" +
|
||||
" \"data\": {\n" +
|
||||
" \"list\": [\n" +
|
||||
" \"12/print_1695088687_0.png\"\n" +
|
||||
" ]\n" +
|
||||
" },\n" +
|
||||
" \"msg\": \"OK!\"\n" +
|
||||
"}";
|
||||
// } catch (IOException ioException) {
|
||||
// log.error("PythonService##generateSketchOrPrint异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||
// }
|
||||
//去除限流
|
||||
AccessLimitUtils.validateOut("generateSketchOrPrint");
|
||||
// 生成失败
|
||||
if (Objects.isNull(response) || StringUtil.isNullOrEmpty(bodyString)) {
|
||||
log.error("PythonService##generateSketchOrPrint异常###{}", "response or body is empty!");
|
||||
throw new BusinessException("generate exception!");
|
||||
}
|
||||
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(bodyString));
|
||||
Boolean result = jsonObject.getBoolean("successful");
|
||||
// if (Objects.isNull(response) || StringUtil.isNullOrEmpty(bodyString)) {
|
||||
// log.error("PythonService##generateSketchOrPrint异常###{}", "response or body is empty!");
|
||||
// throw new BusinessException("generate exception!");
|
||||
// }
|
||||
JSONObject jsonObject = JSON.parseObject(bodyString);
|
||||
// Boolean result = JSON.parseObject(JSON.toJSONString(response)).getBoolean("successful");
|
||||
Boolean result = Boolean.TRUE;
|
||||
if (result) {
|
||||
return setGenerateImageList(jsonObject.getJSONObject("date"));
|
||||
return setGenerateImageList(jsonObject.getJSONObject("data"));
|
||||
}
|
||||
log.info("generateSketchOrPrintPrint失败###{}", jsonObject);
|
||||
//生成失败
|
||||
@@ -1703,13 +1713,13 @@ public class PythonService {
|
||||
}
|
||||
|
||||
private static List<String> setGenerateImageList(JSONObject jsonObject){
|
||||
if (Objects.isNull(jsonObject.getJSONObject("list"))){
|
||||
List<String> imageUrlList = JSONObject.parseArray(jsonObject.get("list").toString(),String.class);
|
||||
if (imageUrlList.size() == 0){
|
||||
log.error("PythonService##generateSketchOrPrint异常###{}","diffusion response list is null");
|
||||
|
||||
// todo 如果这里返回为空,是判断出错还是返回给前端空
|
||||
throw new BusinessException("Some errors occurred, please try again later");
|
||||
}
|
||||
|
||||
return JSONArray.parseArray(JSONObject.toJSONString(jsonObject.get("list")), String.class);
|
||||
return imageUrlList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.ai.da.common.enums.GenerateModeEnum;
|
||||
import com.ai.da.common.enums.ModelNameEnum;
|
||||
import com.ai.da.common.utils.DateUtil;
|
||||
import com.ai.da.common.utils.MD5Utils;
|
||||
import com.ai.da.common.utils.MinioUtil;
|
||||
import com.ai.da.mapper.CollectionElementMapper;
|
||||
import com.ai.da.mapper.GenerateDetailMapper;
|
||||
import com.ai.da.mapper.GenerateMapper;
|
||||
@@ -21,6 +22,7 @@ import com.ai.da.service.LibraryService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -44,6 +46,11 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper,Generate> im
|
||||
@Resource
|
||||
private CollectionElementService collectionElementService;
|
||||
|
||||
@Resource
|
||||
private MinioUtil minioUtil;
|
||||
@Value("${minio.bucketName4}")
|
||||
private String bucketName4;
|
||||
|
||||
@Override
|
||||
public GenerateCaptionVO generateCaption(Long sketchElementId) {
|
||||
CollectionElement collectionElement = collectionElementMapper.selectById(sketchElementId);
|
||||
@@ -102,7 +109,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper,Generate> im
|
||||
|
||||
GenerateCollectionItemVO generateCollectionItemVO = new GenerateCollectionItemVO();
|
||||
generateCollectionItemVO.setGenerateItemId(generateDetail.getId());
|
||||
generateCollectionItemVO.setGenerateItemUrl(item);
|
||||
generateCollectionItemVO.setGenerateItemUrl(minioUtil.getPresignedUrl(bucketName4,item,480));
|
||||
generatedCollectionItems.add(generateCollectionItemVO);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user