Class: Asimov::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/asimov/client.rb

Overview

Asimov::Client is the main class which developers will use to interact with OpenAI.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, organization_id: HeadersFactory::NULL_ORGANIZATION_ID, request_options: {}, openai_api_base: nil) ⇒ Client

Creates a new Asimov::Client. Includes several optional named parameters:

api_key - The OpenAI API key that this Asimov::Client instance will use. If unspecified,

defaults to the application-wide configuration

organization_id - The OpenAI organization identifier that this Asimov::Client instance

will use. If unspecified, defaults to the application-wide configuration.

request_options - HTTParty request options that will be passed to the underlying network

client.  Merges (and overrides) global configuration value.

openai_api_base - Custom base URI for the API calls made by this client. Defaults to global

configuration value.


37
38
39
40
41
42
43
44
45
# File 'lib/asimov/client.rb', line 37

def initialize(api_key: nil, organization_id: HeadersFactory::NULL_ORGANIZATION_ID,
               request_options: {}, openai_api_base: nil)
  @headers_factory = HeadersFactory.new(api_key,
                                        organization_id)
  @request_options = Asimov.configuration.request_options
                           .merge(Utils::RequestOptionsValidator.validate(request_options))
                           .freeze
  initialize_openai_api_base(openai_api_base)
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



23
24
25
# File 'lib/asimov/client.rb', line 23

def api_key
  @api_key
end

#api_versionObject (readonly)

Returns the value of attribute api_version.



23
24
25
# File 'lib/asimov/client.rb', line 23

def api_version
  @api_version
end

#openai_api_baseObject (readonly)

Returns the value of attribute openai_api_base.



23
24
25
# File 'lib/asimov/client.rb', line 23

def openai_api_base
  @openai_api_base
end

#organization_idObject (readonly)

Returns the value of attribute organization_id.



23
24
25
# File 'lib/asimov/client.rb', line 23

def organization_id
  @organization_id
end

#request_optionsObject (readonly)

Returns the value of attribute request_options.



23
24
25
# File 'lib/asimov/client.rb', line 23

def request_options
  @request_options
end

Instance Method Details

#completionsObject

Use the completions method to access API calls in the /completions URI space.



51
52
53
# File 'lib/asimov/client.rb', line 51

def completions
  @completions ||= Asimov::ApiV1::Completions.new(client: self)
end

#editsObject

Use the edits method to access API calls in the /edits URI space.



58
59
60
# File 'lib/asimov/client.rb', line 58

def edits
  @edits ||= Asimov::ApiV1::Edits.new(client: self)
end

#embeddingsObject

Use the embeddings method to access API calls in the /embeddings URI space.



65
66
67
# File 'lib/asimov/client.rb', line 65

def embeddings
  @embeddings ||= Asimov::ApiV1::Embeddings.new(client: self)
end

#filesObject

Use the files method to access API calls in the /files URI space.



72
73
74
# File 'lib/asimov/client.rb', line 72

def files
  @files ||= Asimov::ApiV1::Files.new(client: self)
end

#finetunesObject

Use the finetunes method to access API calls in the /fine-tunes URI space.



79
80
81
# File 'lib/asimov/client.rb', line 79

def finetunes
  @finetunes ||= Asimov::ApiV1::Finetunes.new(client: self)
end

#imagesObject

Use the images method to access API calls in the /images URI space.



86
87
88
# File 'lib/asimov/client.rb', line 86

def images
  @images ||= Asimov::ApiV1::Images.new(client: self)
end

#modelsObject

Use the models method to access API calls in the /models URI space.



93
94
95
# File 'lib/asimov/client.rb', line 93

def models
  @models ||= Asimov::ApiV1::Models.new(client: self)
end

#moderationsObject

Use the moderations method to access API calls in the /moderations URI space.



100
101
102
# File 'lib/asimov/client.rb', line 100

def moderations
  @moderations ||= Asimov::ApiV1::Moderations.new(client: self)
end