From 8a3e6833eed79c354da5557d0a97a5ef5ac1e1a4 Mon Sep 17 00:00:00 2001 From: xupei <1779019091@qq.com> Date: Tue, 21 Nov 2023 16:47:43 +0800 Subject: [PATCH] =?UTF-8?q?TASK:=E6=9C=BA=E5=99=A8=E4=BA=BA=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=9F=A5=E8=AF=A2=E7=94=B7=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ai/da/model/dto/ChatSendDTO.java | 4 +++ .../java/com/ai/da/python/PythonService.java | 21 +++++++---- .../da/service/impl/ChatRobotServiceImpl.java | 35 ++++++++++++++++--- src/main/resources/messages_en.properties | 4 ++- 4 files changed, 51 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/ai/da/model/dto/ChatSendDTO.java b/src/main/java/com/ai/da/model/dto/ChatSendDTO.java index af2c4b9f..0c59658e 100644 --- a/src/main/java/com/ai/da/model/dto/ChatSendDTO.java +++ b/src/main/java/com/ai/da/model/dto/ChatSendDTO.java @@ -31,4 +31,8 @@ public class ChatSendDTO { @ApiModelProperty("消息") private String message; + @NotBlank(message = "gender.cannot.be.empty") + @ApiModelProperty("性别") + private String gender; + } diff --git a/src/main/java/com/ai/da/python/PythonService.java b/src/main/java/com/ai/da/python/PythonService.java index d9439a58..5a1080f9 100644 --- a/src/main/java/com/ai/da/python/PythonService.java +++ b/src/main/java/com/ai/da/python/PythonService.java @@ -2229,30 +2229,37 @@ public class PythonService { .addHeader("Content-Type", "application/json") .build(); Response response = null; - String bodyString = null; + String bodyString ; try { log.info("generateSketchOrPrint请求入参content###{}", JSON.toJSONString(content, SerializerFeature.WriteMapNullValue)); response = client.newCall(request).execute(); - bodyString = response.body().string(); } catch (IOException ioException) { log.error("PythonService##generateSketchOrPrint异常###{}", ExceptionUtil.getThrowableList(ioException)); } //去除限流 AccessLimitUtils.validateOut("generateSketchOrPrint"); - // 生成失败 - if (Objects.isNull(response) || StringUtil.isNullOrEmpty(bodyString)) { + + // 判断是否生成失败 + if (Objects.isNull(response) || Objects.isNull(response.body())) { log.error("PythonService##generateSketchOrPrint异常###{}", "response or body is empty!"); - throw new BusinessException("generate exception!"); + throw new BusinessException("generate.interface.error"); + } else { + try { + bodyString = response.body().string(); + } catch (IOException e) { + throw new BusinessException("generate.interface.error"); + } } JSONObject jsonObject = JSON.parseObject(bodyString); Boolean result = JSON.parseObject(JSON.toJSONString(response)).getBoolean("successful"); -// Boolean result = Boolean.TRUE; + if (result && jsonObject.get("code").equals(200)) { return setGenerateImageList(jsonObject.getJSONObject("data")); } log.info("generateSketchOrPrintPrint失败###{}", jsonObject); + log.info("Generate Exception! Code : " + jsonObject.get("code")); //生成失败 - throw new BusinessException("Generate Exception! Code : " + jsonObject.get("code")); + throw new BusinessException("generate.interface.error"); } public Response sendPostToModel(String content, String portAndRoute, String functionName) { diff --git a/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java b/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java index 593847e3..c1ca9644 100644 --- a/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java @@ -139,6 +139,7 @@ public class ChatRobotServiceImpl implements ChatRobotService { log.info("chatRobot请求python 参数:####{}", param); RequestBody body = RequestBody.create(mediaType, param); Request request = new Request.Builder() +// .url("http://127.0.0.1:5000/api/chat_stream_test") .url("http://18.167.251.121:9991/api/chat_stream_test") // .url(accessPythonIp + ":10200/aifda/api/v1.0/generate") .method("POST", body) @@ -152,7 +153,7 @@ public class ChatRobotServiceImpl implements ChatRobotService { } if (Objects.isNull(response)) { log.error("PythonService##chatRobot异常###{}", "response is empty!"); - throw new BusinessException("system error!"); + throw new BusinessException("chat-bot.interface.exception"); } if (response.isSuccessful()) { try { @@ -193,7 +194,9 @@ public class ChatRobotServiceImpl implements ChatRobotService { } ChatRobotLibraryVO chatRobotLibraryVO = new ChatRobotLibraryVO(); String bucketName = sysImage; - String path = "images/female/" + array.getString(i); + String prefix = getPrefix(array.getString(i)); + String path = prefix; +// String path = prefix + array.getString(i); QueryWrapper qw = new QueryWrapper<>(); qw.lambda().eq(Library::getUrl, bucketName + "/" + path); qw.lambda().eq(Library::getAccountId, chatSendDTO.getUser_id()); @@ -220,12 +223,14 @@ public class ChatRobotServiceImpl implements ChatRobotService { } return chatRobotVO; } - throw new BusinessException("ChatRobot response data is null!"); + log.error("ChatRobot response data is null!"); + throw new BusinessException("chat-bot.interface.exception"); } catch (IOException e) { - throw new RuntimeException(e); + throw new BusinessException("chat-bot.interface.exception"); } } - throw new BusinessException("ChatRobot exception!"); + log.error("ChatRobot exception!"); + throw new BusinessException("chat-bot.interface.exception"); } private void checkBalance(BigDecimal totalCost, Long userId) { @@ -309,4 +314,24 @@ public class ChatRobotServiceImpl implements ChatRobotService { } } + private String getPrefix(String minioPath){ + String substring = minioPath.substring(minioPath.lastIndexOf("/") + 1, minioPath.lastIndexOf("_")); + String folder = minioPath.substring(0,minioPath.lastIndexOf("/")); + if ("mens_test".equals(substring)){ + switch (folder){ + case "bottom": + minioPath = minioPath.replace("bottom","bottoms"); + break; + case "top": + minioPath = minioPath.replace("top","tops"); + break; + case "outer": + minioPath = minioPath.replace("outer","outwear"); + break; + } + return "images/male/" + minioPath; + } + return "images/female/" + minioPath; + } + } diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index df62602c..5fbaa235 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -158,4 +158,6 @@ attributeRetrieval.interface.exception=We encountered an error retrieving attrib design.interface.exception=We encountered an error with the design interface. (Please try again later. If this issue persists, please contact us at help@aida.com.hk.) processMannequins.interface.exception=We encountered an error uploading mannequins. (Please try again later. If this issue persists, please contact us at help@aida.com.hk.) designProcess.interface.exception=There's been an issue loading the progress bar. (Please try again later. If this issue persists, please contact us at help@aida.com.hk.) -generate.interface.exception=We are currently experiencing a high volume of generating requests. (Please try again later. If the problem continues, reach out to us at help@aida.com.hk for support.) \ No newline at end of file +generate.interface.exception=We are currently experiencing a high volume of generating requests. (Please try again later. If the problem continues, reach out to us at help@aida.com.hk for support.) +generate.interface.error=We encountered an error with the generate interface. (Please try again later. If this issue persists, please contact us at help@aida.com.hk.) +chat-bot.interface.exception=I encountered an error.(Please try again later. If this issue persists, please contact us at help@aida.com.hk.) \ No newline at end of file