Class: OpenApiOpenAIClient::CreateChatCompletionRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_openai/models/create_chat_completion_request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ CreateChatCompletionRequest

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 117

def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `OpenApiOpenAIClient::CreateChatCompletionRequest` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!self.class.attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `OpenApiOpenAIClient::CreateChatCompletionRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
    end
    h[k.to_sym] = v
  }

  if attributes.key?(:'model')
    self.model = attributes[:'model']
  else
    self.model = nil
  end

  if attributes.key?(:'messages')
    if (value = attributes[:'messages']).is_a?(Array)
      self.messages = value
    end
  else
    self.messages = nil
  end

  if attributes.key?(:'functions')
    if (value = attributes[:'functions']).is_a?(Array)
      self.functions = value
    end
  end

  if attributes.key?(:'function_call')
    self.function_call = attributes[:'function_call']
  end

  if attributes.key?(:'temperature')
    self.temperature = attributes[:'temperature']
  else
    self.temperature = 1
  end

  if attributes.key?(:'top_p')
    self.top_p = attributes[:'top_p']
  else
    self.top_p = 1
  end

  if attributes.key?(:'n')
    self.n = attributes[:'n']
  else
    self.n = 1
  end

  if attributes.key?(:'stream')
    self.stream = attributes[:'stream']
  else
    self.stream = false
  end

  if attributes.key?(:'stop')
    self.stop = attributes[:'stop']
  end

  if attributes.key?(:'max_tokens')
    self.max_tokens = attributes[:'max_tokens']
  end

  if attributes.key?(:'presence_penalty')
    self.presence_penalty = attributes[:'presence_penalty']
  else
    self.presence_penalty = 0
  end

  if attributes.key?(:'frequency_penalty')
    self.frequency_penalty = attributes[:'frequency_penalty']
  else
    self.frequency_penalty = 0
  end

  if attributes.key?(:'logit_bias')
    self.logit_bias = attributes[:'logit_bias']
  end

  if attributes.key?(:'user')
    self.user = attributes[:'user']
  end
end

Instance Attribute Details

#frequency_penaltyObject

Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model’s likelihood to repeat the same line verbatim. [See more information about frequency and presence penalties.](/docs/api-reference/parameter-details)



49
50
51
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 49

def frequency_penalty
  @frequency_penalty
end

#function_callObject

Returns the value of attribute function_call.



26
27
28
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 26

def function_call
  @function_call
end

#functionsObject

A list of functions the model may generate JSON inputs for.



24
25
26
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 24

def functions
  @functions
end

#logit_biasObject

Modify the likelihood of specified tokens appearing in the completion. Accepts a json object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.



52
53
54
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 52

def logit_bias
  @logit_bias
end

#max_tokensObject

The maximum number of [tokens](/tokenizer) to generate in the chat completion. The total length of input tokens and generated tokens is limited by the model’s context length. [Example Python code](github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb) for counting tokens.



43
44
45
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 43

def max_tokens
  @max_tokens
end

#messagesObject

A list of messages comprising the conversation so far. [Example Python code](github.com/openai/openai-cookbook/blob/main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb).



21
22
23
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 21

def messages
  @messages
end

#modelObject

Returns the value of attribute model.



18
19
20
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 18

def model
  @model
end

#nObject

How many chat completion choices to generate for each input message.



35
36
37
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 35

def n
  @n
end

#presence_penaltyObject

Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model’s likelihood to talk about new topics. [See more information about frequency and presence penalties.](/docs/api-reference/parameter-details)



46
47
48
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 46

def presence_penalty
  @presence_penalty
end

#stopObject

Returns the value of attribute stop.



40
41
42
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 40

def stop
  @stop
end

#streamObject

If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only [server-sent events](developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format) as they become available, with the stream terminated by a ‘data: [DONE]` message. [Example Python code](github.com/openai/openai-cookbook/blob/main/examples/How_to_stream_completions.ipynb).



38
39
40
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 38

def stream
  @stream
end

#temperatureObject

What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or ‘top_p` but not both.



29
30
31
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 29

def temperature
  @temperature
end

#top_pObject

An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or ‘temperature` but not both.



