mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-17 20:45:06 +08:00
【代码新增】AI:聊天会话的段式发送
This commit is contained in:
@ -3,7 +3,7 @@ package cn.iocoder.yudao.framework.ai.core.factory;
|
||||
import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.midjourney.api.MidjourneyApi;
|
||||
import cn.iocoder.yudao.framework.ai.core.model.suno.api.SunoApi;
|
||||
import org.springframework.ai.chat.model.StreamingChatModel;
|
||||
import org.springframework.ai.chat.model.ChatModel;
|
||||
import org.springframework.ai.image.ImageModel;
|
||||
|
||||
/**
|
||||
@ -14,26 +14,26 @@ import org.springframework.ai.image.ImageModel;
|
||||
public interface AiClientFactory {
|
||||
|
||||
/**
|
||||
* 基于指定配置,获得 StreamingChatClient 对象
|
||||
* 基于指定配置,获得 ChatModel 对象
|
||||
*
|
||||
* 如果不存在,则进行创建
|
||||
*
|
||||
* @param platform 平台
|
||||
* @param apiKey API KEY
|
||||
* @param url API URL
|
||||
* @return StreamingChatClient 对象
|
||||
* @return ChatModel 对象
|
||||
*/
|
||||
StreamingChatModel getOrCreateStreamingChatClient(AiPlatformEnum platform, String apiKey, String url);
|
||||
ChatModel getOrCreateChatClient(AiPlatformEnum platform, String apiKey, String url);
|
||||
|
||||
/**
|
||||
* 基于默认配置,获得 StreamingChatClient 对象
|
||||
* 基于默认配置,获得 ChatModel 对象
|
||||
*
|
||||
* 默认配置,指的是在 application.yaml 配置文件中的 spring.ai 相关的配置
|
||||
*
|
||||
* @param platform 平台
|
||||
* @return StreamingChatClient 对象
|
||||
* @return ChatModel 对象
|
||||
*/
|
||||
StreamingChatModel getDefaultStreamingChatClient(AiPlatformEnum platform);
|
||||
ChatModel getDefaultChatClient(AiPlatformEnum platform);
|
||||
|
||||
/**
|
||||
* 基于默认配置,获得 ImageClient 对象
|
||||
|
@ -23,7 +23,7 @@ import org.springframework.ai.autoconfigure.openai.OpenAiAutoConfiguration;
|
||||
import org.springframework.ai.autoconfigure.qianfan.QianFanAutoConfiguration;
|
||||
import org.springframework.ai.autoconfigure.qianfan.QianFanChatProperties;
|
||||
import org.springframework.ai.autoconfigure.qianfan.QianFanConnectionProperties;
|
||||
import org.springframework.ai.chat.model.StreamingChatModel;
|
||||
import org.springframework.ai.chat.model.ChatModel;
|
||||
import org.springframework.ai.image.ImageModel;
|
||||
import org.springframework.ai.ollama.OllamaChatModel;
|
||||
import org.springframework.ai.ollama.api.OllamaApi;
|
||||
@ -50,9 +50,9 @@ import java.util.List;
|
||||
public class AiClientFactoryImpl implements AiClientFactory {
|
||||
|
||||
@Override
|
||||
public StreamingChatModel getOrCreateStreamingChatClient(AiPlatformEnum platform, String apiKey, String url) {
|
||||
String cacheKey = buildClientCacheKey(StreamingChatModel.class, platform, apiKey, url);
|
||||
return Singleton.get(cacheKey, (Func0<StreamingChatModel>) () -> {
|
||||
public ChatModel getOrCreateChatClient(AiPlatformEnum platform, String apiKey, String url) {
|
||||
String cacheKey = buildClientCacheKey(ChatModel.class, platform, apiKey, url);
|
||||
return Singleton.get(cacheKey, (Func0<ChatModel>) () -> {
|
||||
//noinspection EnhancedSwitchMigration
|
||||
switch (platform) {
|
||||
case OPENAI:
|
||||
@ -74,7 +74,7 @@ public class AiClientFactoryImpl implements AiClientFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamingChatModel getDefaultStreamingChatClient(AiPlatformEnum platform) {
|
||||
public ChatModel getDefaultChatClient(AiPlatformEnum platform) {
|
||||
//noinspection EnhancedSwitchMigration
|
||||
switch (platform) {
|
||||
case OPENAI:
|
||||
|
Reference in New Issue
Block a user