Class: AzureOpenaiClient::CompletionsCreateRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/azure_openai_client/models/completions_create_request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ CompletionsCreateRequest

Initializes the object

Parameters:

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

    Model attributes in the form of hash



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
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
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 141

def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `AzureOpenaiClient::CompletionsCreateRequest` 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 `AzureOpenaiClient::CompletionsCreateRequest`. 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?(:'prompt')
    self.prompt = attributes[:'prompt']
  end

  if attributes.key?(:'max_tokens')
    self.max_tokens = attributes[:'max_tokens']
  else
    self.max_tokens = 16
  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?(:'logit_bias')
    self.logit_bias = attributes[:'logit_bias']
  end

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

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

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

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

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

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

  if attributes.key?(:'cache_level')
    self.cache_level = attributes[:'cache_level']
  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?(:'best_of')
    self.best_of = attributes[:'best_of']
  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. Has maximum value of 128.



67
68
69
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 67

def best_of
  @best_of
end

#cache_levelObject

can be used to disable any server-side caching, 0=no cache, 1=prompt prefix enabled, 2=full cache



58
59
60
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 58

def cache_level
  @cache_level
end

#completion_configObject

Returns the value of attribute completion_config.



55
56
57
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 55

def completion_config
  @completion_config
end

#echoObject

Echo back the prompt in addition to the completion



51
52
53
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 51

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.



64
65
66
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 64

def frequency_penalty
  @frequency_penalty
end

#logit_biasObject

Defaults to null. 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 (which works for both GPT-2 and GPT-3) 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 &#58; -100 to prevent the <|endoftext|> token from being generated.



30
31
32
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 30

def logit_bias
  @logit_bias
end

#logprobsObject

Include the log probabilities on the logprobs most likely 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. Minimum of 0 and maximum of 5 allowed.



42
43
44
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 42

def logprobs
  @logprobs
end

#max_tokensObject

The token count of your prompt plus max_tokens cannot exceed the model’s context length. Most models have a context length of 2048 tokens (except for the newest models, which support 4096). Has minimum of 0.



21
22
23
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 21

def max_tokens
  @max_tokens
end

#modelObject

ID of the model to use. You can use the Models_List operation to see all of your available models, or see our Models_Get overview for descriptions of them.



45
46
47
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 45

def model
  @model
end

#nObject

How many completions to generate for each prompt. Minimum of 1 and maximum of 128 allowed. 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.



36
37
38
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 36

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.



61
62
63
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 61

def presence_penalty
  @presence_penalty
end

#promptObject

Returns the value of attribute prompt.



18
19
20
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 18

def prompt
  @prompt
end

#stopObject

Returns the value of attribute stop.



53
54
55
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 53

def stop
  @stop
end

#streamObject

Whether to stream back partial progress. If set, tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message.



39
40
41
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 39

def stream
  @stream
end

#suffixObject

The suffix that comes after a completion of inserted text.



48
49
50
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 48

def suffix
  @suffix
end

#temperatureObject

What sampling temperature to use. Higher values means the model will take more risks. Try 0.9 for more creative applications, and 0 (argmax sampling) for ones with a well-defined answer. We generally recommend altering this or top_p but not both.



24
25
26
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 24

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.



27
28
29
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 27

def top_p
  @top_p
end

#userObject

A unique identifier representing your end-user, which can help monitoring and detecting abuse



33
34
35
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 33

def user
  @user
end

Class Method Details

.acceptable_attributesObject

Returns all the JSON keys this model knows about



94
95
96
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 94

def self.acceptable_attributes
  attribute_map.values
end

.attribute_mapObject

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



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

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



296
297
298
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 296

def self.build_from_hash(attributes)
  new.build_from_hash(attributes)
end

.openapi_nullableObject

List of attributes with nullable: true



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 123

def self.openapi_nullable
  Set.new([
    :'max_tokens',
    :'temperature',
    :'top_p',
    :'n',
    :'stream',
    :'logprobs',
    :'model',
    :'suffix',
    :'echo',
    :'completion_config',
    :'cache_level',
  ])
end

.openapi_typesObject

Attribute type mapping.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 99

def self.openapi_types
  {
    :'prompt' => :'CompletionsCreateRequestPrompt',
    :'max_tokens' => :'Integer',
    :'temperature' => :'Float',
    :'top_p' => :'Float',
    :'logit_bias' => :'Object',
    :'user' => :'String',
    :'n' => :'Integer',
    :'stream' => :'Boolean',
    :'logprobs' => :'Integer',
    :'model' => :'String',
    :'suffix' => :'String',
    :'echo' => :'Boolean',
    :'stop' => :'CompletionsCreateRequestStop',
    :'completion_config' => :'String',
    :'cache_level' => :'Integer',
    :'presence_penalty' => :'Float',
    :'frequency_penalty' => :'Float',
    :'best_of' => :'Integer'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 258

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

#_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



327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 327

def _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 = AzureOpenaiClient.const_get(type)
    klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
  end
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



398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 398

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

#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



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 303

def build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  attributes = attributes.transform_keys(&:to_sym)
  self.class.openapi_types.each_pair do |key, type|
    if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
      self.send("#{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[self.class.attribute_map[key]].is_a?(Array)
        self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
      end
    elsif !attributes[self.class.attribute_map[key]].nil?
      self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
    end
  end

  self
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


283
284
285
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 283

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



289
290
291
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 289

def hash
  [prompt, max_tokens, temperature, top_p, logit_bias, user, n, stream, logprobs, model, suffix, echo, stop, completion_config, cache_level, presence_penalty, frequency_penalty, best_of].hash
end

#list_invalid_propertiesObject

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

Returns:

  • Array for valid properties with the reasons



245
246
247
248
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 245

def list_invalid_properties
  invalid_properties = Array.new
  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



374
375
376
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 374

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



380
381
382
383
384
385
386
387
388
389
390
391
392
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 380

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



368
369
370
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 368

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



252
253
254
# File 'lib/azure_openai_client/models/completions_create_request.rb', line 252

def valid?
  true
end