Class: Async::Ollama::Client

Inherits:
REST::Resource
  • Object
show all
Defined in:
lib/async/ollama/client.rb

Overview

Represents a connection to the Ollama service.

Constant Summary collapse

ENDPOINT =

The default endpoint to connect to.

Async::HTTP::Endpoint.parse("http://localhost:11434")

Instance Method Summary collapse

Instance Method Details

#generate(prompt, **options, &block) ⇒ Object

Generate a response from the given prompt.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/async/ollama/client.rb', line 18

def generate(prompt, **options, &block)
  options[:prompt] = prompt
  options[:model] ||= "llama3"
  
  Generate.post(self.with(path: "/api/generate"), options) do |resource, response|
    if block_given?
      yield response
    end
    
    Generate.new(resource, value: response.read, metadata: response.headers)
  end
end