32
33
34
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 32

def top_p
  @top_p
end

#userObject

A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids).



55
56
57
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 55

def user
  @user
end

Class Method Details

._deserialize(type, value) ⇒ Object

Deserializes the data based on type

Parameters:

  • string

    type Data type

  • string

    value Value to be deserialized

Returns:

  • (Object)

    Deserialized data



450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 450

def self._deserialize(type, value)
  case type.to_sym
  when :Time
    Time.parse(value)
  when :Date
    Date.parse(value)
  when :String
    value.to_s
  when :Integer
    value.to_i
  when :Float
    value.to_f
  when :Boolean
    if value.to_s =~ /\A(true|t|yes|y|1)\z/i
      true
    else
      false
    end
  when :Object
    # generic object (usually a Hash), return directly
    value
  when /\AArray<(?<inner_type>.+)>\z/
    inner_type = Regexp.last_match[:inner_type]
    value.map { |v| _deserialize(inner_type, v) }
  when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
    k_type = Regexp.last_match[:k_type]
    v_type = Regexp.last_match[:v_type]
    {}.tap do |hash|
      value.each do |k, v|
        hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
      end
    end
  else # model
    # models (e.g. Pet) or oneOf
    klass = OpenApiOpenAIClient.const_get(type)
    klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
  end
end

.acceptable_attributesObject

Returns all the JSON keys this model knows about



78
79
80
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 78

def self.acceptable_attributes
  attribute_map.values
end

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 58

def self.attribute_map
  {
    :'model' => :'model',
    :'messages' => :'messages',
    :'functions' => :'functions',
    :'function_call' => :'function_call',
    :'temperature' => :'temperature',
    :'top_p' => :'top_p',
    :'n' => :'n',
    :'stream' => :'stream',
    :'stop' => :'stop',
    :'max_tokens' => :'max_tokens',
    :'presence_penalty' => :'presence_penalty',
    :'frequency_penalty' => :'frequency_penalty',
    :'logit_bias' => :'logit_bias',
    :'user' => :'user'
  }
end

.build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 426

def self.build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  attributes = attributes.transform_keys(&:to_sym)
  transformed_hash = {}
  openapi_types.each_pair do |key, type|
    if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = nil
    elsif type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[attribute_map[key]].is_a?(Array)
        transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
      end
    elsif !attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
    end
  end
  new(transformed_hash)
end

.openapi_nullableObject

List of attributes with nullable: true



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 103

def self.openapi_nullable
  Set.new([
    :'temperature',
    :'top_p',
    :'n',
    :'stream',
    :'presence_penalty',
    :'frequency_penalty',
    :'logit_bias',
  ])
end

.openapi_typesObject

Attribute type mapping.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 83

