【优化】处理 nonce id 必须是一个长整型id问题

This commit is contained in:
cherishsince 2024-05-08 18:12:12 +08:00
parent b058090a77
commit 84a3cd3a75
3 changed files with 6 additions and 5 deletions

View File

@ -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);
}

View File

@ -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");
// 设置参数

View File

@ -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()), "童话里应该是什么样子?");
}