Class: BddOpenai::FileClient

Inherits:
Object
  • Object
show all
Defined in:
lib/bdd_openai/file_client.rb

Overview

Client for OpenAI Files API Ref: platform.openai.com/docs/api-reference/files

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key = '') ⇒ FileClient

Returns a new instance of FileClient.



15
16
17
# File 'lib/bdd_openai/file_client.rb', line 15

def initialize(api_key = '')
  @api_key = api_key
end

Instance Attribute Details

#api_keyObject

Parameters:

  • api_key (String)

    The key of the OpenAI API



13
14
15
# File 'lib/bdd_openai/file_client.rb', line 13

def api_key
  @api_key
end

Instance Method Details

#delete_file(file_id) ⇒ true, BddOpenai::ErrorResponse

Parameters:

  • file_id (String)

    The id of the file to delete

Returns:



33
34
35
# File 'lib/bdd_openai/file_client.rb', line 33

def delete_file(file_id)
  BddOpenai::Services::Files::Delete.new(@api_key).delete_file(file_id)
end

#list_filesArray<BddOpenai::Mapper::File>, BddOpenai::ErrorResponse



20
21
22
# File 'lib/bdd_openai/file_client.rb', line 20

def list_files
  BddOpenai::Services::Files::List.new(@api_key).list_files
end

#retrieve_file(file_id) ⇒ BddOpenai::Mapper::File, BddOpenai::ErrorResponse

Parameters:

  • file_id (String)

    The id of the file to retrieve

Returns:



39
40
41
# File 'lib/bdd_openai/file_client.rb', line 39

def retrieve_file(file_id)
  BddOpenai::Services::Files::Retrieve.new(@api_key).retrieve_file(file_id)
end

#upload_file(purpose, file_path) ⇒ BddOpenai::Mapper::File, BddOpenai::ErrorResponse

Parameters:

  • purpose (String)

    The intended purpose of the file. One of: “fine-tune”, “assistants”.

  • file_path (String)

    The path of the file to upload.rb

Returns:



27
28
29
# File 'lib/bdd_openai/file_client.rb', line 27

def upload_file(purpose, file_path)
  BddOpenai::Services::Files::Upload.new(@api_key).upload_files(purpose, file_path)
end