Skip to content

πŸ¦™ feat(providers): Ollama LLM provider β€” chat, embedding, streaming, function callingΒ #96

Description

@sbharatjoshi

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

  1. Implement in providers/spector-providers module
  2. Create META-INF/services/com.spectrayan.spector.provider.spi.ProviderFactory for ServiceLoader
  3. Use java.net.http.HttpClient for all HTTP calls
  4. Parse NDJSON streaming: read line-by-line, parse each line as JSON
  5. Reference the ProviderFactory SPI from spector-provider-spi
  6. 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions