Class: ActiveHarness::Providers::Ollama
- Defined in:
- lib/active_harness/providers/ollama.rb
Overview
Ollama — local model inference server, OpenAI-compatible API. ollama.com/blog/openai-compatibility
Set OLLAMA_API_BASE to override the default local address. OLLAMA_API_KEY is optional (needed only if Ollama is behind a proxy with auth).
Example:
model do
use provider: :ollama, model: "llama3.2"
end
Constant Summary
Constants inherited from Base
Base::HTTP, Base::STREAMING_HTTP
Instance Method Summary collapse
Instance Method Details
#call(model:, messages:, temperature: 0.7) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/active_harness/providers/ollama.rb', line 16 def call(model:, messages:, temperature: 0.7) url = URI("#{api_base}/v1/chat/completions") headers = { "Content-Type" => "application/json" } key = api_key headers["Authorization"] = "Bearer #{key}" if key raw = post_json(url, headers: headers, body: { model: model, messages: , temperature: temperature } ) data = parse!(raw) handle_error!(data) { content: data.dig("choices", 0, "message", "content").to_s.strip, provider: :ollama, model: data["model"] || model, usage: extract_usage_openai(data) } end |