Class: Ollama::Commands::Push

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

Overview

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

This class is used to interact with the Ollama API's push endpoint, which uploads a model to a remote registry. It inherits from the base command structure and provides the necessary functionality to execute push requests for model deployment.

Examples:

Pushing a model to a remote registry

push = ollama.push(model: 'user/llama3.1')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DTO

#==, #as_array, #as_array_of_hashes, #as_hash, #as_json, #empty?, #to_json

Constructor Details

#initialize(model:, insecure: nil, stream: true) ⇒ Push

The initialize method sets up a new instance with streaming enabled by default.

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

Parameters:

  • model (String)

    the name of the model to be pushed

  • insecure (TrueClass, FalseClass, nil) (defaults to: nil)

    whether to allow insecure connections, or nil to use default

  • stream (TrueClass, FalseClass) (defaults to: true)

    whether to enable streaming for the operation, defaults to true



37
38
39
# File 'lib/ollama/commands/push.rb', line 37

def initialize(model:, insecure: nil, stream: true)
  @model, @insecure, @stream = model, insecure, stream
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.



68
69
70
# File 'lib/ollama/commands/push.rb', line 68

def client=(value)
  @client = value
end

#insecureTrueClass, ... (readonly)

The insecure attribute reader returns the insecure connection setting associated with the object.

Returns:

  • (TrueClass, FalseClass, nil)

    the insecure flag indicating whether insecure connections are allowed, or nil if not set



51
52
53
# File 'lib/ollama/commands/push.rb', line 51

def insecure
  @insecure
end

#modelString (readonly)

The model attribute reader returns the model name associated with the object.

Returns:

  • (String)

    the name of the model to be pushed



44
45
46
# File 'lib/ollama/commands/push.rb', line 44

def model
  @model
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



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

def stream
  @stream
end

Class Method Details

.pathString

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

This class method provides the specific URL path used to interact with the Ollama API's push endpoint. It is utilized internally by the command structure to determine the correct API route for uploading models to a remote registry.

Returns:

  • (String)

    the API endpoint path '/api/push' for push requests



21
22
23
# File 'lib/ollama/commands/push.rb', line 21

def self.path
  '/api/push'
end

Instance Method Details

#perform(handler) ⇒ self

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

This method initiates a request to the Ollama API endpoint associated with the command, utilizing the client instance to send the request and process responses through the provided handler. It handles both streaming and non-streaming scenarios based on the command's configuration.

Parameters:

  • handler (Ollama::Handler)

    the handler object responsible for processing API responses

Returns:

  • (self)

    returns the current instance after initiating the request



80
81
82
# File 'lib/ollama/commands/push.rb', line 80

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