Class: Ollama::Commands::BlobExists
- Inherits:
-
Object
- Object
- Ollama::Commands::BlobExists
- Includes:
- Digester
- Defined in:
- lib/ollama/commands/blob_exists.rb
Overview
A command class that represents the blob existence check API endpoint for Ollama.
This class is used to interact with the Ollama API’s blobs endpoint using a HEAD request to verify if a specific binary blob (identified by its digest) already exists on the server. This is particularly useful for optimizing model uploads by avoiding redundant transfers of large files.
Instance Attribute Summary collapse
-
#client ⇒ Object
writeonly
The client attribute writer allows setting the client instance associated with the object.
-
#digest ⇒ String
readonly
The digest attribute reader returns the target blob digest.
-
#stream ⇒ FalseClass
readonly
The stream attribute reader returns the streaming behavior setting.
Instance Method Summary collapse
-
#initialize(digest: nil, blob: nil) ⇒ BlobExists
constructor
The initialize method sets up a new instance with the target digest.
-
#path ⇒ String
The path method constructs the API endpoint URL for a specific binary blob.
-
#perform(handler) ⇒ self
The perform method executes the existence check request using a HEAD method.
Constructor Details
#initialize(digest: nil, blob: nil) ⇒ BlobExists
The initialize method sets up a new instance with the target digest.
This method initializes the command object with the specific digest of the blob being checked and explicitly disables streaming as HEAD requests are inherently non-streaming.
25 26 27 28 29 30 31 32 |
# File 'lib/ollama/commands/blob_exists.rb', line 25 def initialize(digest: nil, blob: nil) digest = prefix_sha256(digest) if digest.nil? && blob digest = compute_digest(blob) end digest or raise ArgumentError, 'require digest or blob to perform' @digest, @stream = digest, false end |
Instance Attribute Details
#client=(value) ⇒ Object (writeonly)
The client attribute writer allows setting the client instance associated with the object.
48 49 50 |
# File 'lib/ollama/commands/blob_exists.rb', line 48 def client=(value) @client = value end |
#digest ⇒ String (readonly)
The digest attribute reader returns the target blob digest.
37 38 39 |
# File 'lib/ollama/commands/blob_exists.rb', line 37 def digest @digest end |
#stream ⇒ FalseClass (readonly)
The stream attribute reader returns the streaming behavior setting.
42 43 44 |
# File 'lib/ollama/commands/blob_exists.rb', line 42 def stream @stream end |
Instance Method Details
#path ⇒ String
The path method constructs the API endpoint URL for a specific binary blob. It interpolates the target blob’s digest into the path string to create the correct resource identifier for the Ollama API.
55 56 57 |
# File 'lib/ollama/commands/blob_exists.rb', line 55 def path "/api/blobs/#{digest}" end |
#perform(handler) ⇒ self
The perform method executes the existence check request using a HEAD method.
This method initiates a HEAD request to the ‘/api/blobs/:digest’ endpoint. A successful response (typically 200 OK) indicates the blob exists, while a 404 Not Found indicates it does not.
69 70 71 72 |
# File 'lib/ollama/commands/blob_exists.rb', line 69 def perform(handler) @client.request(method: :head, path:, stream:, handler:) self end |