From 3e1641216a31290e3c5734a321d3740eb103f5f7 Mon Sep 17 00:00:00 2001 From: cherishsince Date: Tue, 2 Jul 2024 23:02:24 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E8=A7=A3=E5=86=B3todo=E3=80=91mj=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20base64=20=E5=8F=82=E8=80=83=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../image/vo/midjourney/AiMidjourneyImagineReqVO.java | 5 ++--- .../module/ai/service/image/AiImageServiceImpl.java | 10 ++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/midjourney/AiMidjourneyImagineReqVO.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/midjourney/AiMidjourneyImagineReqVO.java index 96c67acd3..5f9d12445 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/midjourney/AiMidjourneyImagineReqVO.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/midjourney/AiMidjourneyImagineReqVO.java @@ -31,8 +31,7 @@ public class AiMidjourneyImagineReqVO { @NotEmpty(message = "版本号不能为空") private String version; - // TODO @fan:参考图,建议用 referImageUrl。 - @Schema(description = "垫图(参考图)base64数组") - private List base64Array; + @Schema(description = "参考图") + private String referImageUrl; } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java index e101db2f8..6f5e9ac67 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java @@ -35,6 +35,7 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; @@ -191,9 +192,14 @@ public class AiImageServiceImpl implements AiImageService { imageMapper.insert(image); // 2. 调用 Midjourney Proxy 提交任务 + List base64Array = new ArrayList<>(8); + if (StrUtil.isNotBlank(reqVO.getReferImageUrl())) { + base64Array.add("data:image/jpeg;base64,".concat(Base64.encode(HttpUtil.downloadBytes(reqVO.getReferImageUrl())))); + } MidjourneyApi.ImagineRequest imagineRequest = new MidjourneyApi.ImagineRequest( - null, reqVO.getPrompt(),null, - MidjourneyApi.ImagineRequest.buildState(reqVO.getWidth(), reqVO.getHeight(), reqVO.getVersion(), reqVO.getModel())); + base64Array, reqVO.getPrompt(),null, + MidjourneyApi.ImagineRequest.buildState(reqVO.getWidth(), + reqVO.getHeight(), reqVO.getVersion(), reqVO.getModel())); MidjourneyApi.SubmitResponse imagineResponse = midjourneyApi.imagine(imagineRequest); // 3. 情况一【失败】:抛出业务异常