Class: Ollama::Commands::Generate

Inherits:
Object
  • Object
show all
Includes:
DTO
Defined in:
lib/ollama/commands/generate.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DTO

#as_array_of_hashes, #as_json, #empty?, #to_json

Constructor Details

#initialize(model:, prompt:, suffix: nil, images: nil, format: nil, options: nil, system: nil, template: nil, context: nil, stream: nil, raw: nil, keep_alive: nil) ⇒ Generate

Returns a new instance of Generate.



8
9
10
11
# File 'lib/ollama/commands/generate.rb', line 8

def initialize(model:, prompt:, suffix: nil, images: nil, format: nil, options: nil, system: nil, template: nil, context: nil, stream: nil, raw: nil, keep_alive: nil)
  @model, @prompt, @suffix, @images, @format, @options, @system, @template, @context, @stream, @raw, @keep_alive =
    model, prompt, suffix, (Array(images) if images), format, options, system, template, context, stream, raw, keep_alive
end

Instance Attribute Details

#client=(value) ⇒ Object (writeonly)

Sets the attribute client

Parameters:

  • value

    the value to set the attribute client to.



16
17
18
# File 'lib/ollama/commands/generate.rb', line 16

def client=(value)
  @client = value
end

#contextObject (readonly)

Returns the value of attribute context.



13
14
15
# File 'lib/ollama/commands/generate.rb', line 13

def context
  @context
end

#formatObject (readonly)

Returns the value of attribute format.



13
14
15
# File 'lib/ollama/commands/generate.rb', line 13

def format
  @format
end

#imagesObject (readonly)

Returns the value of attribute images.



13
14
15
# File 'lib/ollama/commands/generate.rb', line 13

def images
  @images
end

#keep_aliveObject (readonly)

Returns the value of attribute keep_alive.



13
14
15
# File 'lib/ollama/commands/generate.rb', line 13

def keep_alive
  @keep_alive
end

#modelObject (readonly)

Returns the value of attribute model.



13
14
15
# File 'lib/ollama/commands/generate.rb', line 13

def model
  @model
end

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/ollama/commands/generate.rb', line 13

def options
  @options
end

#promptObject (readonly)

Returns the value of attribute prompt.



13
14
15
# File 'lib/ollama/commands/generate.rb', line 13

def prompt
  @prompt
end

#rawObject (readonly)

Returns the value of attribute raw.



13
14
15
# File 'lib/ollama/commands/generate.rb', line 13

def raw
  @raw
end

#streamObject (readonly)

Returns the value of attribute stream.



13
14
15
# File 'lib/ollama/commands/generate.rb', line 13

def stream
  @stream
end

#suffixObject (readonly)

Returns the value of attribute suffix.



13
14
15
# File 'lib/ollama/commands/generate.rb', line 13

def suffix
  @suffix
end

#systemObject (readonly)

Returns the value of attribute system.



13
14
15
# File 'lib/ollama/commands/generate.rb', line 13

def system
  @system
end

#templateObject (readonly)

Returns the value of attribute template.



13
14
15
# File 'lib/ollama/commands/generate.rb', line 13

def template
  @template
end

Class Method Details

.pathObject



4
5
6
# File 'lib/ollama/commands/generate.rb', line 4

def self.path
  '/api/generate'
end

Instance Method Details

#perform(handler) ⇒ Object



18
19
20
# File 'lib/ollama/commands/generate.rb', line 18

def perform(handler)
  @client.request(method: :post, path: self.class.path, body: to_json, stream:, handler:)
end