Class: RubyLLM::Protocols::Gemini::Files

Inherits:
Protocols::Files
  • Object
show all
Defined in:
lib/ruby_llm/protocols/gemini/files.rb

Overview

Gemini Files API.

Constant Summary collapse

PROCESSING_POLL_INTERVAL =
2
PROCESSING_TIMEOUT =
600

Instance Method Summary collapse

Instance Method Details

#download(file_id) ⇒ Object

Raises:



21
22
23
24
25
26
27
28
29
# File 'lib/ruby_llm/protocols/gemini/files.rb', line 21

def download(file_id)
  file = find(file_id)
  download_uri = file.['downloadUri']
  raise Error, 'gemini file has no download URI' unless download_uri

  gemini_connection(request_json: false, response_json: false).get(download_uri) do |request|
    request.headers.merge!(@provider.headers)
  end.body
end

#upload(file, filename: nil, purpose: nil, expires_in: nil, uri: nil, content_type: nil, provider_options: {}) ⇒ Object

rubocop:disable-next Lint/UnusedMethodArgument



12
13
14
15
16
17
18
19
# File 'lib/ruby_llm/protocols/gemini/files.rb', line 12

def upload(file, filename: nil, purpose: nil, expires_in: nil, uri: nil, content_type: nil,
           provider_options: {})
  attachment = file_attachment(file, filename:)
  display_name = provider_options[:display_name] || attachment.filename
  upload_url = start_resumable_upload(attachment, display_name:)
  response = upload_file_bytes(upload_url, attachment)
  await_active(parse_file_response(response.body.fetch('file')))
end