Class: RubyLLM::Protocols::VertexAI::Files
- Inherits:
-
Protocols::Files
- Object
- Protocols::Files
- RubyLLM::Protocols::VertexAI::Files
- Defined in:
- lib/ruby_llm/protocols/vertexai/files.rb
Overview
Google Cloud Storage-backed files for Vertex AI batch input and output.
Constant Summary collapse
- GCS_URI =
GCS object names allow spaces and other characters URI() rejects.
%r{\Ags://([^/]+)/?(.*)\z}m
Instance Method Summary collapse
- #download(file_id) ⇒ Object
- #find(file_id) ⇒ Object
- #list_uris(prefix_uri) ⇒ Object
-
#upload(file, filename: nil, purpose: nil, expires_in: nil, uri: nil, content_type: nil, provider_options: {}) ⇒ Object
rubocop:disable-next Lint/UnusedMethodArgument.
Instance Method Details
#download(file_id) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/ruby_llm/protocols/vertexai/files.rb', line 48 def download(file_id) bucket_name, key = parse_gcs_uri(file_id) object = bucket(bucket_name).file(key) raise Error, "GCS object not found: #{file_id}" unless object object.download.string end |
#find(file_id) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ruby_llm/protocols/vertexai/files.rb', line 32 def find(file_id) bucket_name, key = parse_gcs_uri(file_id) object = bucket(bucket_name).file(key) raise Error, "GCS object not found: #{file_id}" unless object uploaded_file( { 'uri' => file_id }, id: file_id, uri: file_id, filename: File.basename(key), byte_size: object.size, created_at: object.created_at, mime_type: object.content_type ) end |
#list_uris(prefix_uri) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/ruby_llm/protocols/vertexai/files.rb', line 56 def list_uris(prefix_uri) bucket_name, prefix = parse_gcs_uri(prefix_uri) uris = [] bucket(bucket_name).files(prefix: prefix).all do |object| uris << "gs://#{bucket_name}/#{object.name}" end uris 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 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ruby_llm/protocols/vertexai/files.rb', line 12 def upload(file, filename: nil, purpose: nil, expires_in: nil, uri: nil, content_type: nil, provider_options: {}) = (file, filename:) target_uri = uri || storage_uri_for() bucket_name, key = parse_gcs_uri(target_uri) with_file_body() do |body| bucket(bucket_name).create_file(body, key, content_type: content_type || file_content_type()) end uploaded_file( { 'uri' => target_uri }, id: target_uri, uri: target_uri, filename: .filename, byte_size: file_size(), mime_type: content_type || file_content_type() ) end |