Class: Ollama::Commands::Ps

Inherits:
Object
  • Object
show all
Defined in:
lib/ollama/commands/ps.rb

Overview

A command class that represents the ps API endpoint for Ollama.

This class is used to interact with the Ollama API’s ps endpoint, which retrieves information about running models. It inherits from the base command structure and provides the necessary functionality to execute ps requests for monitoring active model processes.

Examples:

Retrieving information about running models

ps = ollama.ps
ps.models # => array of running model information

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**parameters) ⇒ Ps

The initialize method sets up a new instance with streaming disabled.

This method is responsible for initializing a new object instance and configuring it with a default setting that disables streaming behavior. It is typically called during the object creation process to establish the initial state of the instance.

Parameters:

  • parameters (Hash)

    a hash containing initialization parameters (must be empty for this command)

Raises:

  • (ArgumentError)

    if any parameters are provided (ps endpoint does not accept parameters)



36
37
38
39
40
# File 'lib/ollama/commands/ps.rb', line 36

def initialize(**parameters)
  parameters.empty? or raise ArgumentError,
    "Invalid parameters: #{parameters.keys * ' '}"
  @stream = false
end

Instance Attribute Details

#client=(value) ⇒ Object (writeonly)

The client attribute writer allows setting the client instance associated with the object.

This method assigns the client that will be used to perform requests and handle responses for this command. It is typically called internally when a command is executed through a client instance.



58
59
60
# File 'lib/ollama/commands/ps.rb', line 58

def client=(value)
  @client = value
end

#streamTrueClass, FalseClass (readonly)

The stream attribute reader returns the streaming behavior setting associated with the object.

Returns:

  • (TrueClass, FalseClass)

    the streaming behavior flag, indicating whether streaming is enabled for the command execution (always false for ps commands)



48
49
50
# File 'lib/ollama/commands/ps.rb', line 48

def stream
  @stream
end

Class Method Details

.pathString

The path method returns the API endpoint path for ps requests.

This class method provides the specific URL path used to interact with the Ollama API’s ps endpoint. It is utilized internally by the command structure to determine the correct API route for retrieving information about running models.

Returns:

  • (String)

    the API endpoint path ‘/api/ps’ for ps requests



20
21
22
# File 'lib/ollama/commands/ps.rb', line 20

def self.path
  '/api/ps'
end

Instance Method Details

#perform(handler) ⇒ self

The perform method executes a command request using the specified handler.

This method initiates a GET request to the Ollama API’s ps endpoint, utilizing the client instance to send the request and process responses through the provided handler. It handles non-streaming scenarios since ps commands do not support streaming.

responses

Parameters:

  • handler (Ollama::Handler)

    the handler object responsible for processing API

Returns:

  • (self)

    returns the current instance after initiating the request



71
72
73
# File 'lib/ollama/commands/ps.rb', line 71

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