Class: VeniceClient::ChatCompletionRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/venice_client/models/chat_completion_request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ ChatCompletionRequest

Initializes the object



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
260
261
262
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
# File 'lib/venice_client/models/chat_completion_request.rb', line 164

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  if attributes.key?(:'parallel_tool_calls')
    self.parallel_tool_calls = attributes[:'parallel_tool_calls']
  else
    self.parallel_tool_calls = true
  end

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

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

  if attributes.key?(:'tools')
    if (value = attributes[:'tools']).is_a?(Array)
      self.tools = value
    end
  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.



17
18
19
# File 'lib/venice_client/models/chat_completion_request.rb', line 17

def frequency_penalty
  @frequency_penalty
end

#logprobsObject

Whether to include log probabilities in the response. This is not supported by all models.



20
21
22
# File 'lib/venice_client/models/chat_completion_request.rb', line 20

def logprobs
  @logprobs
end

#max_completion_tokensObject

An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens.



23
24
25
# File 'lib/venice_client/models/chat_completion_request.rb', line 23

def max_completion_tokens
  @max_completion_tokens
end

#max_tempObject

Maximum temperature value for dynamic temperature scaling.



26
27
28
# File 'lib/venice_client/models/chat_completion_request.rb', line 26

def max_temp
  @max_temp
end

#max_tokensObject

The maximum number of tokens that can be generated in the chat completion. This value can be used to control costs for text generated via API. This value is now deprecated in favor of max_completion_tokens.



29
30
31
# File 'lib/venice_client/models/chat_completion_request.rb', line 29

def max_tokens
  @max_tokens
end

#messagesObject

A list of messages comprising the conversation so far. Depending on the model you use, different message types (modalities) are supported, like text and images. For compatibility purposes, the schema supports submitting multiple image_url messages, however, only the last image_url message will be passed to and processed by the model.



32
33
34
# File 'lib/venice_client/models/chat_completion_request.rb', line 32

def messages
  @messages
end

#min_pObject

Sets a minimum probability threshold for token selection. Tokens with probabilities below this value are filtered out.



35
36
37
# File 'lib/venice_client/models/chat_completion_request.rb', line 35

def min_p
  @min_p
end

#min_tempObject

Minimum temperature value for dynamic temperature scaling.



38
39
40
# File 'lib/venice_client/models/chat_completion_request.rb', line 38

def min_temp
  @min_temp
end

#modelObject

The ID of the model you wish to prompt. May also be a model trait, or a compatibility mapping. See the models endpoint for a list of models available to you. You can use feature suffixes to enable features from the venice_parameters object. Please see "Model Feature Suffix" documentation for more details.



41
42
43
# File 'lib/venice_client/models/chat_completion_request.rb', line 41

def model
  @model
end

#nObject

How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep n as 1 to minimize costs.



44
45
46
# File 'lib/venice_client/models/chat_completion_request.rb', line 44

def n
  @n
end

#parallel_tool_callsObject

Whether to enable parallel function calling during tool use.



81
82
83
# File 'lib/venice_client/models/chat_completion_request.rb', line 81

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



47
48
49
# File 'lib/venice_client/models/chat_completion_request.rb', line 47

def presence_penalty
  @presence_penalty
end

#repetition_penaltyObject

The parameter for repetition penalty. 1.0 means no penalty. Values > 1.0 discourage repetition.



50
51
52
# File 'lib/venice_client/models/chat_completion_request.rb', line 50

def repetition_penalty
  @repetition_penalty
end

#response_formatObject

Format in which the response should be returned.



84
85
86
# File 'lib/venice_client/models/chat_completion_request.rb', line 84

def response_format
  @response_format
end

#seedObject

The random seed used to generate the response. This is useful for reproducibility.



53
54
55
# File 'lib/venice_client/models/chat_completion_request.rb', line 53

def seed
  @seed
end

#stopObject

Up to 4 sequences where the API will stop generating further tokens. Defaults to null.



