From 84a3cd3a757998cf51bde89dc1d74f91ab2ec4dd Mon Sep 17 00:00:00 2001 From: cherishsince Date: Wed, 8 May 2024 18:12:12 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91=E5=A4=84?= =?UTF-8?q?=E7=90=86=20nonce=20id=20=E5=BF=85=E9=A1=BB=E6=98=AF=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E9=95=BF=E6=95=B4=E5=9E=8Bid=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/module/ai/service/impl/AiImageServiceImpl.java | 6 ++++-- .../ai/midjourney/api/MidjourneyInteractionsApi.java | 3 +-- .../ai/midjourney/MidjourneyInteractionsTests.java | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiImageServiceImpl.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiImageServiceImpl.java index e0d797d18..19281d4df 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiImageServiceImpl.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiImageServiceImpl.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.ai.service.impl; +import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.ai.exception.AiException; import cn.iocoder.yudao.framework.ai.image.ImageGeneration; @@ -123,11 +124,12 @@ public class AiImageServiceImpl implements AiImageService { @Transactional(rollbackFor = Exception.class) public void midjourney(AiImageMidjourneyReqVO req) { // 保存数据库 + String messageId = String.valueOf(IdUtil.getSnowflakeNextId()); AiImageDO aiImageDO = doSave(req.getPrompt(), null, "midjoureny", null, AiImageDrawingStatusEnum.SUBMIT, null, - null, null, null); + messageId, null, null); // 提交 midjourney 任务 - Boolean imagine = midjourneyInteractionsApi.imagine(aiImageDO.getId(), req.getPrompt()); + Boolean imagine = midjourneyInteractionsApi.imagine(messageId, req.getPrompt()); if (!imagine) { throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_MIDJOURNEY_IMAGINE_FAIL); } diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/api/MidjourneyInteractionsApi.java b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/api/MidjourneyInteractionsApi.java index 8edeb22da..7a578c832 100644 --- a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/api/MidjourneyInteractionsApi.java +++ b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/midjourney/api/MidjourneyInteractionsApi.java @@ -38,8 +38,7 @@ public class MidjourneyInteractionsApi extends MidjourneyInteractions { this.url = midjourneyConfig.getServerUrl().concat(midjourneyConfig.getApiInteractions()); } - public Boolean imagine(Long id, String prompt) { - String nonce = String.valueOf(id); + public Boolean imagine(String nonce, String prompt) { // 获取请求模板 String requestTemplate = midjourneyConfig.getRequestTemplates().get("imagine"); // 设置参数 diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/midjourney/MidjourneyInteractionsTests.java b/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/midjourney/MidjourneyInteractionsTests.java index bfc5aaa85..fda7818f0 100644 --- a/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/midjourney/MidjourneyInteractionsTests.java +++ b/yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/midjourney/MidjourneyInteractionsTests.java @@ -40,7 +40,7 @@ public class MidjourneyInteractionsTests { @Test public void mjImageTest() { MidjourneyInteractionsApi mjImagineInteractions = new MidjourneyInteractionsApi(midjourneyConfig); - mjImagineInteractions.imagine(IdUtil.getSnowflakeNextId(), "童话里应该是什么样子?"); + mjImagineInteractions.imagine(String.valueOf(IdUtil.getSnowflakeNextId()), "童话里应该是什么样子?"); }