mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-13 02:25:06 +08:00
【新增】AI:进一步统一 DALL、SD 的绘制实现
This commit is contained in:
@ -3,10 +3,9 @@ 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.yiyan.api.YiYanChatModel;
|
||||
import cn.iocoder.yudao.framework.ai.core.enums.OpenAiImageModelEnum;
|
||||
import cn.iocoder.yudao.framework.ai.core.enums.OpenAiImageStyleEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springframework.ai.autoconfigure.openai.OpenAiImageProperties;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
@ -92,27 +91,6 @@ public class YudaoAiProperties {
|
||||
private int refreshTokenSecondTime = 86400;
|
||||
}
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public static class OpenAiImageProperties {
|
||||
|
||||
private boolean enable = false;
|
||||
|
||||
/**
|
||||
* api key
|
||||
*/
|
||||
private String apiKey;
|
||||
/**
|
||||
* 模型
|
||||
*/
|
||||
private OpenAiImageModelEnum model = OpenAiImageModelEnum.DALL_E_2;
|
||||
/**
|
||||
* 风格
|
||||
*/
|
||||
private OpenAiImageStyleEnum style = OpenAiImageStyleEnum.VIVID;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public static class MidjourneyProperties {
|
||||
|
@ -20,7 +20,6 @@ public enum AiPlatformEnum {
|
||||
QIAN_WEN("QianWen", "千问"), // 阿里
|
||||
GEMIR ("gemir ", "gemir "), // 谷歌
|
||||
|
||||
OPEN_AI_DALL("dall", "dall"), // TODO OpenAI 提供的绘图,接入中;TODO 要不要统一下?!
|
||||
STABLE_DIFFUSION("StableDiffusion", "StableDiffusion"), // Stability AI
|
||||
MIDJOURNEY("midjourney", "midjourney"), // TODO MJ 提供的绘图,接入中
|
||||
;
|
||||
|
@ -1,37 +0,0 @@
|
||||
package cn.iocoder.yudao.framework.ai.core.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
// TODO 芋艿:待梳理
|
||||
/**
|
||||
* open ai
|
||||
*
|
||||
* @author fansili
|
||||
* @time 2024/4/28 14:21
|
||||
* @since 1.0
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
@Deprecated
|
||||
public enum OpenAiImageModelEnum {
|
||||
|
||||
DALL_E_2("dall-e-2", "dall-e-2"),
|
||||
|
||||
DALL_E_3("dall-e-3", "dall-e-3")
|
||||
|
||||
;
|
||||
|
||||
private String model;
|
||||
|
||||
private String name;
|
||||
|
||||
public static OpenAiImageModelEnum valueOfModel(String model) {
|
||||
for (OpenAiImageModelEnum itemEnum : OpenAiImageModelEnum.values()) {
|
||||
if (itemEnum.getModel().equals(model)) {
|
||||
return itemEnum;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid MessageType value: " + model);
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package cn.iocoder.yudao.framework.ai.core.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
// TODO 芋艿:待梳理
|
||||
/**
|
||||
* open ai image style
|
||||
*
|
||||
* @author fansili
|
||||
* @time 2024/4/28 16:15
|
||||
* @since 1.0
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
@Deprecated
|
||||
public enum OpenAiImageStyleEnum {
|
||||
|
||||
// 图像生成的风格。可为vivid(生动)或 natural(自然)。vivid会使模型偏向生成超现实和戏剧性的图像,而natural则会让模型产出更自然、不那么超现实的图像。该参数仅对dall-e-3模型有效。
|
||||
|
||||
VIVID("vivid", "生动"),
|
||||
NATURAL("natural", "自然"),
|
||||
|
||||
;
|
||||
|
||||
private String style;
|
||||
|
||||
private String name;
|
||||
|
||||
public static OpenAiImageStyleEnum valueOfStyle(String style) {
|
||||
for (OpenAiImageStyleEnum itemEnum : OpenAiImageStyleEnum.values()) {
|
||||
if (itemEnum.getStyle().equals(style)) {
|
||||
return itemEnum;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid MessageType value: " + style);
|
||||
}
|
||||
}
|
@ -33,6 +33,7 @@ import org.springframework.ai.openai.OpenAiChatOptions;
|
||||
import org.springframework.ai.openai.OpenAiImageClient;
|
||||
import org.springframework.ai.openai.api.ApiUtils;
|
||||
import org.springframework.ai.openai.api.OpenAiApi;
|
||||
import org.springframework.ai.stabilityai.StabilityAiImageClient;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -88,12 +89,15 @@ public class AiClientFactoryImpl implements AiClientFactory {
|
||||
|
||||
@Override
|
||||
public ImageClient getDefaultImageClient(AiPlatformEnum platform) {
|
||||
//noinspection EnhancedSwitchMigration
|
||||
switch (platform) {
|
||||
case OPEN_AI_DALL:
|
||||
case OPENAI:
|
||||
return SpringUtil.getBean(OpenAiImageClient.class);
|
||||
|
||||
case STABLE_DIFFUSION:
|
||||
return SpringUtil.getBean(StabilityAiImageClient.class);
|
||||
default:
|
||||
throw new IllegalArgumentException(StrUtil.format("未知平台({})", platform));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String buildClientCacheKey(Class<?> clazz, Object... params) {
|
||||
|
Reference in New Issue
Block a user