Posts

Chat Client APIs and Streaming

 Chat Client APIs and Streaming call(). content() (Most Common) Returns only the generated text. @GetMapping ( "/content" ) public String content ( @RequestParam String question) { return chatClient.prompt() .user(question) .call() .content() ; } Flow: User │ ▼ ChatClient │ ▼ LLM │ ▼ String Use when you only need the answer. call().chatResponse() Returns the complete response object, not just the text. @GetMapping ( "/response" ) public ChatResponse response ( @RequestParam String question) { return chatClient.prompt() .user(question) .call() .chatResponse() ; } Chat Response contains much more than the content. http://localhost:8080/api/response?question=Explain Kafka output are in json format .  Streaming Instead of waiting for the complete answer, stream it token by token. @GetMapping (value= "/stream" , produces = MediaType. TEXT_EVENT_STREAM_VALUE ...

What is ChatOptions

                              What is ChatOptions? Q1. What is ChatOptions? Answer ChatOptions is a configuration object in Spring AI that controls how the underlying language model generates responses.   It allows developers to configure parameters such as model selection, temperature, maximum output tokens, sampling behavior, and other provider-supported settings.    Instead of changing the prompt, it changes how the model generates the answer . Architecture User │ ▼ ChatClient │ ├── Prompt ├── Advisors └── ChatOptions │ ▼ OpenAI / Ollama │ ▼ AI Response Notice: Prompt → tells the model what to do. ChatOptions → tells the model how to do it. Example String response = chatClient . prompt () . user ( "Explain Kafka" ) . options ( OpenAiChatOptions . builder () . temperature ( 0.7 ...