Class: RubyLLM::DownloadedFile

Inherits:
String
  • Object
show all
Includes:
Support::Inspectable
Defined in:
lib/ruby_llm/downloaded_file.rb

Overview

A DownloadedFile contains a provider file's bytes. Save it with #save or read the bytes with #to_blob. It is also a String, so parsers and existing string operations work directly on the result.

RubyLLM.download(file.id, provider: :openai).save("report.pdf")

Constant Summary

Constants included from Support::Inspectable

Support::Inspectable::TRUNCATE_AT

Instance Method Summary collapse

Methods included from Support::Inspectable

#full_inspect, #inspect, #pretty_print

Instance Method Details

#save(path) ⇒ Object

Writes the file bytes to path, expanding it first. Returns path.

file.save("report.pdf")


22
23
24
25
# File 'lib/ruby_llm/downloaded_file.rb', line 22

def save(path)
  File.binwrite(File.expand_path(path), to_blob)
  path
end

#to_blobObject

Returns the raw file bytes as a String.



14
15
16
# File 'lib/ruby_llm/downloaded_file.rb', line 14

def to_blob
  to_s
end