Skip to content

Add Local Model Support via Ollama Integration #2

@crmne

Description

@crmne

TL;DR: Add support for running fully local models via Ollama.

Background

While cloud models offer state-of-the-art capabilities, there are compelling cases for running models locally:

  1. Privacy & Compliance: Keep sensitive data entirely on-premise
  2. Cost Control: Eliminate ongoing API costs for high-volume applications
  3. Latency: Remove network overhead for latency-sensitive applications
  4. Offline Operation: Run AI features without internet connectivity

Ollama provides an excellent way to run models like Llama, Mistral, and others locally with a simple API that's compatible with our existing architecture.

Proposed Solution

Add a new provider interface for Ollama that implements our existing abstractions:

# Configuration
RubyLLM.configure do |config|
  config.ollama_host = "http://localhost:11434" # Default
end

# Usage remains identical to cloud models
chat = RubyLLM.chat(model: 'llama2')
chat.ask("What's the capital of France?")

# Or with embeddings
RubyLLM.embed("Ruby is a programmer's best friend", model: 'nomic-embed-text')

Technical Details

For those looking to help implement this, you'll need to:

  1. Create a new provider module in lib/ruby_llm/providers/ollama/
  2. Implement the core provider interface methods:
    • complete - For chat functionality
    • embed - For embeddings
    • api_base - Returns the Ollama API endpoint
    • capabilities - Define model capabilities
  3. Handle the payload formatting differences between Ollama and OpenAI/Claude

The PR should include:

  • Provider implementation
  • Configuration option for Ollama host
  • Tests that can be run against a local Ollama instance
  • Documentation updates

Benefits

  • Cost efficiency: Eliminate API costs for many use cases
  • Privacy: Keep sensitive data local
  • Flexibility: Mix and match local and cloud models in the same codebase
  • Performance: Reduce latency for response-time sensitive applications

Metadata

Metadata

Assignees

No one assigned

    Labels

    new providerNew provider integration

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions