【增加】MidjourneyApi 自动配置

This commit is contained in:
cherishsince 2024-06-13 14:42:49 +08:00
parent 7358084198
commit 4d9dbeaa8d
5 changed files with 45 additions and 124 deletions

View File

@ -1,98 +0,0 @@
package cn.iocoder.yudao.framework.ai.config;
import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum;
import cn.iocoder.yudao.framework.ai.core.model.xinghuo.XingHuoChatModel;
import cn.iocoder.yudao.framework.ai.core.model.xinghuo.XingHuoOptions;
import cn.iocoder.yudao.framework.ai.core.model.yiyan.api.YiYanChatModel;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* ai 自动配置
*
* @author fansili
* @time 2024/4/12 16:29
* @since 1.0
*/
@Data
@Accessors(chain = true)
public class YudaoAiImageProperties extends LinkedHashMap<String, Map<String, Object>> {
private String initType;
private QianWenProperties qianwen;
private XingHuoOptions xinghuo;
private YiYanProperties yiyan;
@Data
@Accessors(chain = true)
public static class QianWenProperties extends ChatProperties {
/**
* 阿里云服务器接入点
*/
private String endpoint = "bailian.cn-beijing.aliyuncs.com";
/**
* 阿里云权限 accessKeyId
*/
private String accessKeyId;
/**
* 阿里云权限 accessKeySecret
*/
private String accessKeySecret;
/**
* 阿里云agentKey
*/
private String agentKey;
/**
* 阿里云agentKey(相当于应用id)
*/
private String appId;
}
@Data
@Accessors(chain = true)
public static class XingHuoProperties extends ChatProperties {
private String appId;
private String appKey;
private String secretKey;
private XingHuoChatModel chatModel;
}
@Data
@Accessors(chain = true)
public static class YiYanProperties extends ChatProperties {
/**
* appKey
*/
private String appKey;
/**
* secretKey
*/
private String secretKey;
/**
* 模型
*/
private YiYanChatModel chatModel = YiYanChatModel.ERNIE4_3_5_8K;
/**
* token 刷新时间(默认 86400 = 24小时)
*/
private int refreshTokenSecondTime = 86400;
}
@Data
@Accessors(chain = true)
public static class ChatProperties {
private AiPlatformEnum aiPlatform;
private Float temperature;
private Float topP;
private Integer topK;
}
}

View File

@ -0,0 +1,24 @@
package cn.iocoder.yudao.framework.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.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 配置
*
* @author fansili
* @time 2024/6/13 09:50
*/
@Configuration
public class YudaoMidjourneyConfiguration {
@Bean
@ConditionalOnProperty(value = "ai.midjourney-proxy.enable", havingValue = "true")
public MidjourneyApi midjourneyApi(YudaoMidjourneyProperties midjourneyProperties) {
return new MidjourneyApi(BeanUtils.toBean(midjourneyProperties, MidjourneyConfig.class));
}
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.ai.config;
package cn.iocoder.yudao.framework.ai.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ -14,9 +14,9 @@ import org.springframework.context.annotation.Configuration;
@Configuration
@ConfigurationProperties(prefix = "ai.midjourney-proxy")
@Data
public class MidjourneyProperties {
public class YudaoMidjourneyProperties {
private String enable;
private String key;
private String url;
private String notifyUrl;
}

View File

@ -20,8 +20,4 @@ public class MidjourneyConfig {
* 请求地址
*/
private String url;
/**
* 通知回调地址
*/
private String notifyUrl;
}

View File

@ -46,11 +46,11 @@ public class MidjourneyApi {
* @param imagineReqVO
* @return
*/
public MidjourneySubmitResponse imagine(MidjourneyImagineRequest imagineReqVO) {
public SubmitResponse imagine(ImagineRequest imagineReqVO) {
// 1发送 post 请求
String res = post(URI_IMAGINE, imagineReqVO);
// 2转换 resp
return JsonUtils.parseObject(res, MidjourneySubmitResponse.class);
return JsonUtils.parseObject(res, SubmitResponse.class);
}
/**
@ -58,11 +58,11 @@ public class MidjourneyApi {
*
* @param actionReqVO
*/
public MidjourneySubmitResponse action(MidjourneyActionRequest actionReqVO) {
public SubmitResponse action(ActionRequest actionReqVO) {
// 1发送 post 请求
String res = post(URI_ACTON, actionReqVO);
// 2转换 resp
return JsonUtils.parseObject(res, MidjourneySubmitResponse.class);
return JsonUtils.parseObject(res, SubmitResponse.class);
}
/**
@ -104,24 +104,23 @@ public class MidjourneyApi {
* @param prompt 提示词
* @param state 自定义参数
*/
public record MidjourneyImagineRequest(List<String> base64Array,
String notifyHook,
String prompt,
String state) {
public record ImagineRequest(List<String> base64Array,
String notifyHook,
String prompt,
String state) {
}
/**
* Midjourney - Action 请求
*
* @param customId 操作按钮id
* @param taskId 操作按钮id
* @param customId 操作按钮id
* @param taskId 操作按钮id
* @param notifyHook 通知地址
* @param state 自定义参数
*/
public record MidjourneyActionRequest(String customId,
String taskId,
String notifyHook,
String state) {
public record ActionRequest(String customId,
String taskId,
String notifyHook
) {
}
/**
@ -132,10 +131,10 @@ public class MidjourneyApi {
* @param properties 扩展字段
* @param result 任务ID
*/
public record MidjourneySubmitResponse(String code,
String description,
Map<String, Object> properties,
String result) {
public record SubmitResponse(String code,
String description,
Map<String, Object> properties,
String result) {
}
/**