【新增】AI:使用 DALL 绘图时,使用 b64_json 返回

This commit is contained in:
YunaiV
2024-06-01 11:24:39 +08:00
parent 458f5acdf0
commit 0563503102
12 changed files with 108 additions and 313 deletions

View File

@ -20,7 +20,8 @@ public enum AiPlatformEnum {
QIAN_WEN("QianWen", "千问"), // 阿里
GEMIR ("gemir ", "gemir "), // 谷歌
OPEN_AI_DALL("dall", "dall"), // TODO OpenAI 提供的绘图,接入中
OPEN_AI_DALL("dall", "dall"), // TODO OpenAI 提供的绘图,接入中TODO 要不要统一下?!
STABLE_DIFFUSION("StableDiffusion", "StableDiffusion"), // Stability AI
MIDJOURNEY("midjourney", "midjourney"), // TODO MJ 提供的绘图,接入中
;

View File

@ -13,6 +13,7 @@ import lombok.Getter;
*/
@AllArgsConstructor
@Getter
@Deprecated
public enum OpenAiImageModelEnum {
DALL_E_2("dall-e-2", "dall-e-2"),

View File

@ -13,6 +13,7 @@ import lombok.Getter;
*/
@AllArgsConstructor
@Getter
@Deprecated
public enum OpenAiImageStyleEnum {
// 图像生成的风格。可为vivid生动或 natural自然。vivid会使模型偏向生成超现实和戏剧性的图像而natural则会让模型产出更自然、不那么超现实的图像。该参数仅对dall-e-3模型有效。

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.framework.ai.core.factory;
import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum;
import org.springframework.ai.chat.StreamingChatClient;
import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.ai.image.ImageClient;
/**
* AI 客户端工厂的接口类
@ -33,6 +34,16 @@ public interface AiClientFactory {
*/
StreamingChatClient getDefaultStreamingChatClient(AiPlatformEnum platform);
/**
* 基于默认配置,获得 ImageClient 对象
*
* 默认配置,指的是在 application.yaml 配置文件中的 spring.ai 相关的配置
*
* @param platform 平台
* @return ImageClient 对象
*/
ImageClient getDefaultImageClient(AiPlatformEnum platform);
/**
* 创建 Chat 参数
*

View File

@ -24,11 +24,13 @@ import org.springframework.ai.autoconfigure.ollama.OllamaAutoConfiguration;
import org.springframework.ai.autoconfigure.openai.OpenAiAutoConfiguration;
import org.springframework.ai.chat.StreamingChatClient;
import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.ai.image.ImageClient;
import org.springframework.ai.ollama.OllamaChatClient;
import org.springframework.ai.ollama.api.OllamaApi;
import org.springframework.ai.ollama.api.OllamaOptions;
import org.springframework.ai.openai.OpenAiChatClient;
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;
@ -84,6 +86,16 @@ public class AiClientFactoryImpl implements AiClientFactory {
}
}
@Override
public ImageClient getDefaultImageClient(AiPlatformEnum platform) {
switch (platform) {
case OPEN_AI_DALL:
return SpringUtil.getBean(OpenAiImageClient.class);
}
return null;
}
private static String buildClientCacheKey(Class<?> clazz, Object... params) {
if (ArrayUtil.isEmpty(params)) {
return clazz.getName();