Summary
Implement the Ollama LLM provider β connecting Spector to locally-running Ollama models with chat completion, embedding generation, streaming, and function calling support. This is the default provider for local development.
ποΈ Technical Specifications
SPI : Implements ProviderFactory via ServiceLoader (ADR-003)
Module : spector-providers β com.spectrayan.spector.provider.ollama
Key Classes :
OllamaProviderFactory β ServiceLoader entry point, creates OllamaProvider instances
OllamaProvider β implements LlmProvider interface: chat(), chatStream(), embed()
OllamaChatClient β HTTP client wrapping Ollama's REST API
Ollama API Endpoints :
Chat: POST /api/chat with {"model": "...", "messages": [...], "stream": true}
Embedding: POST /api/embed with {"model": "...", "input": "..."}
Models: GET /api/tags (list available models)
HTTP Client : java.net.http.HttpClient with virtual thread executor
Streaming : Parse NDJSON (newline-delimited JSON) response for streaming chat
Configuration : OLLAMA_BASE_URL (default: http://localhost:11434), SPECTOR_OLLAMA_MODEL (default: llama3.2)
Function Calling : Map AgentTool definitions to Ollama's tool format (supported in Ollama 0.5+)
β
Acceptance Criteria
Given OLLAMA_BASE_URL is set, when the provider initializes, then it connects to Ollama and verifies model availability
Given chat completion is requested, when Ollama is called, then responses are returned
Given streaming is enabled, when tokens are generated, then they stream via SSE
Given function calling is used, when tools are defined, then Ollama's native tool format is used
Given embedding is requested, when embed() is called, then embeddings are returned as float[]
π Contributor Guidance
Implement in providers/spector-providers module
Create META-INF/services/com.spectrayan.spector.provider.spi.ProviderFactory for ServiceLoader
Use java.net.http.HttpClient for all HTTP calls
Parse NDJSON streaming: read line-by-line, parse each line as JSON
Reference the ProviderFactory SPI from spector-provider-spi
Build: mvn clean compile -pl providers/spector-providers
π References
Ollama API
spector-provider-spi for the ProviderFactory interface
RICE-C Score
Factor
Score
Rationale
Reach
5/5
Default local provider
Impact
3x
Core functionality
Effort
M
~2 days
Summary
Implement the Ollama LLM provider β connecting Spector to locally-running Ollama models with chat completion, embedding generation, streaming, and function calling support. This is the default provider for local development.
ποΈ Technical Specifications
ProviderFactoryviaServiceLoader(ADR-003)spector-providersβcom.spectrayan.spector.provider.ollamaOllamaProviderFactoryβServiceLoaderentry point, createsOllamaProviderinstancesOllamaProviderβ implementsLlmProviderinterface:chat(),chatStream(),embed()OllamaChatClientβ HTTP client wrapping Ollama's REST APIPOST /api/chatwith{"model": "...", "messages": [...], "stream": true}POST /api/embedwith{"model": "...", "input": "..."}GET /api/tags(list available models)java.net.http.HttpClientwith virtual thread executorOLLAMA_BASE_URL(default:http://localhost:11434),SPECTOR_OLLAMA_MODEL(default:llama3.2)AgentTooldefinitions to Ollama's tool format (supported in Ollama 0.5+)β Acceptance Criteria
OLLAMA_BASE_URLis set, when the provider initializes, then it connects to Ollama and verifies model availabilityembed()is called, then embeddings are returned asfloat[]π Contributor Guidance
providers/spector-providersmoduleMETA-INF/services/com.spectrayan.spector.provider.spi.ProviderFactoryfor ServiceLoaderjava.net.http.HttpClientfor all HTTP callsProviderFactorySPI fromspector-provider-spimvn clean compile -pl providers/spector-providersπ References
spector-provider-spifor theProviderFactoryinterfaceRICE-C Score