Class: OmniAI::Google::Upload

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(client:, io:) ⇒ Upload

Returns a new instance of Upload.

Parameters:



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

Parameters:



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

Returns:

Raises:

  • (HTTPError)


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