- 
                Notifications
    
You must be signed in to change notification settings  - Fork 2k
 
Closed
Description
Bug description
When creating a ChatClient without explicitly specifying a ChatModel (relying on auto-configuration), the call to the LLM fails if a default advisor is set (e.g., SimpleLoggerAdvisor). The following exception is thrown:
java.lang.IllegalArgumentException: chatModel cannot be null
Environment
- Spring AI version: 1.0.0-SNAPSHOT
 - Java version: GraalVM 21.0.4 - VM 23.1.4
 - Impacted models: VertexAIGemini, Mistral
 
Steps to reproduce
- Create a ChatClient without specifying a 
ChatModel, using an injectedChatClient.Builderand callingchatClient.build(). - Add a default advisor (e.g., SimpleLoggerAdvisor).
 - Call the LLM, specifying the model via the prompt.
 
Note: Everything works as expected if no default advisor is set.
Expected behavior
The call to the LLM should succeed, and the advisor should be invoked correctly during execution.
Minimal Complete Reproducible example
 package com.malt.platform.spring.test.controller
 import org.springframework.ai.chat.client.ChatClient
 import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor
 import org.springframework.ai.chat.prompt.ChatOptions
 import org.springframework.ai.chat.prompt.Prompt
 import org.springframework.web.bind.annotation.PostMapping
 import org.springframework.web.bind.annotation.RequestBody
 import org.springframework.web.bind.annotation.RequestMapping
 import org.springframework.web.bind.annotation.RestController
 @RestController
 @RequestMapping("/springai-test")
 class SpringAiTestController(
    chatClientBuilder: ChatClient.Builder,
 ) {
    private val chatClient: ChatClient = chatClientBuilder.defaultAdvisors(SimpleLoggerAdvisor()).build()
    @PostMapping("/springai")
    fun springAi(
        @RequestBody prompt: String,
    ): String? =
        chatClient
            .prompt(
                Prompt
                    .Builder()
                    .chatOptions(
                        ChatOptions.builder().model("gemini-2.0-flash-001").build(),
                    ).build(),
            ).user(prompt)
            .call()
            .content()
 }Metadata
Metadata
Assignees
Labels
No labels