Class: Ollama::Commands::PushBlob
- Inherits:
-
Object
- Object
- Ollama::Commands::PushBlob
- Includes:
- Digester
- Defined in:
- lib/ollama/commands/push_blob.rb
Overview
A command class that represents the push blob API endpoint for Ollama.
This class is used to upload raw binary files (blobs) to the Ollama server. It accepts the content to be uploaded and automatically calculates the required SHA256 digest to target the correct API endpoint.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
The body attribute reader returns the binary content to be uploaded to the Ollama server.
-
#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(body:, digest: nil) ⇒ PushBlob
constructor
The initialize method sets up a new instance and calculates the content digest.
-
#path ⇒ String
The path method returns the API endpoint path for pushing blobs.
-
#perform(handler) ⇒ self
The perform method is not used directly for file uploads in this implementation, as the client uses a specialized streaming request method to handle IO.
Constructor Details
#initialize(body:, digest: nil) ⇒ PushBlob
The initialize method sets up a new instance and calculates the content digest.
This method ensures the body is an IO-like object and computes the SHA256 hash of the content to be used as the target endpoint path.
23 24 25 26 27 28 |
# File 'lib/ollama/commands/push_blob.rb', line 23 def initialize(body:, digest: nil) @body = body.respond_to?(:read) ? body : StringIO.new(body.to_str) digest = prefix_sha256(digest) @digest = digest || compute_digest(@body) @stream = false end |
Instance Attribute Details
#body ⇒ Object (readonly)
The body attribute reader returns the binary content to be uploaded to the Ollama server.
34 35 36 |
# File 'lib/ollama/commands/push_blob.rb', line 34 def body @body end |
#client=(value) ⇒ Object (writeonly)
The client attribute writer allows setting the client instance associated with the object.
50 51 52 |
# File 'lib/ollama/commands/push_blob.rb', line 50 def client=(value) @client = value end |
#digest ⇒ String (readonly)
The digest attribute reader returns the target blob digest.
39 40 41 |
# File 'lib/ollama/commands/push_blob.rb', line 39 def digest @digest end |
#stream ⇒ FalseClass (readonly)
The stream attribute reader returns the streaming behavior setting.
44 45 46 |
# File 'lib/ollama/commands/push_blob.rb', line 44 def stream @stream end |
Instance Method Details
#path ⇒ String
The path method returns the API endpoint path for pushing blobs.
This method interpolates the digest into the URL to target a specific blob.
57 58 59 |
# File 'lib/ollama/commands/push_blob.rb', line 57 def path "/api/blobs/#{digest}" end |
#perform(handler) ⇒ self
The perform method is not used directly for file uploads in this implementation, as the client uses a specialized streaming request method to handle IO. However, it’s kept for interface consistency.
69 70 71 72 73 |
# File 'lib/ollama/commands/push_blob.rb', line 69 def perform(handler) @client.blob_exists?(digest) or @client.upload_file(path:, body:, handler:) handler.result = digest self end |