Skip to content

Conversation

@quaff
Copy link
Contributor

@quaff quaff commented May 15, 2025

Given:

implementation("org.springframework.ai:spring-ai-starter-model-deepseek")
implementation("org.springframework.ai:spring-ai-starter-model-ollama")

Application failed to start before this commit:

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 1 of method chatClientBuilder in org.springframework.ai.model.chat.client.autoconfigure.ChatClientAutoConfiguration required a single bean, but 2 were found:
	- deepSeekChatModel: defined by method 'deepSeekChatModel' in class path resource [org/springframework/ai/model/deepseek/autoconfigure/DeepSeekChatAutoConfiguration.class]
	- ollamaChatModel: defined by method 'ollamaChatModel' in class path resource [org/springframework/ai/model/ollama/autoconfigure/OllamaChatAutoConfiguration.class]

After this commit, we could construct our own instead of autoconfigured ChatClient.Builder by injecting qualified ChatModel.

Related to GH-2221.

@markpollack
Copy link
Member

Hi. How does this PR work to achieve the goal of injecting by qualified chat model? Holding off on this until the GA release.

@markpollack markpollack added this to the 1.0.x milestone May 15, 2025
@quaff
Copy link
Contributor Author

quaff commented May 16, 2025

Hi. How does this PR work to achieve the goal of injecting by qualified chat model? Holding off on this until the GA release.

Application could define their own ChatClient.Builders like this:

	@Bean
	@Scope("prototype")
	ChatClient.Builder deepSeekChatClientBuilder(ChatClientBuilderConfigurer chatClientBuilderConfigurer, @Qualifier("deepSeekChatModel") ChatModel deepSeekChatModel,
										 ObjectProvider<ObservationRegistry> observationRegistry,
										 ObjectProvider<ChatClientObservationConvention> observationConvention) {
		ChatClient.Builder builder = ChatClient.builder(deepSeekChatModel,
				observationRegistry.getIfUnique(() -> ObservationRegistry.NOOP),
				observationConvention.getIfUnique(() -> null));
		return chatClientBuilderConfigurer.configure(builder);
	}

	@Bean
	@Scope("prototype")
	ChatClient.Builder ollamaChatClientBuilder(ChatClientBuilderConfigurer chatClientBuilderConfigurer, @Qualifier("ollamaChatModel") ChatModel ollamaChatModel,
												 ObjectProvider<ObservationRegistry> observationRegistry,
												 ObjectProvider<ChatClientObservationConvention> observationConvention) {
		ChatClient.Builder builder = ChatClient.builder(ollamaChatModel,
				observationRegistry.getIfUnique(() -> ObservationRegistry.NOOP),
				observationConvention.getIfUnique(() -> null));
		return chatClientBuilderConfigurer.configure(builder);
	}

@quaff
Copy link
Contributor Author

quaff commented Oct 15, 2025

@markpollack WDYT?

Given:
```
implementation("org.springframework.ai:spring-ai-starter-model-deepseek")
implementation("org.springframework.ai:spring-ai-starter-model-ollama")

```

Application failed to start before this commit:

```
***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 1 of method chatClientBuilder in org.springframework.ai.model.chat.client.autoconfigure.ChatClientAutoConfiguration required a single bean, but 2 were found:
	- deepSeekChatModel: defined by method 'deepSeekChatModel' in class path resource [org/springframework/ai/model/deepseek/autoconfigure/DeepSeekChatAutoConfiguration.class]
	- ollamaChatModel: defined by method 'ollamaChatModel' in class path resource [org/springframework/ai/model/ollama/autoconfigure/OllamaChatAutoConfiguration.class]

```

After this commit, we could construct our own instead of autoconfigured `ChatClient.Builder` by injecting qualified `ChatModel`.

Related to spring-projectsGH-2221.

Signed-off-by: Yanming Zhou <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants