Class: RubyCanUseLLM::Providers::Ollama

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

Constant Summary collapse

DEFAULT_BASE_URL =
"http://localhost:11434"

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from RubyCanUseLLM::Providers::Base

Instance Method Details

#chat(messages, **options, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/rubycanusellm/providers/ollama.rb', line 12

def chat(messages, **options, &block)
  if options[:stream] && block
    body = build_body(messages, options.except(:stream)).merge(stream: true)
    stream_request(body, &block)
  else
    body = build_body(messages, options).merge(stream: false)
    response = request(body)
    parse_response(response)
  end
end

#embed(text, **options) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/rubycanusellm/providers/ollama.rb', line 23

def embed(text, **options)
  body = {
    model: options[:model] || "nomic-embed-text",
    input: text
  }
  response = embedding_request(body)
  parse_embedding(response)
end