diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/imageopenai/OpenAiImageClient.java b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/imageopenai/OpenAiImageClient.java index c5ae757d1..4dd536f99 100644 --- a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/imageopenai/OpenAiImageClient.java +++ b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/imageopenai/OpenAiImageClient.java @@ -2,9 +2,11 @@ package cn.iocoder.yudao.framework.ai.imageopenai; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.codec.Base64; +import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpUtil; import cn.iocoder.yudao.framework.ai.chat.ChatException; import cn.iocoder.yudao.framework.ai.chatyiyan.exception.YiYanApiException; +import cn.iocoder.yudao.framework.ai.exception.AiException; import cn.iocoder.yudao.framework.ai.image.*; import cn.iocoder.yudao.framework.ai.imageopenai.api.OpenAiImageRequest; import cn.iocoder.yudao.framework.ai.imageopenai.api.OpenAiImageResponse; @@ -69,6 +71,10 @@ public class OpenAiImageClient implements ImageClient { request.setSize(openAiImageOptions.getSize()); // 发送请求 OpenAiImageResponse response = openAiImageApi.createImage(request); + if (response.getError() != null && !StrUtil.isBlank(response.getError().getMessage())) { + // code 错误没有编码,就先根据 message 来进行判断 + throw new AiException("openAi 图片生成失败! " + response.getError().getMessage()); + } return new ImageResponse(response.getData().stream().map(res -> { byte[] bytes = HttpUtil.downloadBytes(res.getUrl()); String base64 = Base64.encode(bytes); diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/imageopenai/api/OpenAiImageResponse.java b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/imageopenai/api/OpenAiImageResponse.java index 1f4ab6152..02698963e 100644 --- a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/imageopenai/api/OpenAiImageResponse.java +++ b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/imageopenai/api/OpenAiImageResponse.java @@ -17,6 +17,7 @@ public class OpenAiImageResponse { private long created; private List data; + private Error error; @Data @Accessors(chain = true) @@ -26,4 +27,13 @@ public class OpenAiImageResponse { private String b64_json; } + + @Data + @Accessors(chain = true) + public static class Error { + private String code; + private String message; + private String param; + private String type; + } }