class RubyLLM::StoredFile
A file in a FileStore: its path, size, content type, and a digest of its content. FileStore#list and FileStore#find return them, and Chat#after_file_write callbacks receive each one the conversation writes.
chat.file_store.list # => [#<RubyLLM::StoredFile path: "report.pdf", byte_size: 2201344, content_type: "application/pdf">]
Attributes
The size of the file in bytes.
The MIME type of the file, such as "application/pdf".
A digest of the fileโs content that changes whenever the content does, or nil when the store does not know one without reading the file. Stores in the box use SHA-256 in hex.
Who wrote the file, for stores that keep one, or nil. RubyLLM stores it and hands it back without interpreting it.
The path of the file inside its store, relative and with forward slashes, such as "reports/q3.pdf".
When the file was last written, or nil when the store does not say.
Public Instance Methods
Source
# File lib/ruby_llm/stored_file.rb, line 74 def ==(other) other.is_a?(StoredFile) && other.to_h.except(:updated_at, :owner) == to_h.except(:updated_at, :owner) end
Returns whether other is a StoredFile with the same path, size, content type, and digest.
Source
# File lib/ruby_llm/stored_file.rb, line 51 def filename File.basename(path) end
Returns the last part of path.
file.path # => "reports/q3.pdf" file.filename # => "q3.pdf"
Source
# File lib/ruby_llm/stored_file.rb, line 63 def human_size units = %w[bytes KB MB GB TB] size = byte_size.to_f exponent = size.zero? ? 0 : [(Math.log(size) / Math.log(1024)).floor, units.size - 1].min return "#{byte_size} #{byte_size == 1 ? 'byte' : 'bytes'}" if exponent.zero? "#{(size / (1024**exponent)).round(1)} #{units[exponent]}" end
Returns the fileโs size for people and models to read, such as "2.1 MB".
Source
# File lib/ruby_llm/stored_file.rb, line 57 def text? Files::MimeType.text?(content_type) end
Returns whether the content is text, like source code, CSV, or Markdown, judged by its content type.
Source
# File lib/ruby_llm/stored_file.rb, line 84 def to_h { path:, byte_size:, content_type:, digest:, updated_at:, owner: } end
Returns the attributes as a Hash.