Class: OmniAI::Google::Upload
- Inherits:
-
Object
- Object
- OmniAI::Google::Upload
- Defined in:
- lib/omniai/google/upload.rb,
lib/omniai/google/upload/file.rb
Overview
Uploads a file to Google to be used when generating completions.
Defined Under Namespace
Classes: FetchError, File
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(client:, io:) ⇒ Upload
constructor
A new instance of Upload.
- #process! ⇒ Upload::File
Constructor Details
#initialize(client:, io:) ⇒ Upload
Returns a new instance of Upload.
17 18 19 20 |
# File 'lib/omniai/google/upload.rb', line 17 def initialize(client:, io:) @client = client @io = io end |
Class Method Details
.process!(client:, io:) ⇒ Object
11 12 13 |
# File 'lib/omniai/google/upload.rb', line 11 def self.process!(client:, io:) new(client:, io:).process! end |
Instance Method Details
#process! ⇒ Upload::File
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/omniai/google/upload.rb', line 25 def process! response = io! do |io| response = @client .connection .headers({ 'X-Goog-Upload-Protocol' => 'raw' }) .post("/upload/#{@client.version}/files?key=#{@client.api_key}", body: HTTP::FormData::File.new(io)) end raise OmniAI::HTTPError, response.flush unless response.status.ok? File.parse(client: @client, data: response.parse['file']) end |