mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-31 09:30:05 +08:00
【优化】MidjourneyApi 保持 spring ai 代码风格,使用 record
This commit is contained in:
parent
937992fd16
commit
2f07896651
@ -1,12 +1,11 @@
|
||||
package cn.iocoder.yudao.framework.ai.core.model.midjourney.api;
|
||||
|
||||
import cn.iocoder.yudao.framework.ai.core.model.midjourney.MidjourneyProperties;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.midjourney.vo.MidjourneyActionRequest;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.midjourney.vo.MidjourneyImagineRequest;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.midjourney.vo.MidjourneyNotifyRequest;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.midjourney.vo.MidjourneySubmitResponse;
|
||||
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.ai.openai.api.ApiUtils;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
@ -14,6 +13,7 @@ import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Midjourney api
|
||||
@ -71,11 +71,11 @@ public class MidjourneyApi {
|
||||
* @param taskIds
|
||||
* @return
|
||||
*/
|
||||
public List<MidjourneyNotifyRequest> listByCondition(Collection<String> taskIds) {
|
||||
public List<NotifyRequest> listByCondition(Collection<String> taskIds) {
|
||||
// 1、发送 post 请求
|
||||
String res = post(URI_LIST_BY_CONDITION, ImmutableMap.of("ids", taskIds));
|
||||
// 2、转换 对象
|
||||
return JsonUtils.parseArray(res, MidjourneyNotifyRequest.class);
|
||||
return JsonUtils.parseArray(res, NotifyRequest.class);
|
||||
}
|
||||
|
||||
private String post(String uri, Object body) {
|
||||
@ -93,4 +93,205 @@ public class MidjourneyApi {
|
||||
.bodyToMono(String.class)
|
||||
.block();
|
||||
}
|
||||
|
||||
// ====== record 结构
|
||||
|
||||
/**
|
||||
* Midjourney - Imagine 请求
|
||||
*
|
||||
* @param base64Array 垫图(参考图)base64数组
|
||||
* @param notifyHook 通知地址
|
||||
* @param prompt 提示词
|
||||
* @param state 自定义参数
|
||||
*/
|
||||
public record MidjourneyImagineRequest(List<String> base64Array,
|
||||
String notifyHook,
|
||||
String prompt,
|
||||
String state) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Midjourney - Action 请求
|
||||
*
|
||||
* @param customId 操作按钮id
|
||||
* @param taskId 操作按钮id
|
||||
* @param notifyHook 通知地址
|
||||
* @param state 自定义参数
|
||||
*/
|
||||
public record MidjourneyActionRequest(String customId,
|
||||
String taskId,
|
||||
String notifyHook,
|
||||
String state) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Midjourney - Submit 返回
|
||||
*
|
||||
* @param code 状态码: 1(提交成功), 21(已存在), 22(排队中), other(错误)
|
||||
* @param description 描述
|
||||
* @param properties 扩展字段
|
||||
* @param result 任务ID
|
||||
*/
|
||||
public record MidjourneySubmitResponse(String code,
|
||||
String description,
|
||||
Map<String, Object> properties,
|
||||
String result) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Midjourney - 通知 request
|
||||
*
|
||||
* @param id job id
|
||||
* @param action 任务类型 {@link TaskActionEnum}
|
||||
* @param status 任务状态 {@link TaskStatusEnum}
|
||||
* @param prompt 提示词
|
||||
* @param promptEn 提示词-英文
|
||||
* @param description 任务描述
|
||||
* @param state 自定义参数
|
||||
* @param submitTime 提交时间
|
||||
* @param startTime 开始执行时间
|
||||
* @param finishTime 结束时间
|
||||
* @param imageUrl 图片url
|
||||
* @param progress 任务进度
|
||||
* @param failReason 失败原因
|
||||
* @param buttons 任务完成后的可执行按钮
|
||||
*/
|
||||
public record NotifyRequest(String id,
|
||||
String action,
|
||||
String status,
|
||||
|
||||
String prompt,
|
||||
String promptEn,
|
||||
|
||||
String description,
|
||||
String state,
|
||||
|
||||
Long submitTime,
|
||||
Long startTime,
|
||||
Long finishTime,
|
||||
|
||||
String imageUrl,
|
||||
String progress,
|
||||
String failReason,
|
||||
List<Button> buttons) {
|
||||
|
||||
/**
|
||||
* button
|
||||
*
|
||||
* @param customId MJ::JOB::upsample::1::85a4b4c1-8835-46c5-a15c-aea34fad1862 动作标识
|
||||
* @param emoji 图标 emoji
|
||||
* @param label Make Variations 文本
|
||||
* @param type 类型,系统内部使用
|
||||
* @param style 样式: 2(Primary)、3(Green)
|
||||
*/
|
||||
public record Button(String customId,
|
||||
String emoji,
|
||||
String label,
|
||||
String type,
|
||||
String style) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ====== enums
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum ModelEnum {
|
||||
|
||||
MIDJOURNEY("midjourney", "midjourney"),
|
||||
NIJI("Niji", "Niji"),
|
||||
|
||||
;
|
||||
|
||||
private String model;
|
||||
private String name;
|
||||
|
||||
public static ModelEnum valueOfModel(String model) {
|
||||
for (ModelEnum itemEnum : ModelEnum.values()) {
|
||||
if (itemEnum.getModel().equals(model)) {
|
||||
return itemEnum;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid MessageType value: " + model);
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum SubmitCodeEnum {
|
||||
|
||||
SUBMIT_SUCCESS("1", "提交成功"),
|
||||
ALREADY_EXISTS("21", "已存在"),
|
||||
QUEUING("22", "排队中"),
|
||||
;
|
||||
|
||||
public static final List<String> SUCCESS_CODES = Lists.newArrayList(
|
||||
SUBMIT_SUCCESS.code,
|
||||
ALREADY_EXISTS.code,
|
||||
QUEUING.code
|
||||
);
|
||||
|
||||
private final String code;
|
||||
private final String name;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum TaskActionEnum {
|
||||
/**
|
||||
* 生成图片.
|
||||
*/
|
||||
IMAGINE,
|
||||
/**
|
||||
* 选中放大.
|
||||
*/
|
||||
UPSCALE,
|
||||
/**
|
||||
* 选中其中的一张图,生成四张相似的.
|
||||
*/
|
||||
VARIATION,
|
||||
/**
|
||||
* 重新执行.
|
||||
*/
|
||||
REROLL,
|
||||
/**
|
||||
* 图转prompt.
|
||||
*/
|
||||
DESCRIBE,
|
||||
/**
|
||||
* 多图混合.
|
||||
*/
|
||||
BLEND
|
||||
}
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum TaskStatusEnum {
|
||||
/**
|
||||
* 未启动.
|
||||
*/
|
||||
NOT_START(0),
|
||||
/**
|
||||
* 已提交.
|
||||
*/
|
||||
SUBMITTED(1),
|
||||
/**
|
||||
* 执行中.
|
||||
*/
|
||||
IN_PROGRESS(3),
|
||||
/**
|
||||
* 失败.
|
||||
*/
|
||||
FAILURE(4),
|
||||
/**
|
||||
* 成功.
|
||||
*/
|
||||
SUCCESS(4);
|
||||
|
||||
@Getter
|
||||
private final int order;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,30 +0,0 @@
|
||||
package cn.iocoder.yudao.framework.ai.core.model.midjourney.enums;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 来源于 midjourney-proxy
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum MidjourneyModelEnum {
|
||||
|
||||
MIDJOURNEY("midjourney", "midjourney"),
|
||||
NIJI("Niji", "Niji"),
|
||||
|
||||
;
|
||||
|
||||
private String model;
|
||||
private String name;
|
||||
|
||||
public static MidjourneyModelEnum valueOfModel(String model) {
|
||||
for (MidjourneyModelEnum itemEnum : MidjourneyModelEnum.values()) {
|
||||
if (itemEnum.getModel().equals(model)) {
|
||||
return itemEnum;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid MessageType value: " + model);
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package cn.iocoder.yudao.framework.ai.core.model.midjourney.enums;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
// TODO @fan:待定
|
||||
/**
|
||||
* Midjourney 提交任务 code 枚举
|
||||
*
|
||||
* @author fansili
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum MidjourneySubmitCodeEnum {
|
||||
|
||||
SUBMIT_SUCCESS("1", "提交成功"),
|
||||
ALREADY_EXISTS("21", "已存在"),
|
||||
QUEUING("22", "排队中"),
|
||||
;
|
||||
|
||||
public static final List<String> SUCCESS_CODES = Lists.newArrayList(
|
||||
SUBMIT_SUCCESS.code,
|
||||
ALREADY_EXISTS.code,
|
||||
QUEUING.code
|
||||
);
|
||||
|
||||
private final String code;
|
||||
private final String name;
|
||||
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package cn.iocoder.yudao.framework.ai.core.model.midjourney.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 来源于 midjourney-proxy
|
||||
*/
|
||||
@Getter
|
||||
public enum MidjourneyTaskActionEnum {
|
||||
/**
|
||||
* 生成图片.
|
||||
*/
|
||||
IMAGINE,
|
||||
/**
|
||||
* 选中放大.
|
||||
*/
|
||||
UPSCALE,
|
||||
/**
|
||||
* 选中其中的一张图,生成四张相似的.
|
||||
*/
|
||||
VARIATION,
|
||||
/**
|
||||
* 重新执行.
|
||||
*/
|
||||
REROLL,
|
||||
/**
|
||||
* 图转prompt.
|
||||
*/
|
||||
DESCRIBE,
|
||||
/**
|
||||
* 多图混合.
|
||||
*/
|
||||
BLEND
|
||||
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package cn.iocoder.yudao.framework.ai.core.model.midjourney.enums;
|
||||
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 来源于 midjourney-proxy
|
||||
*/
|
||||
public enum MidjourneyTaskStatusEnum {
|
||||
/**
|
||||
* 未启动.
|
||||
*/
|
||||
NOT_START(0),
|
||||
/**
|
||||
* 已提交.
|
||||
*/
|
||||
SUBMITTED(1),
|
||||
/**
|
||||
* 执行中.
|
||||
*/
|
||||
IN_PROGRESS(3),
|
||||
/**
|
||||
* 失败.
|
||||
*/
|
||||
FAILURE(4),
|
||||
/**
|
||||
* 成功.
|
||||
*/
|
||||
SUCCESS(4);
|
||||
|
||||
@Getter
|
||||
private final int order;
|
||||
|
||||
MidjourneyTaskStatusEnum(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package cn.iocoder.yudao.framework.ai.core.model.midjourney.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Midjourney:action 请求
|
||||
*
|
||||
* @author fansili
|
||||
* @time 2024/5/30 14:02
|
||||
* @since 1.0
|
||||
*/
|
||||
@Data
|
||||
public class MidjourneyActionRequest {
|
||||
|
||||
@Schema(description = "操作按钮id", required = true)
|
||||
private String customId;
|
||||
|
||||
@Schema(description = "操作按钮id", required = true)
|
||||
private String taskId;
|
||||
|
||||
@Schema(description = "通知地址", required = false)
|
||||
private String notifyHook;
|
||||
|
||||
@Schema(description = "自定义参数", required = false)
|
||||
private String state;
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package cn.iocoder.yudao.framework.ai.core.model.midjourney.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
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 MidjourneyImagineRequest {
|
||||
|
||||
@Schema(description = "垫图(参考图)base64数组", required = false)
|
||||
private List<String> base64Array;
|
||||
|
||||
@Schema(description = "通知地址", required = false)
|
||||
private String notifyHook;
|
||||
|
||||
@Schema(description = "提示词", required = true)
|
||||
private String prompt;
|
||||
|
||||
@Schema(description = "自定义参数", required = false)
|
||||
private String state;
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
package cn.iocoder.yudao.framework.ai.core.model.midjourney.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 MidjourneyNotifyRequest {
|
||||
|
||||
@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<Button> buttons;
|
||||
|
||||
@Data
|
||||
public static class Button {
|
||||
|
||||
@Schema(description = "MJ::JOB::upsample::1::85a4b4c1-8835-46c5-a15c-aea34fad1862 动作标识")
|
||||
private String customId;
|
||||
|
||||
@Schema(description = "图标 emoji")
|
||||
private String emoji;
|
||||
|
||||
@Schema(description = "Make Variations 文本")
|
||||
private String label;
|
||||
|
||||
@Schema(description = "类型,系统内部使用")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "样式: 2(Primary)、3(Green)")
|
||||
private String style;
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package cn.iocoder.yudao.framework.ai.core.model.midjourney.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
// TODO @fan:待定
|
||||
/**
|
||||
* Midjourney:Imagine 请求
|
||||
*
|
||||
* @author fansili
|
||||
* @time 2024/5/30 14:02
|
||||
* @since 1.0
|
||||
*/
|
||||
@Data
|
||||
public class MidjourneySubmitResponse {
|
||||
|
||||
@Schema(description = "状态码: 1(提交成功), 21(已存在), 22(排队中), other(错误)")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "描述")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "扩展字段")
|
||||
private Map<String, Object> properties;
|
||||
|
||||
@Schema(description = "任务ID")
|
||||
private String result;
|
||||
}
|
Loading…
Reference in New Issue
Block a user