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.


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

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.



25
26
27
# File 'lib/asimov/client.rb', line 25

def api_key
  @api_key
end

#api_versionObject (readonly)

Returns the value of attribute api_version.



25
26
27
# File 'lib/asimov/client.rb', line 25

def api_version
  @api_version
end

#openai_api_baseObject (readonly)

Returns the value of attribute openai_api_base.



25
26
27
# File 'lib/asimov/client.rb', line 25

def openai_api_base
  @openai_api_base
end

#organization_idObject (readonly)

Returns the value of attribute organization_id.



25
26
27
# File 'lib/asimov/client.rb', line 25

def organization_id
  @organization_id
end

#request_optionsObject (readonly)

Returns the value of attribute request_options.



25
26
27
# File 'lib/asimov/client.rb', line 25

def request_options
  @request_options
end

Instance Method Details

#audioObject

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



53
54
55
# File 'lib/asimov/client.rb', line 53

def audio
  @audio ||= Asimov::ApiV1::Audio.new(client: self)
end

#chatObject

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



60
61
62
# File 'lib/asimov/client.rb', line 60

def chat
  @chat ||= Asimov::ApiV1::Chat.new(client: self)
end

#completionsObject

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



67
68
69
# File 'lib/asimov/client.rb', line 67

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

#editsObject

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



74
75
76
# File 'lib/asimov/client.rb', line 74

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

#embeddingsObject

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



81
82
83
# File 'lib/asimov/client.rb', line 81

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

#filesObject

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



88
89
90
# File 'lib/asimov/client.rb', line 88

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.



95
96
97
# File 'lib/asimov/client.rb', line 95

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

#imagesObject

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



102
103
104
# File 'lib/asimov/client.rb', line 102

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

#modelsObject

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



109
110
111
# File 'lib/asimov/client.rb', line 109

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

#moderationsObject

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



116
117
118
# File 'lib/asimov/client.rb', line 116

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