Class: OpenApiOpenAIClient::CreateCompletionRequest

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApiModelBase

_deserialize, #_to_hash, #to_body, #to_s

Constructor Details

#initialize(attributes = {}) ⇒ CreateCompletionRequest

Initializes the object

Parameters:

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

    Model attributes in the form of hash



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
206
207
208
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
# File 'lib/openapi_openai/models/create_completion_request.rb', line 150

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

  # check to see if the attribute exists and convert string to symbol for hash key
  acceptable_attribute_map = self.class.acceptable_attribute_map
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!acceptable_attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `OpenApiOpenAIClient::CreateCompletionRequest`. Please check the name to make sure it's valid. List of attributes: " + acceptable_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?(:'prompt')
    self.prompt = attributes[:'prompt']
  else
    self.prompt = nil
  end

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

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

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

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

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

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

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

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

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

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

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

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

  if attributes.key?(:'suffix')
    self.suffix = attributes[:'suffix']
  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?(:'user')
    self.user = attributes[:'user']
  end
end

Instance Attribute Details

#best_ofObject

Generates best_of completions server-side and returns the "best" (the one with the highest log probability per token). Results cannot be streamed. When used with n, best_of controls the number of candidate completions and n specifies how many to return – best_of must be greater than n. Note: Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for max_tokens and stop.



23
24
25
# File 'lib/openapi_openai/models/create_completion_request.rb', line 23

def best_of
  @best_of
end

#echoObject

Echo back the prompt in addition to the completion



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

def echo
  @echo
end

#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/guides/text-generation)



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

def frequency_penalty
  @frequency_penalty
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 GPT tokenizer) to an associated bias value from -100 to 100. You can use this [tokenizer tool](/tokenizer?view=bpe) to convert text to token IDs. 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. As an example, you can pass ‘-100` to prevent the <|endoftext|> token from being generated.



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

def logit_bias
  @logit_bias
end

#logprobsObject

Include the log probabilities on the logprobs most likely output tokens, as well the chosen tokens. For example, if logprobs is 5, the API will return a list of the 5 most likely tokens. The API will always return the logprob of the sampled token, so there may be up to ‘logprobs+1` elements in the response. The maximum value for logprobs is 5.



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

def logprobs
  @logprobs
end

#max_tokensObject

The maximum number of [tokens](/tokenizer) that can be generated in the completion. The token count of your prompt plus max_tokens cannot exceed the model’s context length. [Example Python code](cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) for counting tokens.



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

def max_tokens
  @max_tokens
end

#modelObject

Returns the value of attribute model.



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

def model
  @model
end

#nObject

How many completions to generate for each prompt. Note: Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for max_tokens and stop.



41
42
43
# File 'lib/openapi_openai/models/create_completion_request.rb', line 41

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/guides/text-generation)



44
45
46
# File 'lib/openapi_openai/models/create_completion_request.rb', line 44

def presence_penalty
  @presence_penalty
end

#promptObject

Returns the value of attribute prompt.



20
21
22
# File 'lib/openapi_openai/models/create_completion_request.rb', line 20

def prompt
  @prompt
end

#seedObject

If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend.



47
48
49
# File 'lib/openapi_openai/models/create_completion_request.rb', line 47

def seed
  @seed
end

#stopObject

Returns the value of attribute stop.



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

def stop
  @stop
end

#streamObject

Whether to stream back partial progress. If set, 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](cookbook.openai.com/examples/how_to_stream_completions).



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

def stream
  @stream
end

#stream_optionsObject

Returns the value of attribute stream_options.



54
55
56
# File 'lib/openapi_openai/models/create_completion_request.rb', line 54

def stream_options
  @stream_options
end

#suffixObject

The suffix that comes after a completion of inserted text. This parameter is only supported for gpt-3.5-turbo-instruct.



57
58
59
# File 'lib/openapi_openai/models/create_completion_request.rb', line 57

def suffix
  @suffix
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.



60
61
62
# File 'lib/openapi_openai/models/create_completion_request.rb', line 60

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.



63
64
65
# File 'lib/openapi_openai/models/create_completion_request.rb', line 63

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).



66
67
68
# File 'lib/openapi_openai/models/create_completion_request.rb', line 66

def user
  @user
end

Class Method Details

.acceptable_attribute_mapObject

Returns attribute mapping this model knows about



93
94
95
# File 'lib/openapi_openai/models/create_completion_request.rb', line 93

def self.acceptable_attribute_map
  attribute_map
end

.acceptable_attributesObject

Returns all the JSON keys this model knows about



98
99
100
# File 'lib/openapi_openai/models/create_completion_request.rb', line 98

def self.acceptable_attributes
  acceptable_attribute_map.values
end

.attribute_mapObject

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



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/openapi_openai/models/create_completion_request.rb', line 69

