| | |
| | | import org.springframework.ai.openai.OpenAiChatModel; |
| | | import org.springframework.ai.vectorstore.VectorStore; |
| | | import org.springframework.ai.vectorstore.milvus.MilvusVectorStore; |
| | | import java.time.Duration; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | public class AiModelFactoryImpl implements AiModelFactory { |
| | | |
| | | @Override |
| | | public ChatModel getOrCreateChatModel(AiPlatformEnum platform, String apiKey, String url, String model) { |
| | | String cacheKey = buildCacheKey(ChatModel.class, platform, apiKey, url, model); |
| | | public ChatModel getOrCreateChatModel(AiPlatformEnum platform, String apiKey, String url, String model, |
| | | Double temperature, Integer maxTokens, Duration timeout) { |
| | | // 温度 / maxTokens / 超时必须一起进 cacheKey:否则在库里改了这些参数后, |
| | | // 缓存仍然返回第一次构建的模型,改了等于没改(且完全静默) |
| | | String cacheKey = buildCacheKey(ChatModel.class, platform, apiKey, url, model, |
| | | temperature, maxTokens, timeout); |
| | | return Singleton.get(cacheKey, (Func0<ChatModel>) () -> { |
| | | if (platform == AiPlatformEnum.TONG_YI) { |
| | | return AiAutoConfiguration.buildTongYiChatModel(apiKey, model); |
| | | return AiAutoConfiguration.buildTongYiChatModel(apiKey, model, temperature, maxTokens, timeout); |
| | | } |
| | | throw new IllegalArgumentException(StrUtil.format("不支持的平台({})", platform)); |
| | | }); |