|
@@ -20,16 +20,16 @@ import cn.iocoder.yudao.framework.ai.core.model.yiyan.YiYanChatClient;
|
|
|
import cn.iocoder.yudao.framework.ai.core.model.yiyan.api.YiYanApi;
|
|
|
import org.springframework.ai.autoconfigure.ollama.OllamaAutoConfiguration;
|
|
|
import org.springframework.ai.autoconfigure.openai.OpenAiAutoConfiguration;
|
|
|
-import org.springframework.ai.chat.StreamingChatClient;
|
|
|
-import org.springframework.ai.image.ImageClient;
|
|
|
-import org.springframework.ai.ollama.OllamaChatClient;
|
|
|
+import org.springframework.ai.chat.model.StreamingChatModel;
|
|
|
+import org.springframework.ai.image.ImageModel;
|
|
|
+import org.springframework.ai.ollama.OllamaChatModel;
|
|
|
import org.springframework.ai.ollama.api.OllamaApi;
|
|
|
-import org.springframework.ai.openai.OpenAiChatClient;
|
|
|
-import org.springframework.ai.openai.OpenAiImageClient;
|
|
|
+import org.springframework.ai.openai.OpenAiChatModel;
|
|
|
+import org.springframework.ai.openai.OpenAiImageModel;
|
|
|
import org.springframework.ai.openai.api.ApiUtils;
|
|
|
import org.springframework.ai.openai.api.OpenAiApi;
|
|
|
import org.springframework.ai.openai.api.OpenAiImageApi;
|
|
|
-import org.springframework.ai.stabilityai.StabilityAiImageClient;
|
|
|
+import org.springframework.ai.stabilityai.StabilityAiImageModel;
|
|
|
import org.springframework.ai.stabilityai.api.StabilityAiApi;
|
|
|
import org.springframework.web.client.RestClient;
|
|
|
|
|
@@ -43,9 +43,9 @@ import java.util.List;
|
|
|
public class AiClientFactoryImpl implements AiClientFactory {
|
|
|
|
|
|
@Override
|
|
|
- public StreamingChatClient getOrCreateStreamingChatClient(AiPlatformEnum platform, String apiKey, String url) {
|
|
|
- String cacheKey = buildClientCacheKey(StreamingChatClient.class, platform, apiKey, url);
|
|
|
- return Singleton.get(cacheKey, (Func0<StreamingChatClient>) () -> {
|
|
|
+ public StreamingChatModel getOrCreateStreamingChatClient(AiPlatformEnum platform, String apiKey, String url) {
|
|
|
+ String cacheKey = buildClientCacheKey(StreamingChatModel.class, platform, apiKey, url);
|
|
|
+ return Singleton.get(cacheKey, (Func0<StreamingChatModel>) () -> {
|
|
|
//noinspection EnhancedSwitchMigration
|
|
|
switch (platform) {
|
|
|
case OPENAI:
|
|
@@ -67,13 +67,13 @@ public class AiClientFactoryImpl implements AiClientFactory {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public StreamingChatClient getDefaultStreamingChatClient(AiPlatformEnum platform) {
|
|
|
+ public StreamingChatModel getDefaultStreamingChatClient(AiPlatformEnum platform) {
|
|
|
//noinspection EnhancedSwitchMigration
|
|
|
switch (platform) {
|
|
|
case OPENAI:
|
|
|
- return SpringUtil.getBean(OpenAiChatClient.class);
|
|
|
+ return SpringUtil.getBean(OpenAiChatModel.class);
|
|
|
case OLLAMA:
|
|
|
- return SpringUtil.getBean(OllamaChatClient.class);
|
|
|
+ return SpringUtil.getBean(OllamaChatModel.class);
|
|
|
case YI_YAN:
|
|
|
return SpringUtil.getBean(YiYanChatClient.class);
|
|
|
case XING_HUO:
|
|
@@ -86,20 +86,20 @@ public class AiClientFactoryImpl implements AiClientFactory {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ImageClient getDefaultImageClient(AiPlatformEnum platform) {
|
|
|
+ public ImageModel getDefaultImageClient(AiPlatformEnum platform) {
|
|
|
//noinspection EnhancedSwitchMigration
|
|
|
switch (platform) {
|
|
|
case OPENAI:
|
|
|
- return SpringUtil.getBean(OpenAiImageClient.class);
|
|
|
+ return SpringUtil.getBean(OpenAiImageModel.class);
|
|
|
case STABLE_DIFFUSION:
|
|
|
- return SpringUtil.getBean(StabilityAiImageClient.class);
|
|
|
+ return SpringUtil.getBean(StabilityAiImageModel.class);
|
|
|
default:
|
|
|
throw new IllegalArgumentException(StrUtil.format("未知平台({})", platform));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ImageClient getOrCreateImageClient(AiPlatformEnum platform, String apiKey, String url) {
|
|
|
+ public ImageModel getOrCreateImageClient(AiPlatformEnum platform, String apiKey, String url) {
|
|
|
//noinspection EnhancedSwitchMigration
|
|
|
switch (platform) {
|
|
|
case OPENAI:
|
|
@@ -138,18 +138,18 @@ public class AiClientFactoryImpl implements AiClientFactory {
|
|
|
/**
|
|
|
* 可参考 {@link OpenAiAutoConfiguration}
|
|
|
*/
|
|
|
- private static OpenAiChatClient buildOpenAiChatClient(String openAiToken, String url) {
|
|
|
+ private static OpenAiChatModel buildOpenAiChatClient(String openAiToken, String url) {
|
|
|
url = StrUtil.blankToDefault(url, ApiUtils.DEFAULT_BASE_URL);
|
|
|
OpenAiApi openAiApi = new OpenAiApi(url, openAiToken);
|
|
|
- return new OpenAiChatClient(openAiApi);
|
|
|
+ return new OpenAiChatModel(openAiApi);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 可参考 {@link OllamaAutoConfiguration}
|
|
|
*/
|
|
|
- private static OllamaChatClient buildOllamaChatClient(String url) {
|
|
|
+ private static OllamaChatModel buildOllamaChatClient(String url) {
|
|
|
OllamaApi ollamaApi = new OllamaApi(url);
|
|
|
- return new OllamaChatClient(ollamaApi);
|
|
|
+ return new OllamaChatModel(ollamaApi);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -192,16 +192,16 @@ public class AiClientFactoryImpl implements AiClientFactory {
|
|
|
// return new VertexAiGeminiChatClient(vertexApi);
|
|
|
// }
|
|
|
|
|
|
- private ImageClient buildOpenAiImageClient(String openAiToken, String url) {
|
|
|
+ private OpenAiImageModel buildOpenAiImageClient(String openAiToken, String url) {
|
|
|
url = StrUtil.blankToDefault(url, ApiUtils.DEFAULT_BASE_URL);
|
|
|
OpenAiImageApi openAiApi = new OpenAiImageApi(url, openAiToken, RestClient.builder());
|
|
|
- return new OpenAiImageClient(openAiApi);
|
|
|
+ return new OpenAiImageModel(openAiApi);
|
|
|
}
|
|
|
|
|
|
- private ImageClient buildStabilityAiImageClient(String apiKey, String url) {
|
|
|
+ private StabilityAiImageModel buildStabilityAiImageClient(String apiKey, String url) {
|
|
|
url = StrUtil.blankToDefault(url, StabilityAiApi.DEFAULT_BASE_URL);
|
|
|
StabilityAiApi stabilityAiApi = new StabilityAiApi(apiKey, StabilityAiApi.DEFAULT_IMAGE_MODEL, url);
|
|
|
- return new StabilityAiImageClient(stabilityAiApi);
|
|
|
+ return new StabilityAiImageModel(stabilityAiApi);
|
|
|
}
|
|
|
|
|
|
}
|