56
57
58
# File 'lib/venice_client/models/chat_completion_request.rb', line 56

def stop
  @stop
end

#stop_token_idsObject

Array of token IDs where the API will stop generating further tokens.



59
60
61
# File 'lib/venice_client/models/chat_completion_request.rb', line 59

def stop_token_ids
  @stop_token_ids
end

#streamObject

Whether to stream back partial progress. Defaults to false.



62
63
64
# File 'lib/venice_client/models/chat_completion_request.rb', line 62

def stream
  @stream
end

#stream_optionsObject

Returns the value of attribute stream_options.



64
65
66
# File 'lib/venice_client/models/chat_completion_request.rb', line 64

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



67
68
69
# File 'lib/venice_client/models/chat_completion_request.rb', line 67

def temperature
  @temperature
end

#tool_choiceObject

Returns the value of attribute tool_choice.



86
87
88
# File 'lib/venice_client/models/chat_completion_request.rb', line 86

def tool_choice
  @tool_choice
end

#toolsObject

A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for.



89
90
91
# File 'lib/venice_client/models/chat_completion_request.rb', line 89

def tools
  @tools
end

#top_kObject

The number of highest probability vocabulary tokens to keep for top-k-filtering.



70
71
72
# File 'lib/venice_client/models/chat_completion_request.rb', line 70

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



73
74
75
# File 'lib/venice_client/models/chat_completion_request.rb', line 73

def top_p
  @top_p
end

#userObject

This field is discarded on the request but is supported in the Venice API for compatibility with OpenAPI clients.



76
77
78
# File 'lib/venice_client/models/chat_completion_request.rb', line 76

def user
  @user
end

#venice_parametersObject

Returns the value of attribute venice_parameters.



78
79
80
# File 'lib/venice_client/models/chat_completion_request.rb', line 78

def venice_parameters
  @venice_parameters
end

Class Method Details

.attribute_mapObject

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



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/venice_client/models/chat_completion_request.rb', line 92

def self.attribute_map
  {
    :'frequency_penalty' => :'frequency_penalty',
    :'logprobs' => :'logprobs',
    :'max_completion_tokens' => :'max_completion_tokens',
    :'max_temp' => :'max_temp',
    :'max_tokens' => :'max_tokens',
    :'messages' => :'messages',
    :'min_p' => :'min_p',
    :'min_temp' => :'min_temp',
    :'model' => :'model',
    :'n' => :'n',
    :'presence_penalty' => :'presence_penalty',
    :'repetition_penalty' => :'repetition_penalty',
    :'seed' => :'seed',
    :'stop' => :'stop',
    :'stop_token_ids' => :'stop_token_ids',
    :'stream' => :'stream',
    :'stream_options' => :'stream_options',
    :'temperature' => :'temperature',
    :'top_k' => :'top_k',
    :'top_p' => :'top_p',
    :'user' => :'user',
    :'venice_parameters' => :'venice_parameters',
    :'parallel_tool_calls' => :'parallel_tool_calls',
    :'response_format' => :'response_format',
    :'tool_choice' => :'tool_choice',
    :'tools' => :'tools'
  }
end

.build_from_hash(attributes) ⇒ Object

Builds the object from hash



371
372
373
# File 'lib/venice_client/models/chat_completion_request.rb', line 371

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

.openapi_nullableObject

List of attributes with nullable: true



156
157
158
159
160
# File 'lib/venice_client/models/chat_completion_request.rb', line 156

def self.openapi_nullable
  Set.new([
    :'tools'
  ])
end

.openapi_typesObject

Attribute type mapping.



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
# File 'lib/venice_client/models/chat_completion_request.rb', line 124

