同一项目配置ollama与openai模型时@Primary无法生效问题
多模型共存时@Primary配置失效问题
Bug描述
在同一项目中同时使用Ollama与OpenAI模型时,无法通过@Primary进行配置。
错误信息如下:
*************************** APPLICATION FAILED TO START *************************** Description: Parameter 1 of method chatClientBuilder in org.springframework.ai.autoconfigure.chat.client.ChatClientAutoConfiguration required a single bean, but 2 were found: - ollamaChatModel: defined by method 'ollamaChatModel' in class path resource [org/springframework/ai/autoconfigure/ollama/OllamaAutoConfiguration.class] - openAiChatModel: defined by method 'openAiChatModel' in class path resource [org/springframework/ai/autoconfigure/openai/OpenAiAutoConfiguration.class] This may be due to missing parameter name information Action: Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed Ensure that your compiler is configured to use the '-parameters' flag. You may need to update both your build tool settings as well as your IDE.
环境依赖
<!-- spring boot AI --> <dependency> <groupId>org.springframework.ai</groupId> <artifactId>spring-ai-openai-spring-boot-starter</artifactId> <version>1.0.0-M1</version> </dependency> <!--spring-ai-ollama-spring-boot-starter--> <dependency> <groupId>org.springframework.ai</groupId> <artifactId>spring-ai-ollama-spring-boot-starter</artifactId> <version>1.0.0-M1</version> </dependency>
复现步骤
@Autowired(required = false) @Qualifier("openAiChatModel") private ChatModel chatModel; @Resource @Qualifier("ollamaChatModel") OllamaChatModel ollamaChatModel;
预期行为
支持在同一项目中同时使用Ollama、OpenAI等多模型,并可通过@Primary指定优先级。
内容的提问来源于stack exchange,提问作者CloudNativeLab
相关产品推荐
相关产品推荐

