Add OllamaLiteClient for zero-dependency Ollama access#6626
Open
vijaytank wants to merge 1 commit into
Open
Conversation
Users running Ollama in CLI tools, edge utilities, and lightweight apps face real pain with the full Spring AI Ollama stack: - The WebClient/RestClient transitive dependency graph adds significant classpath weight for scenarios that only need a single blocking generate() call (spring-projects#5838). - WebClient read timeouts fire immediately for slow/large-prompt Ollama responses with no straightforward configuration path (spring-projects#3573). - Reactive cancellation signals do not cleanly terminate the underlying Ollama inference thread, causing GPU resource leaks (spring-projects#2351, spring-projects#2944). OllamaLiteClient solves these by using only java.net.http.HttpClient (JDK 11+, zero external dependencies). It targets the /api/generate endpoint with a simple blocking generate(model, prompt) call, proper input validation, and safe JSON escaping. It lives alongside the existing OllamaApi so users can choose the right tool for their needs. See spring-projects#5838 See spring-projects#3573 See spring-projects#2351 See spring-projects#2944 Signed-off-by: Vijay Tank <vijaytank132@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Users running Ollama from CLI tools, edge utilities, or lightweight apps hit several compounding issues with the full Spring AI Ollama stack:
generate()call (see Use JDK HttpClient with OpenAI SDK instead of OkHttp3 #5838).Solution
OllamaLiteClientis a zero-external-dependency alternative that uses onlyjava.net.http.HttpClient(JDK 11+). It provides a single blockinggenerate(model, prompt)method targeting/api/generate, with proper input validation and safe JSON character escaping.It lives alongside the existing
OllamaApiin theorg.springframework.ai.ollama.apipackage — users who need the full Spring stack (streaming, observability, retry, auto-configuration) should continue usingOllamaApi+OllamaChatModel.