def self.attribute_map
  {
    :'model' => :'model',
    :'prompt' => :'prompt',
    :'best_of' => :'best_of',
    :'echo' => :'echo',
    :'frequency_penalty' => :'frequency_penalty',
    :'logit_bias' => :'logit_bias',
    :'logprobs' => :'logprobs',
    :'max_tokens' => :'max_tokens',
    :'n' => :'n',
    :'presence_penalty' => :'presence_penalty',
    :'seed' => :'seed',
    :'stop' => :'stop',
    :'stream' => :'stream',
    :'stream_options' => :'stream_options',
    :'suffix' => :'suffix',
    :'temperature' => :'temperature',
    :'top_p' => :'top_p',
    :'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



538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
# File 'lib/openapi_openai/models/create_completion_request.rb', line 538

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



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/openapi_openai/models/create_completion_request.rb', line 127

def self.openapi_nullable
  Set.new([
    :'prompt',
    :'best_of',
    :'echo',
    :'frequency_penalty',
    :'logit_bias',
    :'logprobs',
    :'max_tokens',
    :'n',
    :'presence_penalty',
    :'seed',
    :'stop',
    :'stream',
    :'stream_options',
    :'suffix',
    :'temperature',
    :'top_p',
  ])
end

.openapi_typesObject

Attribute type mapping.



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/openapi_openai/models/create_completion_request.rb', line 103

def self.openapi_types
  {
    :'model' => :'CreateCompletionRequestModel',
    :'prompt' => :'CreateCompletionRequestPrompt',
    :'best_of' => :'Integer',
    :'echo' => :'Boolean',
    :'frequency_penalty' => :'Float',
    :'logit_bias' => :'Hash<String, Integer>',
    :'logprobs' => :'Integer',
    :'max_tokens' => :'Integer',
    :'n' => :'Integer',
    :'presence_penalty' => :'Float',
    :'seed' => :'Integer',
    :'stop' => :'CreateCompletionRequestStop',
    :'stream' => :'Boolean',
    :'stream_options' => :'ChatCompletionStreamOptions',
    :'suffix' => :'String',
    :'temperature' => :'Float',
    :'top_p' => :'Float',
    :'user' => :'String'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
# File 'lib/openapi_openai/models/create_completion_request.rb', line 500

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      model == o.model &&
      prompt == o.prompt &&
      best_of == o.best_of &&
      echo == o.echo &&
      frequency_penalty == o.frequency_penalty &&
      logit_bias == o.logit_bias &&
      logprobs == o.logprobs &&
      max_tokens == o.max_tokens &&
      n == o.n &&
      presence_penalty == o.presence_penalty &&
      seed == o.seed &&
      stop == o.stop &&
      stream == o.stream &&
      stream_options == o.stream_options &&
      suffix == o.suffix &&
      temperature == o.temperature &&
      top_p == o.top_p &&
      user == o.user
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


525
526
527
# File 'lib/openapi_openai/models/create_completion_request.rb', line 525

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



531
532
533
# File 'lib/openapi_openai/models/create_completion_request.rb', line 531

def hash
  [model, prompt, best_of, echo, frequency_penalty, logit_bias, logprobs, max_tokens, n, presence_penalty, seed, stop, stream, stream_options, suffix, temperature, top_p, 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



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/openapi_openai/models/create_completion_request.rb', line 263

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 !@best_of.nil? && @best_of > 20
    invalid_properties.push('invalid value for "best_of", must be smaller than or equal to 20.')
  end

  if !@best_of.nil? && @best_of < 0
    invalid_properties.push('invalid value for "best_of", must be greater than or equal to 0.')
  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

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

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

  if !@max_tokens.nil? && @max_tokens < 0
    invalid_properties.push('invalid value for "max_tokens", 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 !@seed.nil? && @seed > 9223372036854776000
    invalid_properties.push('invalid value for "seed", must be smaller than or equal to 9223372036854776000.')
  end

  if !@seed.nil? && @seed < -9223372036854776000
    invalid_properties.push('invalid value for "seed", must be greater than or equal to -9223372036854776000.')
  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

  invalid_properties
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



560
561
562
563
564
565
566
567
568
569
570
571
572
# File 'lib/openapi_openai/models/create_completion_request.rb', line 560

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

#valid?Boolean

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

Returns:

  • (Boolean)

    true if the model is valid



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/openapi_openai/models/create_completion_request.rb', line 343

def valid?
  warn '[DEPRECATED] the `valid?` method is obsolete'
  return false if @model.nil?
  return false if !@best_of.nil? && @best_of > 20
  return false if !@best_of.nil? && @best_of < 0
  return false if !@frequency_penalty.nil? && @frequency_penalty > 2
  return false if !@frequency_penalty.nil? && @frequency_penalty < -2
  return false if !@logprobs.nil? && @logprobs > 5
  return false if !@logprobs.nil? && @logprobs < 0
  return false if !@max_tokens.nil? && @max_tokens < 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 !@seed.nil? && @seed > 9223372036854776000
  return false if !@seed.nil? && @seed < -9223372036854776000
  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
  true
end