generate 接口疏通

This commit is contained in:
xupei
2023-09-19 15:52:33 +08:00
parent aef2bb7457
commit 3afe1c715d

View File

@@ -1636,7 +1636,7 @@ public class PythonService {
content.put("user_id", userId); content.put("user_id", userId);
content.put("image_url", url); content.put("image_url", url);
content.put("category", category); content.put("category", category);
content.put("mode",mode); // content.put("mode",mode);
content.put("str", text); content.put("str", text);
content.put("version",2); content.put("version",2);
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content)); RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content));
@@ -1650,32 +1650,32 @@ public class PythonService {
.build(); .build();
Response response = null; Response response = null;
String bodyString = null; String bodyString = null;
// try { try {
log.info("generateSketchOrPrint请求入参content###{}", JSON.toJSONString(content)); log.info("generateSketchOrPrint请求入参content###{}", JSON.toJSONString(content));
// response = client.newCall(request).execute(); response = client.newCall(request).execute();
// bodyString = response.body().string(); bodyString = response.body().string();
bodyString = "{\n" + // bodyString = "{\n" +
" \"code\": 200,\n" + // " \"code\": 200,\n" +
" \"data\": {\n" + // " \"data\": {\n" +
" \"list\": [\n" + // " \"list\": [\n" +
" \"aida-users/12/print_1695088687_0.png\"\n" + // " \"aida-users/12/print_1695088687_0.png\"\n" +
" ]\n" + // " ]\n" +
" },\n" + // " },\n" +
" \"msg\": \"OK!\"\n" + // " \"msg\": \"OK!\"\n" +
"}"; // "}";
// } catch (IOException ioException) { } catch (IOException ioException) {
// log.error("PythonService##generateSketchOrPrint异常###{}", ExceptionUtil.getThrowableList(ioException)); log.error("PythonService##generateSketchOrPrint异常###{}", ExceptionUtil.getThrowableList(ioException));
// } }
//去除限流 //去除限流
AccessLimitUtils.validateOut("generateSketchOrPrint"); AccessLimitUtils.validateOut("generateSketchOrPrint");
// 生成失败 // 生成失败
// if (Objects.isNull(response) || StringUtil.isNullOrEmpty(bodyString)) { if (Objects.isNull(response) || StringUtil.isNullOrEmpty(bodyString)) {
// log.error("PythonService##generateSketchOrPrint异常###{}", "response or body is empty!"); log.error("PythonService##generateSketchOrPrint异常###{}", "response or body is empty!");
// throw new BusinessException("generate exception!"); throw new BusinessException("generate exception!");
// } }
JSONObject jsonObject = JSON.parseObject(bodyString); JSONObject jsonObject = JSON.parseObject(bodyString);
// Boolean result = JSON.parseObject(JSON.toJSONString(response)).getBoolean("successful"); Boolean result = JSON.parseObject(JSON.toJSONString(response)).getBoolean("successful");
Boolean result = Boolean.TRUE; // Boolean result = Boolean.TRUE;
if (result) { if (result) {
return setGenerateImageList(jsonObject.getJSONObject("data")); return setGenerateImageList(jsonObject.getJSONObject("data"));
} }