Class: RubyLLM::Protocols::Bedrock::Files
- Inherits:
-
Protocols::Files
- Object
- Protocols::Files
- RubyLLM::Protocols::Bedrock::Files
- Defined in:
- lib/ruby_llm/protocols/bedrock/files.rb
Overview
S3-backed file storage for Bedrock batch input and output.
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
45 46 47 48 |
# File 'lib/ruby_llm/protocols/bedrock/files.rb', line 45 def download(file_id) bucket, key = parse_s3_uri(file_id) s3_client.get_object(bucket: bucket, key: key).body.read end |
#find(file_id) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ruby_llm/protocols/bedrock/files.rb', line 30 def find(file_id) bucket, key = parse_s3_uri(file_id) response = s3_client.head_object(bucket: bucket, key: key) uploaded_file( { 'uri' => file_id }, id: file_id, uri: file_id, filename: File.basename(key), byte_size: response.content_length, created_at: response.last_modified, mime_type: response.content_type ) end |
#list_uris(prefix_uri) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ruby_llm/protocols/bedrock/files.rb', line 50 def list_uris(prefix_uri) bucket, prefix = parse_s3_uri(prefix_uri) uris = [] token = nil loop do = { bucket: bucket, prefix: prefix } [:continuation_token] = token if token response = s3_client.list_objects_v2(**) uris.concat(Array(response.contents).map { |object| "s3://#{bucket}/#{object.key}" }) token = response.next_continuation_token break unless token 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
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ruby_llm/protocols/bedrock/files.rb', line 9 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, key = parse_s3_uri(target_uri) with_file_body() do |body| s3_client.put_object(bucket: bucket, key: key, body: body, 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 |