Class: Ollama::Attachment
- Inherits:
-
Object
- Object
- Ollama::Attachment
- Defined in:
- lib/ollama/attachment.rb
Overview
Typed attachment payload for multimodal inputs.
Each variant normalizes to a single hash accepted by Ollama as the
:images entry on a user message: { type: "...", data: "..." }.
Example:
Ollama::Attachment.file("photo.png")
# => { type: "file", data: "photo.png" }
Ollama::Attachment.base64(b64_string)
# => { type: "base64", data: b64_string }
Ollama::Attachment.url("https://...")
# => { type: "url", data: "https://..." }
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.base64(data) ⇒ Object
type:"base64",data:base64-encoded string. -
.file(path) ⇒ Object
type:"file",data:path(string orPathname). -
.url(url) ⇒ Object
type:"url",data:remote URL.
Instance Method Summary collapse
-
#initialize(type, data) ⇒ Attachment
constructor
A new instance of Attachment.
- #to_h ⇒ Object
Constructor Details
#initialize(type, data) ⇒ Attachment
Returns a new instance of Attachment.
24 25 26 27 |
# File 'lib/ollama/attachment.rb', line 24 def initialize(type, data) @type = type.to_s @data = coerce(data) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
20 21 22 |
# File 'lib/ollama/attachment.rb', line 20 def data @data end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
20 21 22 |
# File 'lib/ollama/attachment.rb', line 20 def type @type end |
Class Method Details
.base64(data) ⇒ Object
type: "base64", data: base64-encoded string
42 43 44 |
# File 'lib/ollama/attachment.rb', line 42 def self.base64(data) new("base64", data) end |
.file(path) ⇒ Object
type: "file", data: path (string or Pathname). Reads as base64 when a file path is supplied.
Uses base64-encoded file when a file path is supplied.
31 32 33 34 35 36 37 38 39 |
# File 'lib/ollama/attachment.rb', line 31 def self.file(path) path = path.to_s data = if path.include?("\n") || path.include?("+") path else base64_from_file(path) end new("file", data) end |
.url(url) ⇒ Object
type: "url", data: remote URL
47 48 49 |
# File 'lib/ollama/attachment.rb', line 47 def self.url(url) new("url", url.to_s) end |
Instance Method Details
#to_h ⇒ Object
51 52 53 |
# File 'lib/ollama/attachment.rb', line 51 def to_h { "type" => type, "data" => data } end |