mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-30 11:11:55 +08:00
【增加】MidjourneyApi 自动配置
This commit is contained in:
parent
7358084198
commit
4d9dbeaa8d
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package cn.iocoder.yudao.module.ai.config;
|
package cn.iocoder.yudao.framework.ai.config;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
@ -14,9 +14,9 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
@Configuration
|
@Configuration
|
||||||
@ConfigurationProperties(prefix = "ai.midjourney-proxy")
|
@ConfigurationProperties(prefix = "ai.midjourney-proxy")
|
||||||
@Data
|
@Data
|
||||||
public class MidjourneyProperties {
|
public class YudaoMidjourneyProperties {
|
||||||
|
|
||||||
|
private String enable;
|
||||||
private String key;
|
private String key;
|
||||||
private String url;
|
private String url;
|
||||||
private String notifyUrl;
|
|
||||||
}
|
}
|
@ -20,8 +20,4 @@ public class MidjourneyConfig {
|
|||||||
* 请求地址
|
* 请求地址
|
||||||
*/
|
*/
|
||||||
private String url;
|
private String url;
|
||||||
/**
|
|
||||||
* 通知回调地址
|
|
||||||
*/
|
|
||||||
private String notifyUrl;
|
|
||||||
}
|
}
|
||||||
|
@ -46,11 +46,11 @@ public class MidjourneyApi {
|
|||||||
* @param imagineReqVO
|
* @param imagineReqVO
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public MidjourneySubmitResponse imagine(MidjourneyImagineRequest imagineReqVO) {
|
public SubmitResponse imagine(ImagineRequest imagineReqVO) {
|
||||||
// 1、发送 post 请求
|
// 1、发送 post 请求
|
||||||
String res = post(URI_IMAGINE, imagineReqVO);
|
String res = post(URI_IMAGINE, imagineReqVO);
|
||||||
// 2、转换 resp
|
// 2、转换 resp
|
||||||
return JsonUtils.parseObject(res, MidjourneySubmitResponse.class);
|
return JsonUtils.parseObject(res, SubmitResponse.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,11 +58,11 @@ public class MidjourneyApi {
|
|||||||
*
|
*
|
||||||
* @param actionReqVO
|
* @param actionReqVO
|
||||||
*/
|
*/
|
||||||
public MidjourneySubmitResponse action(MidjourneyActionRequest actionReqVO) {
|
public SubmitResponse action(ActionRequest actionReqVO) {
|
||||||
// 1、发送 post 请求
|
// 1、发送 post 请求
|
||||||
String res = post(URI_ACTON, actionReqVO);
|
String res = post(URI_ACTON, actionReqVO);
|
||||||
// 2、转换 resp
|
// 2、转换 resp
|
||||||
return JsonUtils.parseObject(res, MidjourneySubmitResponse.class);
|
return JsonUtils.parseObject(res, SubmitResponse.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -104,7 +104,7 @@ public class MidjourneyApi {
|
|||||||
* @param prompt 提示词
|
* @param prompt 提示词
|
||||||
* @param state 自定义参数
|
* @param state 自定义参数
|
||||||
*/
|
*/
|
||||||
public record MidjourneyImagineRequest(List<String> base64Array,
|
public record ImagineRequest(List<String> base64Array,
|
||||||
String notifyHook,
|
String notifyHook,
|
||||||
String prompt,
|
String prompt,
|
||||||
String state) {
|
String state) {
|
||||||
@ -116,12 +116,11 @@ public class MidjourneyApi {
|
|||||||
* @param customId 操作按钮id
|
* @param customId 操作按钮id
|
||||||
* @param taskId 操作按钮id
|
* @param taskId 操作按钮id
|
||||||
* @param notifyHook 通知地址
|
* @param notifyHook 通知地址
|
||||||
* @param state 自定义参数
|
|
||||||
*/
|
*/
|
||||||
public record MidjourneyActionRequest(String customId,
|
public record ActionRequest(String customId,
|
||||||
String taskId,
|
String taskId,
|
||||||
String notifyHook,
|
String notifyHook
|
||||||
String state) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -132,7 +131,7 @@ public class MidjourneyApi {
|
|||||||
* @param properties 扩展字段
|
* @param properties 扩展字段
|
||||||
* @param result 任务ID
|
* @param result 任务ID
|
||||||
*/
|
*/
|
||||||
public record MidjourneySubmitResponse(String code,
|
public record SubmitResponse(String code,
|
||||||
String description,
|
String description,
|
||||||
Map<String, Object> properties,
|
Map<String, Object> properties,
|
||||||
String result) {
|
String result) {
|
||||||
|
Loading…
Reference in New Issue
Block a user