def self.openapi_types
  {
    :'frequency_penalty' => :'Object',
    :'logprobs' => :'Object',
    :'max_completion_tokens' => :'Object',
    :'max_temp' => :'Object',
    :'max_tokens' => :'Object',
    :'messages' => :'Object',
    :'min_p' => :'Object',
    :'min_temp' => :'Object',
    :'model' => :'Object',
    :'n' => :'Object',
    :'presence_penalty' => :'Object',
    :'repetition_penalty' => :'Object',
    :'seed' => :'Object',
    :'stop' => :'Object',
    :'stop_token_ids' => :'Object',
    :'stream' => :'Object',
    :'stream_options' => :'Object',
    :'temperature' => :'Object',
    :'top_k' => :'Object',
    :'top_p' => :'Object',
    :'user' => :'Object',
    :'venice_parameters' => :'Object',
    :'parallel_tool_calls' => :'Object',
    :'response_format' => :'Object',
    :'tool_choice' => :'Object',
    :'tools' => :'Object'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.



325
326
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
# File 'lib/venice_client/models/chat_completion_request.rb', line 325

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      frequency_penalty == o.frequency_penalty &&
      logprobs == o.logprobs &&
      max_completion_tokens == o.max_completion_tokens &&
      max_temp == o.max_temp &&
      max_tokens == o.max_tokens &&
      messages == o.messages &&
      min_p == o.min_p &&
      min_temp == o.min_temp &&
      model == o.model &&
      n == o.n &&
      presence_penalty == o.presence_penalty &&
      repetition_penalty == o.repetition_penalty &&
      seed == o.seed &&
      stop == o.stop &&
      stop_token_ids == o.stop_token_ids &&
      stream == o.stream &&
      stream_options == o.stream_options &&
      temperature == o.temperature &&
      top_k == o.top_k &&
      top_p == o.top_p &&
      user == o.user &&
      venice_parameters == o.venice_parameters &&
      parallel_tool_calls == o.parallel_tool_calls &&
      response_format == o.response_format &&
      tool_choice == o.tool_choice &&
      tools == o.tools
end

#_deserialize(type, value) ⇒ Object

Deserializes the data based on type



401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
# File 'lib/venice_client/models/chat_completion_request.rb', line 401

def _deserialize(type, value)
  case type.to_sym
  when :DateTime
    DateTime.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
    VeniceClient.const_get(type).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



470
471
472
473
474
475
476
477
478
479
480
481
482
# File 'lib/venice_client/models/chat_completion_request.rb', line 470

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



378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/venice_client/models/chat_completion_request.rb', line 378

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

  self
end

#eql?(o) ⇒ Boolean

See Also:

  • `==` method


358
359
360
# File 'lib/venice_client/models/chat_completion_request.rb', line 358

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.



364
365
366
# File 'lib/venice_client/models/chat_completion_request.rb', line 364

def hash
  [frequency_penalty, logprobs, max_completion_tokens, max_temp, max_tokens, messages, min_p, min_temp, model, n, presence_penalty, repetition_penalty, seed, stop, stop_token_ids, stream, stream_options, temperature, top_k, top_p, user, venice_parameters, parallel_tool_calls, response_format, tool_choice, tools].hash
end

#list_invalid_propertiesObject

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



302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/venice_client/models/chat_completion_request.rb', line 302

def list_invalid_properties
  invalid_properties = Array.new
  if @messages.nil?
    invalid_properties.push('invalid value for "messages", messages cannot be nil.')
  end

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

  invalid_properties
end

#to_bodyHash

to_body is an alias to to_hash (backward compatibility)



446
447
448
# File 'lib/venice_client/models/chat_completion_request.rb', line 446

def to_body
  to_hash
end

#to_hashHash

Returns the object in the form of hash



452
453
454
455
456
457
458
459
460
461
462
463
464
# File 'lib/venice_client/models/chat_completion_request.rb', line 452

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



440
441
442
# File 'lib/venice_client/models/chat_completion_request.rb', line 440

def to_s
  to_hash.to_s
end

#valid?Boolean

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



317
318
319
320
321
# File 'lib/venice_client/models/chat_completion_request.rb', line 317

def valid?
  return false if @messages.nil?
  return false if @model.nil?
  true
end