class Ollama::Commands::Chat

chat = ollama.chat(model: ‘llama3.1’, stream: true, messages:)
]
Ollama::Message.new(role: ‘assistant’, content: ‘I am doing well, thank you!’)
Ollama::Message.new(role: ‘user’, content: ‘Hello, how are you?’),
messages = [
@example Initiating a chat conversation
chat requests for interactive conversations with language models.
the base command structure and provides the necessary functionality to execute
generates conversational responses using a specified model. It inherits from
This class is used to interact with the Ollama API’s chat endpoint, which
A command class that represents the chat API endpoint for Ollama.

def self.path

Returns:
  • (String) - the API endpoint path '/api/chat' for chat requests
def self.path
  '/api/chat'
end

def initialize(model:, messages:, tools: nil, format: nil, options: nil, stream: nil, keep_alive: nil, think: nil)

Parameters:
  • think (Boolean, String, nil) -- whether to enable thinking mode for
  • keep_alive (String, nil) -- duration to keep the model loaded in memory
  • stream (TrueClass, FalseClass, nil) -- whether to enable streaming for the operation
  • options (Ollama::Options, nil) -- configuration parameters for the model
  • format (String, nil) -- response format (e.g., 'json')
  • tools (Array, Hash, nil) -- tools available for function calling
  • messages (Array, Hash, nil) -- conversation history with roles and content
  • model (String) -- the name of the model to use for chat responses
def initialize(model:, messages:, tools: nil, format: nil, options: nil, stream: nil, keep_alive: nil, think: nil)
  @model, @messages, @tools, @format, @options, @stream, @keep_alive, @think =
    model, as_array_of_hashes(messages), as_array_of_hashes(tools),
    format, options, stream, keep_alive, think
end

def perform(handler)

Returns:
  • (self) - returns the current instance after initiating the request

Parameters:
  • handler (Ollama::Handler) -- the handler object responsible for processing API
def perform(handler)
  @client.request(method: :post, path: self.class.path, body: to_json, stream:, handler:)
end