Class: ActiveAgent::Providers::Ollama

Inherits:
Base
  • Object
show all
Defined in:
lib/active_agent/providers/ollama.rb

Constant Summary collapse

DEFAULT_URL =
'http://localhost:11434/v1/chat/completions'

Instance Attribute Summary

Attributes inherited from Base

#api_key, #api_url, #model

Instance Method Summary collapse

Constructor Details

#initialize(model: 'llama3', api_key: nil, api_url: nil) ⇒ Ollama

Returns a new instance of Ollama.



10
11
12
13
# File 'lib/active_agent/providers/ollama.rb', line 10

def initialize(model: 'llama3', api_key: nil, api_url: nil)
  url = api_url || DEFAULT_URL
  super(model: model, api_key: api_key, api_url: url)
end

Instance Method Details

#chat(messages:, tools: []) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/active_agent/providers/ollama.rb', line 15

def chat(messages:, tools: [])
  headers = { 'Content-Type' => 'application/json' }
  payload = {
    model: @model,
    messages: messages,
    temperature: 0.2
  }

  data = http_post(@api_url, headers, payload)
  message = data.dig('choices', 0, 'message') || {}

  { content: message['content'], tool_calls: nil }
end