1、generate 异步生成及获取排队情况

2、generate 取消生成
This commit is contained in:
2024-01-21 14:14:55 +08:00
parent c31ecfb1e9
commit 577dc94850
21 changed files with 929 additions and 36 deletions

View File

@@ -23,7 +23,6 @@ import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.springframework.beans.factory.annotation.Value;
@@ -2238,7 +2237,7 @@ public class PythonService {
throw new BusinessException("system error!");
}
public List<String> generateSketchOrPrint(Long userId, String url, String category, String text, int mode, String modelName, String gender) {
public List<String> generateSketchOrPrint(GenerateToPythonDTO generateToPythonDTO) {
//限流校验
AccessLimitUtils.validate("generateSketchOrPrint", 5);
OkHttpClient client = new OkHttpClient().newBuilder()
@@ -2248,18 +2247,10 @@ public class PythonService {
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
.build();
MediaType mediaType = MediaType.parse("application/json");
Map<String, Object> content = Maps.newHashMap();
content.put("user_id", userId);
content.put("image_url", url);
content.put("category", category);
content.put("mode", mode);
content.put("str", text);
content.put("version", "1");
content.put("gender", gender);
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content, SerializerFeature.WriteMapNullValue));
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(generateToPythonDTO, SerializerFeature.WriteMapNullValue));
Request request = new Request.Builder()
// .url(accessPythonIp + ":2828/aida/diffusion")
// .url("http://18.167.251.121:9992")
// .url("http://127.0.0.1:5000/api/diffusion")
.url(accessPythonIp + ":" + accessPythonPort + "/api/diffusion")
.method("POST", body)
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
@@ -2268,10 +2259,11 @@ public class PythonService {
Response response = null;
String bodyString ;
try {
log.info("generateSketchOrPrint请求入参content###{}", JSON.toJSONString(content, SerializerFeature.WriteMapNullValue));
log.info("generateSketchOrPrint请求入参content###{}", JSON.toJSONString(generateToPythonDTO, SerializerFeature.WriteMapNullValue));
response = client.newCall(request).execute();
} catch (IOException ioException) {
log.error("PythonService##generateSketchOrPrint异常###{}", ExceptionUtil.getThrowableList(ioException));
throw new BusinessException("generate.interface.error");
}
//去除限流
AccessLimitUtils.validateOut("generateSketchOrPrint");