Class: RubyLLM::Protocols::Files
- Inherits:
-
RubyLLM::Protocol
- Object
- RubyLLM::Protocol
- RubyLLM::Protocols::Files
- Defined in:
- lib/ruby_llm/protocols/files.rb
Overview
Provider-managed file storage APIs.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from RubyLLM::Protocol
#config, #connection, #model, #provider
Instance Method Summary collapse
- #download(file_id) ⇒ Object
- #find(file_id) ⇒ Object
- #list_uris(_uri) ⇒ Object
-
#upload(file, filename: nil, purpose: nil, expires_in: nil, uri: nil, content_type: nil, provider_options: {}) ⇒ Object
rubocop:disable-next Lint/UnusedMethodArgument.
Methods inherited from RubyLLM::Protocol
abstract, #animate_later, #apply_compaction, #apply_compaction_headers, #apply_end_user, #cache_content, #compact, #complete, #count_tokens, #delete_cache, #embed, #extend_cache, #find_cache, #initialize, #list_models, #moderate, #ocr, #paint, #parse_error, #parse_image_responses, #post_image, #post_video, #preprocess_message, #raise_transcription_streaming_unsupported, #refresh_video_job, #render, #render_embedding, #render_transcription_options, #render_video_extension_payload, #rerank, #server_tool_aliases, #speak, #stream_speech, #stream_speech_response, #stream_transcription, #supports_embedding_media?, #tokenize, #tool_approval_response, #transcribe, #video_extension_attachment, #video_extension_url, #video_request_url
Methods included from RubyLLM::Protocol::BinaryStreaming
Methods included from RubyLLM::Protocol::Streaming
build_on_data_handler, build_stream_error_response, error_chunk?, failed_http_status, faraday_1?, handle_data, handle_error_chunk, handle_error_event, handle_failed_response, handle_json_error_chunk, handle_sse, handle_stream, json_error_payload?, parse_error_from_json, parse_streaming_error, process_stream_chunk, raise_stream_error, stream_events, stream_response, stream_state
Constructor Details
This class inherits a constructor from RubyLLM::Protocol
Instance Method Details
#download(file_id) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/ruby_llm/protocols/files.rb', line 26 def download(file_id) response = @connection.get(download_file_url(file_id)) do |request| request.headers['Accept'] = 'application/octet-stream' file_headers(request) end response.body end |
#find(file_id) ⇒ Object
21 22 23 24 |
# File 'lib/ruby_llm/protocols/files.rb', line 21 def find(file_id) response = @connection.get(file_info_url(file_id)) { |request| file_headers(request) } parse_file_response(response.body) end |
#list_uris(_uri) ⇒ Object
34 35 36 |
# File 'lib/ruby_llm/protocols/files.rb', line 34 def list_uris(_uri) raise Error, "#{@provider.slug} doesn't support file listing" end |
#upload(file, filename: nil, purpose: nil, expires_in: nil, uri: nil, content_type: nil, provider_options: {}) ⇒ Object
rubocop:disable-next Lint/UnusedMethodArgument
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ruby_llm/protocols/files.rb', line 10 def upload(file, filename: nil, purpose: nil, expires_in: nil, uri: nil, content_type: nil, provider_options: {}) = (file, filename:) = { purpose:, expires_in: }.compact.merge(.transform_keys(&:to_sym)) response = @connection.post(files_url, render_upload_payload(, **), idempotent: false) do |request| request.headers.delete('Content-Type') upload_headers(request) end parse_file_response(response.body) end |