Skip to content

chatModel cannot be null #2810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
SamSamSamChen opened this issue Apr 19, 2025 · 5 comments
Open

chatModel cannot be null #2810

SamSamSamChen opened this issue Apr 19, 2025 · 5 comments

Comments

@SamSamSamChen
Copy link

I already config chat model in config file, but still tell me that cannot be null when use deepseek model.

application yaml:

spring:
ai:
openai:
base-url: https://api.deepseek.com
api-key: ${DEEPSEEK_API_KEY}
chat:
options:
model: deepseek-chat

build.gradle:
implementation platform("org.springframework.ai:spring-ai-bom:1.0.0-SNAPSHOT")
implementation 'org.springframework.ai:spring-ai-openai'
implementation 'org.springframework.ai:spring-ai-starter-model-openai'

And actually, during the morning, this was ok.

I didn't change the code, it's confusing me..

@agent-pasha
Copy link

agent-pasha commented Apr 19, 2025

Same issue here with the snapshot release, OpenAI and gpt-4o model. Tried a new API key and different models, too. It's been working ok in the past couple of days.

@1435646097
Copy link

Yes, I also encountered the issue locally, the stack information is as follows
java.lang.IllegalArgumentException: chatModel cannot be null
at org.springframework.util.Assert.notNull(Assert.java:181)
at org.springframework.ai.chat.client.advisor.api.AdvisedRequest.(AdvisedRequest.java:93)
at org.springframework.ai.chat.client.advisor.api.AdvisedRequest$Builder.build(AdvisedRequest.java:430)
at org.springframework.ai.chat.client.advisor.api.AdvisedRequest.from(AdvisedRequest.java:191)
at org.springframework.ai.chat.client.advisor.DefaultAroundAdvisorChain.lambda$nextCall$1(DefaultAroundAdvisorChain.java:105)
at io.micrometer.observation.Observation.observe(Observation.java:564)
at org.springframework.ai.chat.client.advisor.DefaultAroundAdvisorChain.nextCall(DefaultAroundAdvisorChain.java:100)
at org.springframework.ai.chat.client.DefaultChatClient$DefaultCallResponseSpec.lambda$doGetObservableChatClientResponse$1(DefaultChatClient.java:508)
at io.micrometer.observation.Observation.observe(Observation.java:564)
at org.springframework.ai.chat.client.DefaultChatClient$DefaultCallResponseSpec.doGetObservableChatClientResponse(DefaultChatClient.java:506)
at org.springframework.ai.chat.client.DefaultChatClient$DefaultCallResponseSpec.doGetObservableChatClientResponse(DefaultChatClient.java:490)
at org.springframework.ai.chat.client.DefaultChatClient$DefaultCallResponseSpec.content(DefaultChatClient.java:485)

@1435646097
Copy link

Yes, I also encountered the issue locally, the stack information is as follows java.lang.IllegalArgumentException: chatModel cannot be null at org.springframework.util.Assert.notNull(Assert.java:181) at org.springframework.ai.chat.client.advisor.api.AdvisedRequest.(AdvisedRequest.java:93) at org.springframework.ai.chat.client.advisor.api.AdvisedRequest$Builder.build(AdvisedRequest.java:430) at org.springframework.ai.chat.client.advisor.api.AdvisedRequest.from(AdvisedRequest.java:191) at org.springframework.ai.chat.client.advisor.DefaultAroundAdvisorChain.lambda$nextCall$1(DefaultAroundAdvisorChain.java:105) at io.micrometer.observation.Observation.observe(Observation.java:564) at org.springframework.ai.chat.client.advisor.DefaultAroundAdvisorChain.nextCall(DefaultAroundAdvisorChain.java:100) at org.springframework.ai.chat.client.DefaultChatClient$DefaultCallResponseSpec.lambda$doGetObservableChatClientResponse$1(DefaultChatClient.java:508) at io.micrometer.observation.Observation.observe(Observation.java:564) at org.springframework.ai.chat.client.DefaultChatClient$DefaultCallResponseSpec.doGetObservableChatClientResponse(DefaultChatClient.java:506) at org.springframework.ai.chat.client.DefaultChatClient$DefaultCallResponseSpec.doGetObservableChatClientResponse(DefaultChatClient.java:490) at org.springframework.ai.chat.client.DefaultChatClient$DefaultCallResponseSpec.content(DefaultChatClient.java:485)

The actual issue is here at line 155 of the AdvisedRequest class:
if (from.context().get(ChatClientAttributes.CHAT_MODEL.getKey()) instanceof ChatModel chatModel) {
builder.chatModel = chatModel;
}
How exactly is from.context() set here?

@rmewanou
Copy link

FYI, when facing same issue last week, moving our spring ai dependency back to milestone 7 (M7) instead of snapshot build fixed it.

@agent-pasha
Copy link

agent-pasha commented Apr 21, 2025

Removing .defaultAdvisors() from chatClientBuilder chain fixed the issue. Not ideal, of course, but I've been using it only for logging, and having access to gpt-4.1 outweighs the problem for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants