class RubyLLM::FileStore::Memory
Keeps files in memory, for as long as the chat lives. It is the store Chat#with_file_store uses when given none.
chat.with_file_store(RubyLLM.file_store.memory)
Public Instance Methods
Source
# File lib/ruby_llm/file_store/memory.rb, line 50 def delete(path) @lock.synchronize { @files.delete(FileStore.path(path))&.first } end
Deletes the file at path and returns its StoredFile, or nil.
Source
# File lib/ruby_llm/file_store/memory.rb, line 25 def find(path) @lock.synchronize { @files[FileStore.path(path)]&.first } end
Returns the StoredFile at path, or nil.
Source
# File lib/ruby_llm/file_store/memory.rb, line 18 def list(prefix = nil) @lock.synchronize { @files.values.map(&:first) } .select { |file| FileStore.inside?(file.path, prefix) } .sort_by(&:path) end
Returns the files inside the folder prefix, or every file.
Source
# File lib/ruby_llm/file_store/memory.rb, line 30 def read(path) path = FileStore.path(path) content = @lock.synchronize { @files[path]&.last } raise FileNotFoundError, "No file at #{path}" unless content content.dup end
Returns the content of the file at path.
# File lib/ruby_llm/file_store/memory.rb, line 39 def write(path, content, content_type: nil) path = FileStore.path(path) content = FileStore.bytes(content).freeze file = StoredFile.new(path:, byte_size: content.bytesize, content_type: content_type || FileStore.content_type_for(path, content), digest: FileStore.digest(content), updated_at: Time.now) @lock.synchronize { @files[path] = [file, content] } file end
Writes content to path and returns its StoredFile.