Commit 4d9dbeaa8d59b6b05ef1fc4ce61881fe5ae78fb7
1 parent
73580841
【增加】MidjourneyApi 自动配置
Showing
5 changed files
with
45 additions
and
124 deletions
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/config/YudaoAiImageProperties.java deleted
| 1 | -package cn.iocoder.yudao.framework.ai.config; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum; | |
| 4 | -import cn.iocoder.yudao.framework.ai.core.model.xinghuo.XingHuoChatModel; | |
| 5 | -import cn.iocoder.yudao.framework.ai.core.model.xinghuo.XingHuoOptions; | |
| 6 | -import cn.iocoder.yudao.framework.ai.core.model.yiyan.api.YiYanChatModel; | |
| 7 | -import lombok.Data; | |
| 8 | -import lombok.experimental.Accessors; | |
| 9 | - | |
| 10 | -import java.util.LinkedHashMap; | |
| 11 | -import java.util.Map; | |
| 12 | - | |
| 13 | -/** | |
| 14 | - * ai 自动配置 | |
| 15 | - * | |
| 16 | - * @author fansili | |
| 17 | - * @time 2024/4/12 16:29 | |
| 18 | - * @since 1.0 | |
| 19 | - */ | |
| 20 | - | |
| 21 | -@Data | |
| 22 | -@Accessors(chain = true) | |
| 23 | -public class YudaoAiImageProperties extends LinkedHashMap<String, Map<String, Object>> { | |
| 24 | - | |
| 25 | - private String initType; | |
| 26 | - private QianWenProperties qianwen; | |
| 27 | - private XingHuoOptions xinghuo; | |
| 28 | - private YiYanProperties yiyan; | |
| 29 | - | |
| 30 | - @Data | |
| 31 | - @Accessors(chain = true) | |
| 32 | - public static class QianWenProperties extends ChatProperties { | |
| 33 | - /** | |
| 34 | - * 阿里云:服务器接入点 | |
| 35 | - */ | |
| 36 | - private String endpoint = "bailian.cn-beijing.aliyuncs.com"; | |
| 37 | - /** | |
| 38 | - * 阿里云:权限 accessKeyId | |
| 39 | - */ | |
| 40 | - private String accessKeyId; | |
| 41 | - /** | |
| 42 | - * 阿里云:权限 accessKeySecret | |
| 43 | - */ | |
| 44 | - private String accessKeySecret; | |
| 45 | - /** | |
| 46 | - * 阿里云:agentKey | |
| 47 | - */ | |
| 48 | - private String agentKey; | |
| 49 | - /** | |
| 50 | - * 阿里云:agentKey(相当于应用id) | |
| 51 | - */ | |
| 52 | - private String appId; | |
| 53 | - | |
| 54 | - } | |
| 55 | - | |
| 56 | - @Data | |
| 57 | - @Accessors(chain = true) | |
| 58 | - public static class XingHuoProperties extends ChatProperties { | |
| 59 | - private String appId; | |
| 60 | - private String appKey; | |
| 61 | - private String secretKey; | |
| 62 | - private XingHuoChatModel chatModel; | |
| 63 | - } | |
| 64 | - | |
| 65 | - @Data | |
| 66 | - @Accessors(chain = true) | |
| 67 | - public static class YiYanProperties extends ChatProperties { | |
| 68 | - /** | |
| 69 | - * appKey | |
| 70 | - */ | |
| 71 | - private String appKey; | |
| 72 | - /** | |
| 73 | - * secretKey | |
| 74 | - */ | |
| 75 | - private String secretKey; | |
| 76 | - /** | |
| 77 | - * 模型 | |
| 78 | - */ | |
| 79 | - private YiYanChatModel chatModel = YiYanChatModel.ERNIE4_3_5_8K; | |
| 80 | - /** | |
| 81 | - * token 刷新时间(默认 86400 = 24小时) | |
| 82 | - */ | |
| 83 | - private int refreshTokenSecondTime = 86400; | |
| 84 | - } | |
| 85 | - | |
| 86 | - @Data | |
| 87 | - @Accessors(chain = true) | |
| 88 | - public static class ChatProperties { | |
| 89 | - | |
| 90 | - private AiPlatformEnum aiPlatform; | |
| 91 | - | |
| 92 | - private Float temperature; | |
| 93 | - | |
| 94 | - private Float topP; | |
| 95 | - | |
| 96 | - private Integer topK; | |
| 97 | - } | |
| 98 | -} |
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/config/YudaoMidjourneyConfiguration.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.ai.config; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.ai.core.model.midjourney.MidjourneyConfig; | |
| 4 | +import cn.iocoder.yudao.framework.ai.core.model.midjourney.api.MidjourneyApi; | |
| 5 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 6 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | |
| 7 | +import org.springframework.context.annotation.Bean; | |
| 8 | +import org.springframework.context.annotation.Configuration; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 配置 | |
| 12 | + * | |
| 13 | + * @author fansili | |
| 14 | + * @time 2024/6/13 09:50 | |
| 15 | + */ | |
| 16 | +@Configuration | |
| 17 | +public class YudaoMidjourneyConfiguration { | |
| 18 | + | |
| 19 | + @Bean | |
| 20 | + @ConditionalOnProperty(value = "ai.midjourney-proxy.enable", havingValue = "true") | |
| 21 | + public MidjourneyApi midjourneyApi(YudaoMidjourneyProperties midjourneyProperties) { | |
| 22 | + return new MidjourneyApi(BeanUtils.toBean(midjourneyProperties, MidjourneyConfig.class)); | |
| 23 | + } | |
| 24 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/config/MidjourneyProperties.java renamed to yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/config/YudaoMidjourneyProperties.java
| 1 | -package cn.iocoder.yudao.module.ai.config; | |
| 1 | +package cn.iocoder.yudao.framework.ai.config; | |
| 2 | 2 | |
| 3 | 3 | import lombok.Data; |
| 4 | 4 | import org.springframework.boot.context.properties.ConfigurationProperties; |
| ... | ... | @@ -14,9 +14,9 @@ import org.springframework.context.annotation.Configuration; |
| 14 | 14 | @Configuration |
| 15 | 15 | @ConfigurationProperties(prefix = "ai.midjourney-proxy") |
| 16 | 16 | @Data |
| 17 | -public class MidjourneyProperties { | |
| 17 | +public class YudaoMidjourneyProperties { | |
| 18 | 18 | |
| 19 | + private String enable; | |
| 19 | 20 | private String key; |
| 20 | 21 | private String url; |
| 21 | - private String notifyUrl; | |
| 22 | 22 | } | ... | ... |
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/midjourney/MidjourneyConfig.java
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/midjourney/api/MidjourneyApi.java
| ... | ... | @@ -46,11 +46,11 @@ public class MidjourneyApi { |
| 46 | 46 | * @param imagineReqVO |
| 47 | 47 | * @return |
| 48 | 48 | */ |
| 49 | - public MidjourneySubmitResponse imagine(MidjourneyImagineRequest imagineReqVO) { | |
| 49 | + public SubmitResponse imagine(ImagineRequest imagineReqVO) { | |
| 50 | 50 | // 1、发送 post 请求 |
| 51 | 51 | String res = post(URI_IMAGINE, imagineReqVO); |
| 52 | 52 | // 2、转换 resp |
| 53 | - return JsonUtils.parseObject(res, MidjourneySubmitResponse.class); | |
| 53 | + return JsonUtils.parseObject(res, SubmitResponse.class); | |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
| ... | ... | @@ -58,11 +58,11 @@ public class MidjourneyApi { |
| 58 | 58 | * |
| 59 | 59 | * @param actionReqVO |
| 60 | 60 | */ |
| 61 | - public MidjourneySubmitResponse action(MidjourneyActionRequest actionReqVO) { | |
| 61 | + public SubmitResponse action(ActionRequest actionReqVO) { | |
| 62 | 62 | // 1、发送 post 请求 |
| 63 | 63 | String res = post(URI_ACTON, actionReqVO); |
| 64 | 64 | // 2、转换 resp |
| 65 | - return JsonUtils.parseObject(res, MidjourneySubmitResponse.class); | |
| 65 | + return JsonUtils.parseObject(res, SubmitResponse.class); | |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
| ... | ... | @@ -104,24 +104,23 @@ public class MidjourneyApi { |
| 104 | 104 | * @param prompt 提示词 |
| 105 | 105 | * @param state 自定义参数 |
| 106 | 106 | */ |
| 107 | - public record MidjourneyImagineRequest(List<String> base64Array, | |
| 108 | - String notifyHook, | |
| 109 | - String prompt, | |
| 110 | - String state) { | |
| 107 | + public record ImagineRequest(List<String> base64Array, | |
| 108 | + String notifyHook, | |
| 109 | + String prompt, | |
| 110 | + String state) { | |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
| 114 | 114 | * Midjourney - Action 请求 |
| 115 | 115 | * |
| 116 | - * @param customId 操作按钮id | |
| 117 | - * @param taskId 操作按钮id | |
| 116 | + * @param customId 操作按钮id | |
| 117 | + * @param taskId 操作按钮id | |
| 118 | 118 | * @param notifyHook 通知地址 |
| 119 | - * @param state 自定义参数 | |
| 120 | 119 | */ |
| 121 | - public record MidjourneyActionRequest(String customId, | |
| 122 | - String taskId, | |
| 123 | - String notifyHook, | |
| 124 | - String state) { | |
| 120 | + public record ActionRequest(String customId, | |
| 121 | + String taskId, | |
| 122 | + String notifyHook | |
| 123 | + ) { | |
| 125 | 124 | } |
| 126 | 125 | |
| 127 | 126 | /** |
| ... | ... | @@ -132,10 +131,10 @@ public class MidjourneyApi { |
| 132 | 131 | * @param properties 扩展字段 |
| 133 | 132 | * @param result 任务ID |
| 134 | 133 | */ |
| 135 | - public record MidjourneySubmitResponse(String code, | |
| 136 | - String description, | |
| 137 | - Map<String, Object> properties, | |
| 138 | - String result) { | |
| 134 | + public record SubmitResponse(String code, | |
| 135 | + String description, | |
| 136 | + Map<String, Object> properties, | |
| 137 | + String result) { | |
| 139 | 138 | } |
| 140 | 139 | |
| 141 | 140 | /** | ... | ... |