Class: Ollama::Commands::Chat

Inherits:
Object
  • Object
show all
Includes:
DTO
Defined in:
lib/ollama/commands/chat.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:, messages:, tools: nil, format: nil, options: nil, stream: nil, keep_alive: nil) ⇒ Chat

Returns a new instance of Chat.



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

def initialize(model:, messages:, tools: nil, format: nil, options: nil, stream: nil, keep_alive: nil)
  @model, @messages, @tools, @format, @options, @stream, @keep_alive =
    model, as_array_of_hashes(messages), as_array_of_hashes(tools),
    format, options, stream, 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/chat.rb', line 16

def client=(value)
  @client = value
end

#formatObject (readonly)

Returns the value of attribute format.



14
15
16
# File 'lib/ollama/commands/chat.rb', line 14

def format
  @format
end

#keep_aliveObject (readonly)

Returns the value of attribute keep_alive.



14
15
16
# File 'lib/ollama/commands/chat.rb', line 14

def keep_alive
  @keep_alive
end

#messagesObject (readonly)

Returns the value of attribute messages.



14
15
16
# File 'lib/ollama/commands/chat.rb', line 14

def messages
  @messages
end

#modelObject (readonly)

Returns the value of attribute model.



14
15
16
# File 'lib/ollama/commands/chat.rb', line 14

def model
  @model
end

#optionsObject (readonly)

Returns the value of attribute options.



14
15
16
# File 'lib/ollama/commands/chat.rb', line 14

def options
  @options
end

#streamObject (readonly)

Returns the value of attribute stream.



14
15
16
# File 'lib/ollama/commands/chat.rb', line 14

def stream
  @stream
end

#toolsObject (readonly)

Returns the value of attribute tools.



14
15
16
# File 'lib/ollama/commands/chat.rb', line 14

def tools
  @tools
end

Class Method Details

.pathObject



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

def self.path
  '/api/chat'
end

Instance Method Details

#perform(handler) ⇒ Object



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

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