Class: Senior::Configuration::OpenAI

Inherits:
Object
  • Object
show all
Defined in:
lib/senior/configuration/open_ai.rb

Overview

Encapsulates the OpenAI configuration

Constant Summary collapse

DEFAULT_API_VERSION =

The default OpenAI API version

'v1'
DEFAULT_MAX_TOKENS =

The default maximum number of tokens to use in the OpenAI API request

1024
DEFAULT_MODEL =

The default OpenAI model to use

'text-davinci-003'
DEFAULT_N =

The default number of responses to generate

1
DEFAULT_REQUEST_TIMEOUT =

The default maximum amount of time to wait for an OpenAI API request to complete

120
DEFAULT_TEMPERATURE =

The default temperature to use in the OpenAI API request

0.7
DEFAULT_URI_BASE =

The default OpenAI URI base

'https://api.openai.com/'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOpenAI

Initializes a new instance of the OpenAI configuration for the Senior gem

Examples:

configuration = Senior::Configuration::OpenAI.new


116
117
118
119
120
121
122
123
124
125
126
# File 'lib/senior/configuration/open_ai.rb', line 116

def initialize
  @access_token = nil
  @api_version = DEFAULT_API_VERSION
  @max_tokens = DEFAULT_MAX_TOKENS
  @model = DEFAULT_MODEL
  @n = DEFAULT_N
  @organization_id = nil
  @request_timeout = DEFAULT_REQUEST_TIMEOUT
  @temperature = DEFAULT_TEMPERATURE
  @uri_base = DEFAULT_URI_BASE
end

Instance Attribute Details

#access_tokenString

Gets the OpenAI access token, raising an error if it is not set

Examples:

configuration = Senior::Configuration::OpenAI.new
configuration.access_token # => raises ConfigurationError if access token is not set

Returns:

  • (String)

    The OpenAI access token.

Raises:



138
139
140
141
142
143
# File 'lib/senior/configuration/open_ai.rb', line 138

def access_token
  return @access_token if @access_token

  error_text = 'OpenAI access token missing! See https://github.com/wilsonsilva/senior#usage'
  raise ConfigurationError, error_text
end

#api_versionString

The OpenAI API version

Examples:

configuration = Senior::Configuration::OpenAI.new
configuration.api_version = 'v1'

Returns:

  • (String)

    The OpenAI API version



25
26
27
# File 'lib/senior/configuration/open_ai.rb', line 25

def api_version
  @api_version
end

#max_tokensInteger

The maximum number of tokens to use in the OpenAI API request

Examples:

configuration = Senior::Configuration::OpenAI.new
configuration.max_tokens = 1024

Returns:

  • (Integer)

    The maximum number of tokens to use in the OpenAI API request



34
35
36
# File 'lib/senior/configuration/open_ai.rb', line 34

def max_tokens
  @max_tokens
end

#modelString

The OpenAI model to use

Examples:

configuration = Senior::Configuration::OpenAI.new
configuration.model = 'text-davinci-003'

Returns:

  • (String)

    The OpenAI model to use



43
44
45
# File 'lib/senior/configuration/open_ai.rb', line 43

def model
  @model
end

#nInteger

The number of responses to generate

Examples:

configuration = Senior::Configuration::OpenAI.new
configuration.n = 1

Returns:

  • (Integer)

    The number of responses to generate



52
53
54
# File 'lib/senior/configuration/open_ai.rb', line 52

def n
  @n
end

#organization_idString?

The OpenAI organization ID

Examples:

configuration = Senior::Configuration::OpenAI.new
configuration.organization_id = 'your_organization_id'

Returns:

  • (String, nil)

    The OpenAI organization ID, or nil if not set



61
62
63
# File 'lib/senior/configuration/open_ai.rb', line 61

def organization_id
  @organization_id
end

#request_timeoutInteger

The maximum amount of time to wait for an OpenAI API request to complete

Examples:

configuration = Senior::Configuration::OpenAI.new
configuration.request_timeout = 120

Returns:

  • (Integer)

    The maximum amount of time to wait for an OpenAI API request to complete



70
71
72
# File 'lib/senior/configuration/open_ai.rb', line 70

def request_timeout
  @request_timeout
end

#temperatureFloat

The temperature to use in the OpenAI API request

Examples:

configuration = Senior::Configuration::OpenAI.new
configuration.temperature = 0.7

Returns:

  • (Float)

    The temperature to use in the OpenAI API request



79
80
81
# File 'lib/senior/configuration/open_ai.rb', line 79

def temperature
  @temperature
end

#uri_baseString

The OpenAI URI base

Examples:

configuration = Senior::Configuration::OpenAI.new
configuration.uri_base = 'https://api.openai.com/'

Returns:

  • (String)

    The OpenAI URI base



88
89
90
# File 'lib/senior/configuration/open_ai.rb', line 88

def uri_base
  @uri_base
end