Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/ruby_llm/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Configuration
:openrouter_api_key,
:xai_api_key,
:ollama_api_base,
:ollama_api_key,
:gpustack_api_base,
:gpustack_api_key,
:mistral_api_key,
Expand Down
4 changes: 3 additions & 1 deletion lib/ruby_llm/providers/ollama.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def api_base
end

def headers
{}
return {} unless @config.ollama_api_key

{ 'Authorization' => "Bearer #{@config.ollama_api_key}" }
end

class << self
Expand Down
23 changes: 23 additions & 0 deletions spec/ruby_llm/providers/ollama_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe RubyLLM::Providers::Ollama do
include_context 'with configured RubyLLM'

describe '#headers' do
it 'returns empty headers when no API key is configured' do
RubyLLM.configure { |config| config.ollama_api_key = nil }
provider = described_class.new(RubyLLM.config)

expect(provider.headers).to eq({})
end

it 'returns Authorization header when API key is configured' do
RubyLLM.configure { |config| config.ollama_api_key = 'test-ollama-key' }
provider = described_class.new(RubyLLM.config)

expect(provider.headers).to eq({ 'Authorization' => 'Bearer test-ollama-key' })
end
end
end
1 change: 1 addition & 0 deletions spec/support/rubyllm_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
config.mistral_api_key = ENV.fetch('MISTRAL_API_KEY', 'test')
config.model_registry_class = 'Model'
config.ollama_api_base = ENV.fetch('OLLAMA_API_BASE', 'http://localhost:11434/v1')
config.ollama_api_key = ENV.fetch('OLLAMA_API_KEY', nil)
config.openai_api_key = ENV.fetch('OPENAI_API_KEY', 'test')
config.openrouter_api_key = ENV.fetch('OPENROUTER_API_KEY', 'test')
config.perplexity_api_key = ENV.fetch('PERPLEXITY_API_KEY', 'test')
Expand Down