Class: Ollama::Commands::Delete

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

Overview

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

This class is used to interact with the Ollama API’s delete endpoint, which removes a specified model from the local system. It inherits from the base command structure and provides the necessary functionality to execute delete requests for model removal.

Examples:

Deleting a local model

delete = ollama.delete(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:) ⇒ Delete

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 the model name to be deleted. It explicitly disables streaming since delete operations are typically non-streaming.



31
32
33
# File 'lib/ollama/commands/delete.rb', line 31

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



55
56
57
# File 'lib/ollama/commands/delete.rb', line 55

def client=(value)
  @client = value
end

#modelString (readonly)

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



38
39
40
# File 'lib/ollama/commands/delete.rb', line 38

def model
  @model
end

#streamFalseClass (readonly)

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



45
46
47
# File 'lib/ollama/commands/delete.rb', line 45

def stream
  @stream
end

Class Method Details

.pathString

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

This class method provides the specific URL path used to interact with the Ollama API’s delete endpoint. It is utilized internally by the command structure to determine the correct API route for removing models from local storage.



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

def self.path
  '/api/delete'
end

Instance Method Details

#perform(handler) ⇒ self

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

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

responses



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

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