def self.openapi_types
  {
    :'model' => :'CreateChatCompletionRequestModel',
    :'messages' => :'Array<ChatCompletionRequestMessage>',
    :'functions' => :'Array<ChatCompletionFunctions>',
    :'function_call' => :'CreateChatCompletionRequestFunctionCall',
    :'temperature' => :'Float',
    :'top_p' => :'Float',
    :'n' => :'Integer',
    :'stream' => :'Boolean',
    :'stop' => :'CreateChatCompletionRequestStop',
    :'max_tokens' => :'Integer',
    :'presence_penalty' => :'Float',
    :'frequency_penalty' => :'Float',
    :'logit_bias' => :'Object',
    :'user' => :'String'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 392

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      model == o.model &&
      messages == o.messages &&
      functions == o.functions &&
      function_call == o.function_call &&
      temperature == o.temperature &&
      top_p == o.top_p &&
      n == o.n &&
      stream == o.stream &&
      stop == o.stop &&
      max_tokens == o.max_tokens &&
      presence_penalty == o.presence_penalty &&
      frequency_penalty == o.frequency_penalty &&
      logit_bias == o.logit_bias &&
      user == o.user
end

#_to_hash(value) ⇒ Hash

Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value

Parameters:

  • value (Object)

    Any valid value

Returns:

  • (Hash)

    Returns the value in the form of hash



521
522
523
524
525
526
527
528
529
530
531
532
533
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 521

def _to_hash(value)
  if value.is_a?(Array)
    value.compact.map { |v| _to_hash(v) }
  elsif value.is_a?(Hash)
    {}.tap do |hash|
      value.each { |k, v| hash[k] = _to_hash(v) }
    end
  elsif value.respond_to? :to_hash
    value.to_hash
  else
    value
  end
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


413
414
415
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 413

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



419
420
421
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 419

def hash
  [model, messages, functions, function_call, temperature, top_p, n, stream, stop, max_tokens, presence_penalty, frequency_penalty, logit_bias, user].hash
end

#list_invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 209

def list_invalid_properties
  warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
  invalid_properties = Array.new
  if @model.nil?
    invalid_properties.push('invalid value for "model", model cannot be nil.')
  end

  if @messages.nil?
    invalid_properties.push('invalid value for "messages", messages cannot be nil.')
  end

  if @messages.length < 1
    invalid_properties.push('invalid value for "messages", number of items must be greater than or equal to 1.')
  end

  if !@functions.nil? && @functions.length < 1
    invalid_properties.push('invalid value for "functions", number of items must be greater than or equal to 1.')
  end

  if !@temperature.nil? && @temperature > 2
    invalid_properties.push('invalid value for "temperature", must be smaller than or equal to 2.')
  end

  if !@temperature.nil? && @temperature < 0
    invalid_properties.push('invalid value for "temperature", must be greater than or equal to 0.')
  end

  if !@top_p.nil? && @top_p > 1
    invalid_properties.push('invalid value for "top_p", must be smaller than or equal to 1.')
  end

  if !@top_p.nil? && @top_p < 0
    invalid_properties.push('invalid value for "top_p", must be greater than or equal to 0.')
  end

  if !@n.nil? && @n > 128
    invalid_properties.push('invalid value for "n", must be smaller than or equal to 128.')
  end

  if !@n.nil? && @n < 1
    invalid_properties.push('invalid value for "n", must be greater than or equal to 1.')
  end

  if !@presence_penalty.nil? && @presence_penalty > 2
    invalid_properties.push('invalid value for "presence_penalty", must be smaller than or equal to 2.')
  end

  if !@presence_penalty.nil? && @presence_penalty < -2
    invalid_properties.push('invalid value for "presence_penalty", must be greater than or equal to -2.')
  end

  if !@frequency_penalty.nil? && @frequency_penalty > 2
    invalid_properties.push('invalid value for "frequency_penalty", must be smaller than or equal to 2.')
  end

  if !@frequency_penalty.nil? && @frequency_penalty < -2
    invalid_properties.push('invalid value for "frequency_penalty", must be greater than or equal to -2.')
  end

  invalid_properties
end

#to_bodyHash

to_body is an alias to to_hash (backward compatibility)

Returns:

  • (Hash)

    Returns the object in the form of hash



497
498
499
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 497

def to_body
  to_hash
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



503
504
505
506
507
508
509
510
511
512
513
514
515
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 503

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    if value.nil?
      is_nullable = self.class.openapi_nullable.include?(attr)
      next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
    end

    hash[param] = _to_hash(value)
  end
  hash
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



491
492
493
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 491

def to_s
  to_hash.to_s
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/openapi_openai/models/create_chat_completion_request.rb', line 273

def valid?
  warn '[DEPRECATED] the `valid?` method is obsolete'
  return false if @model.nil?
  return false if @messages.nil?
  return false if @messages.length < 1
  return false if !@functions.nil? && @functions.length < 1
  return false if !@temperature.nil? && @temperature > 2
  return false if !@temperature.nil? && @temperature < 0
  return false if !@top_p.nil? && @top_p > 1
  return false if !@top_p.nil? && @top_p < 0
  return false if !@n.nil? && @n > 128
  return false if !@n.nil? && @n < 1
  return false if !@presence_penalty.nil? && @presence_penalty > 2
  return false if !@presence_penalty.nil? && @presence_penalty < -2
  return false if !@frequency_penalty.nil? && @frequency_penalty > 2
  return false if !@frequency_penalty.nil? && @frequency_penalty < -2
  true
end