diff --git a/yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/ErrorCodeConstants.java b/yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/ErrorCodeConstants.java index b08b36a03..6dbd08730 100644 --- a/yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/ErrorCodeConstants.java +++ b/yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/ErrorCodeConstants.java @@ -21,30 +21,21 @@ public interface ErrorCodeConstants { // ========== API 聊天模型 1-040-002-000 ========== ErrorCode CHAT_ROLE_NOT_EXISTS = new ErrorCode(1_040_002_000, "聊天角色不存在"); ErrorCode CHAT_ROLE_DISABLE = new ErrorCode(1_040_001_001, "聊天角色({})已禁用!"); - ErrorCode CHAT_ROLE_DEFAULT_NOT_EXISTS = new ErrorCode(1_040_001_002, "操作失败,找不到默认聊天角色"); // ========== API 聊天会话 1-040-003-000 ========== ErrorCode CHAT_CONVERSATION_NOT_EXISTS = new ErrorCode(1_040_003_000, "对话不存在!"); ErrorCode CHAT_CONVERSATION_MODEL_ERROR = new ErrorCode(1_040_003_001, "操作失败,该聊天模型的配置不完整"); - ErrorCode CHAT_CONVERSATION_UPDATE_MAX_TOKENS_ERROR = new ErrorCode(1_040_003_002, "更新对话失败,最大 Token 超过上限"); - ErrorCode CHAT_CONVERSATION_UPDATE_MAX_CONTEXTS_ERROR = new ErrorCode(1_040_003_002, "更新对话失败,最大 Context 超过上限"); // ========== API 聊天消息 1-040-004-000 ========== + ErrorCode AI_CHAT_MESSAGE_NOT_EXIST = new ErrorCode(1_040_004_000, "消息不存在!"); ErrorCode AI_CHAT_STREAM_ERROR = new ErrorCode(1_040_004_001, "Stream 对话异常!"); - // midjourney - - ErrorCode AI_MIDJOURNEY_IMAGINE_FAIL = new ErrorCode(1_022_000_040, "midjourney imagine 操作失败!"); - ErrorCode AI_MIDJOURNEY_OPERATION_NOT_EXISTS = new ErrorCode(1_022_000_040, "midjourney 操作不存在!"); - ErrorCode AI_MIDJOURNEY_MESSAGE_ID_INCORRECT = new ErrorCode(1_022_000_040, "midjourney message id 不正确!"); - // ========== API 绘画 1-040-005-000 ========== - ErrorCode AI_IMAGE_NOT_EXISTS = new ErrorCode(1_022_005_000, "image 不存在!"); - ErrorCode AI_IMAGE_MIDJOURNEY_SUBMIT_FAIL = new ErrorCode(1_022_005_001, "Midjourney 提交失败! {}"); + ErrorCode AI_IMAGE_NOT_EXISTS = new ErrorCode(1_022_005_000, "图片不存在!"); + ErrorCode AI_IMAGE_MIDJOURNEY_SUBMIT_FAIL = new ErrorCode(1_022_005_001, "Midjourney 提交失败!原因:{}"); ErrorCode AI_IMAGE_CUSTOM_ID_NOT_EXISTS = new ErrorCode(1_022_005_002, "Midjourney 按钮 customId 不存在! {}"); - ErrorCode AI_IMAGE_SYSTEM_ACCOUNT_INSUFFICIENT_BALANCE = new ErrorCode(1_022_005_003, "Midjourney 系统账户余额不足!"); } diff --git a/yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/image/AiImageStatusEnum.java b/yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/image/AiImageStatusEnum.java index 4fd942b39..2d6b3d822 100644 --- a/yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/image/AiImageStatusEnum.java +++ b/yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/image/AiImageStatusEnum.java @@ -12,20 +12,20 @@ import lombok.Getter; @Getter public enum AiImageStatusEnum { - IN_PROGRESS("10", "进行中"), - SUCCESS("20", "完成"), - FAIL("30", "失败"); + IN_PROGRESS(10, "进行中"), + SUCCESS(20, "完成"), + FAIL(30, "失败"); /** * 状态 */ - private final String status; + private final Integer status; /** * 状态名 */ private final String name; - public static AiImageStatusEnum valueOfStatus(String status) { + public static AiImageStatusEnum valueOfStatus(Integer status) { for (AiImageStatusEnum statusEnum : AiImageStatusEnum.values()) { if (statusEnum.getStatus().equals(status)) { return statusEnum; diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/config/YudaoMidjourneyConfiguration.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/config/YudaoMidjourneyConfiguration.java index fbdb49a67..84548fefd 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/config/YudaoMidjourneyConfiguration.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/config/YudaoMidjourneyConfiguration.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.ai.config; import cn.iocoder.yudao.framework.ai.core.model.midjourney.MidjourneyConfig; import cn.iocoder.yudao.framework.ai.core.model.midjourney.api.MidjourneyApi; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/AiImageController.http b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/AiImageController.http index 4af24f792..10fa24b5f 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/AiImageController.http +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/AiImageController.http @@ -29,12 +29,17 @@ Authorization: {{token}} "style": "vivid" } -### chat midjourney +### 生成图片:生成图片 -POST {{baseUrl}}/admin-api/ai/image/midjourney +POST {{baseUrl}}/ai/image/midjourney/imagine Content-Type: application/json Authorization: {{token}} { - "prompt": "Cute cartoon style mobile game scene, a colorful camping car with an outdoor table and chairs next to it on the road in a spring forest, the simple structure of the camper van, soft lighting, C4D rendering, 3d model in the style of a cartoon, cute shape, a pastel color scheme, closeup view from the side angle, high resolution, bright colors, a happy atmosphere." + "prompt": "中国旗袍", + "model": "midjourney", + "width": "1", + "height": "1", + "version": "6.0", + "base64Array": [] } \ No newline at end of file diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/AiImageController.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/AiImageController.java index 2445fe629..e5872e0dc 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/AiImageController.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/AiImageController.java @@ -1,14 +1,14 @@ package cn.iocoder.yudao.module.ai.controller.admin.image; import cn.hutool.core.util.ObjUtil; +import cn.iocoder.yudao.framework.ai.core.model.midjourney.api.MidjourneyApi; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.module.ai.controller.admin.image.vo.MidjourneyNotifyReqVO; import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageDrawReqVO; -import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageMidjourneyImagineReqVO; import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageRespVO; +import cn.iocoder.yudao.module.ai.controller.admin.image.vo.midjourney.AiImageMidjourneyImagineReqVO; import cn.iocoder.yudao.module.ai.dal.dataobject.image.AiImageDO; import cn.iocoder.yudao.module.ai.service.image.AiImageService; import io.swagger.v3.oas.annotations.Operation; @@ -63,19 +63,24 @@ public class AiImageController { return success(true); } - // ================ midjourney 接口 ================ + // ================ midjourney 专属 ================ - @Operation(summary = "Midjourney imagine(绘画)") + @Operation(summary = "【Midjourney】生成图片") @PostMapping("/midjourney/imagine") - public CommonResult midjourneyImagine(@Validated @RequestBody AiImageMidjourneyImagineReqVO req) { - return success(imageService.midjourneyImagine(getLoginUserId(), req)); + public CommonResult midjourneyImagine(@Validated @RequestBody AiImageMidjourneyImagineReqVO reqVO) { + if (true) { + imageService.midjourneySync(); + return null; + } + Long imageId = imageService.midjourneyImagine(getLoginUserId(), reqVO); + return success(imageId); } - @Operation(summary = "Midjourney 回调通知", description = "由 Midjourney Proxy 回调") + @Operation(summary = "Midjourney 生成图片的回调通知", description = "由 Midjourney Proxy 回调") @PostMapping("/midjourney-notify") @PermitAll - public void midjourneyNotify(@RequestBody MidjourneyNotifyReqVO notifyReqVO) { - imageService.midjourneyNotify(notifyReqVO); + public void midjourneyNotify(@RequestBody MidjourneyApi.Notify notify) { + imageService.midjourneyNotify(notify); } @Operation(summary = "Midjourney Action", description = "例如说:放大、缩小、U1、U2 等") diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageMidjourneyImagineReqVO.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageMidjourneyImagineReqVO.java deleted file mode 100644 index 64c519d57..000000000 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageMidjourneyImagineReqVO.java +++ /dev/null @@ -1,40 +0,0 @@ -package cn.iocoder.yudao.module.ai.controller.admin.image.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotNull; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.List; - -// TODO @fan:待定 -/** - * midjourney req - * - * @author fansili - * @time 2024/4/28 17:42 - * @since 1.0 - */ -@Data -@Accessors(chain = true) -public class AiImageMidjourneyImagineReqVO { - - @Schema(description = "提示词") - @NotNull(message = "提示词不能为空!") - private String prompt; - - @Schema(description = "模型(midjourney、niji)") - private String model; - - @Schema(description = "图片宽度 --ar 设置") - private Integer width; - - @Schema(description = "图片高度 --ar 设置") - private Integer height; - - @Schema(description = "版本号 --v 设置") - private String version; - - @Schema(description = "垫图(参考图)base64数组") - private List base64Array; -} diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageMidjourneyOperationsVO.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageMidjourneyOperationsVO.java deleted file mode 100644 index fe202d83d..000000000 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageMidjourneyOperationsVO.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.ai.controller.admin.image.vo; - -import lombok.Data; -import lombok.experimental.Accessors; - -/** - * mj 保存 components 记录 - * - * "components": [ - * { - * "custom_id": "MJ::JOB::upsample::1::5d32f4e8-8d2f-4bef-82d8-bf517e3c3660", - * "style": 2, - * "label": "U1", - * "type": 2 - * }, - * ] - * - * @author fansili - * @time 2024/5/8 14:44 - * @since 1.0 - */ -@Data -@Accessors(chain = true) -public class AiImageMidjourneyOperationsVO { - - private String custom_id; - private String style; - private String label; - private String type; -} diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageRespVO.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageRespVO.java index 3f011a57e..9d761a891 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageRespVO.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageRespVO.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.ai.controller.admin.image.vo; +import cn.iocoder.yudao.framework.ai.core.model.midjourney.api.MidjourneyApi; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -46,14 +47,11 @@ public class AiImageRespVO { @Schema(description = "绘制参数") private Map options; - @Schema(description = "绘画 response") - private MidjourneyNotifyReqVO response; - // TODO @fan:进度是百分比,还是一个数字哈?感觉这个可以统一成通用字段; @Schema(description = "mj 进度") private String progress; @Schema(description = "mj buttons 按钮") - private List buttons; + private List buttons; } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/MidjourneyImagineReqVO.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/MidjourneyImagineReqVO.java deleted file mode 100644 index bc2ac0139..000000000 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/MidjourneyImagineReqVO.java +++ /dev/null @@ -1,33 +0,0 @@ -package cn.iocoder.yudao.module.ai.controller.admin.image.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -import java.util.List; - -// TODO @fan:待定 -/** - * Midjourney:Imagine 请求 - * - * @author fansili - * @time 2024/5/30 14:02 - * @since 1.0 - */ -@Data -public class MidjourneyImagineReqVO { - - @Schema(description = "垫图(参考图)base64数组", required = false) - private List base64Array; - - @Schema(description = "通知地址", required = false) - @NotNull(message = "回调地址不能为空!") - private String notifyHook; - - @Schema(description = "提示词", required = true) - @NotNull(message = "提示词不能为空!") - private String prompt; - - @Schema(description = "自定义参数", required = false) - private String state; -} diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/MidjourneyNotifyReqVO.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/MidjourneyNotifyReqVO.java deleted file mode 100644 index ebc9a83c6..000000000 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/MidjourneyNotifyReqVO.java +++ /dev/null @@ -1,75 +0,0 @@ -package cn.iocoder.yudao.module.ai.controller.admin.image.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.util.List; - -/** - * Midjourney Proxy 通知回调 - * - * - Midjourney Proxy:通知回调 bean 是 com.github.novicezk.midjourney.support.Task - * - 毫秒 api 通知回调文档地址:https://gpt-best.apifox.cn/doc-3530863 - * - * @author fansili - * @time 2024/5/31 10:37 - * @since 1.0 - */ -@Data -public class MidjourneyNotifyReqVO { - - @Schema(description = "job id") - private String id; - - @Schema(description = "任务类型 MidjourneyTaskActionEnum") - private String action; - @Schema(description = "任务状态 MidjourneyTaskStatusEnum") - private String status; - - @Schema(description = "提示词") - private String prompt; - @Schema(description = "提示词-英文") - private String promptEn; - - @Schema(description = "任务描述") - private String description; - @Schema(description = "自定义参数") - private String state; - - @Schema(description = "提交时间") - private Long submitTime; - @Schema(description = "开始执行时间") - private Long startTime; - @Schema(description = "结束时间") - private Long finishTime; - - @Schema(description = "图片url") - private String imageUrl; - - @Schema(description = "任务进度") - private String progress; - @Schema(description = "失败原因") - private String failReason; - - @Schema(description = "任务完成后的可执行按钮") - private List