解决问题:ChatClientAutoConfiguration检测到两个ChatModel类型的bean(dashscopeChatModel和ollamaChatModel),导致无法自动注入
This commit is contained in:
parent
fbb9b3049b
commit
655de86e69
4
pom.xml
4
pom.xml
@ -132,6 +132,10 @@
|
||||
<version>1.18.38</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
<parameters>true</parameters>
|
||||
<compilerArgs>
|
||||
<arg>-parameters</arg>
|
||||
</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
@ -18,6 +18,7 @@ import jakarta.annotation.Resource;
|
||||
import org.springframework.ai.chat.messages.AssistantMessage;
|
||||
import org.springframework.ai.chat.prompt.Prompt;
|
||||
import org.springframework.ai.ollama.OllamaChatModel;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -34,9 +35,11 @@ public class InvokeServiceImpl implements InvokeService {
|
||||
private String baiLianKey;
|
||||
|
||||
@Resource
|
||||
@Qualifier("dashscopeChatModel")
|
||||
private DashScopeChatModel dashscopeChatModel;
|
||||
|
||||
@Resource
|
||||
@Qualifier("ollamaChatModel")
|
||||
private OllamaChatModel ollamaChatModel;
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,31 @@
|
||||
package com.huangge1199.aiagent.config;
|
||||
|
||||
import org.springframework.ai.chat.model.ChatModel;
|
||||
import org.springframework.ai.ollama.OllamaChatModel;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
/**
|
||||
* ChatModelConfig
|
||||
*
|
||||
* @author huangge1199
|
||||
* @since 2025/5/17 12:48:28
|
||||
*/
|
||||
@Configuration
|
||||
public class ChatModelConfig {
|
||||
|
||||
// 选择DashScope作为默认模型
|
||||
// @Bean
|
||||
// @Primary
|
||||
// public ChatModel primaryChatModel(DashScopeChatModel dashscopeChatModel) {
|
||||
// return dashscopeChatModel;
|
||||
// }
|
||||
|
||||
// 或者选择Ollama:
|
||||
@Bean
|
||||
@Primary
|
||||
public ChatModel primaryChatModel(OllamaChatModel ollamaChatModel) {
|
||||
return ollamaChatModel;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user