azure_openai_client 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +178 -0
  3. data/lib/azure_openai_client/api/default_api.rb +232 -0
  4. data/lib/azure_openai_client/api_client.rb +390 -0
  5. data/lib/azure_openai_client/api_error.rb +58 -0
  6. data/lib/azure_openai_client/configuration.rb +214 -0
  7. data/lib/azure_openai_client/models/chat_completions_body.rb +334 -0
  8. data/lib/azure_openai_client/models/deploymentid_completions_body.rb +406 -0
  9. data/lib/azure_openai_client/models/deploymentid_embeddings_body.rb +202 -0
  10. data/lib/azure_openai_client/models/deploymentsdeploymentidchatcompletions_messages.rb +274 -0
  11. data/lib/azure_openai_client/models/error_response.rb +209 -0
  12. data/lib/azure_openai_client/models/error_response_error.rb +236 -0
  13. data/lib/azure_openai_client/models/inline_response_200.rb +281 -0
  14. data/lib/azure_openai_client/models/inline_response_200_1.rb +258 -0
  15. data/lib/azure_openai_client/models/inline_response_200_1_data.rb +244 -0
  16. data/lib/azure_openai_client/models/inline_response_200_1_usage.rb +228 -0
  17. data/lib/azure_openai_client/models/inline_response_200_2.rb +281 -0
  18. data/lib/azure_openai_client/models/inline_response_200_2_choices.rb +227 -0
  19. data/lib/azure_openai_client/models/inline_response_200_2_message.rb +264 -0
  20. data/lib/azure_openai_client/models/inline_response_200_2_usage.rb +242 -0
  21. data/lib/azure_openai_client/models/inline_response_200_choices.rb +236 -0
  22. data/lib/azure_openai_client/models/inline_response_200_logprobs.rb +244 -0
  23. data/lib/azure_openai_client/models/inline_response_200_usage.rb +242 -0
  24. data/lib/azure_openai_client/models/one_ofchat_completions_body_stop.rb +198 -0
  25. data/lib/azure_openai_client/models/one_ofdeploymentid_completions_body_prompt.rb +198 -0
  26. data/lib/azure_openai_client/models/one_ofdeploymentid_completions_body_stop.rb +198 -0
  27. data/lib/azure_openai_client/version.rb +16 -0
  28. data/lib/azure_openai_client.rb +61 -0
  29. data/spec/api/default_api_spec.rb +75 -0
  30. data/spec/api_client_spec.rb +229 -0
  31. data/spec/configuration_spec.rb +78 -0
  32. data/spec/models/chat_completions_body_spec.rb +102 -0
  33. data/spec/models/deploymentid_completions_body_spec.rb +144 -0
  34. data/spec/models/deploymentid_embeddings_body_spec.rb +36 -0
  35. data/spec/models/deploymentsdeploymentidchatcompletions_messages_spec.rb +58 -0
  36. data/spec/models/error_response_error_spec.rb +60 -0
  37. data/spec/models/error_response_spec.rb +42 -0
  38. data/spec/models/inline_response_200_1_data_spec.rb +54 -0
  39. data/spec/models/inline_response_200_1_spec.rb +60 -0
  40. data/spec/models/inline_response_200_1_usage_spec.rb +48 -0
  41. data/spec/models/inline_response_200_2_choices_spec.rb +54 -0
  42. data/spec/models/inline_response_200_2_message_spec.rb +52 -0
  43. data/spec/models/inline_response_200_2_spec.rb +72 -0
  44. data/spec/models/inline_response_200_2_usage_spec.rb +54 -0
  45. data/spec/models/inline_response_200_choices_spec.rb +60 -0
  46. data/spec/models/inline_response_200_logprobs_spec.rb +60 -0
  47. data/spec/models/inline_response_200_spec.rb +72 -0
  48. data/spec/models/inline_response_200_usage_spec.rb +54 -0
  49. data/spec/models/one_ofchat_completions_body_stop_spec.rb +36 -0
  50. data/spec/models/one_ofdeploymentid_completions_body_prompt_spec.rb +36 -0
  51. data/spec/models/one_ofdeploymentid_completions_body_stop_spec.rb +36 -0
  52. data/spec/spec_helper.rb +112 -0
  53. metadata +177 -0
@@ -0,0 +1,406 @@
1
+ # frozen_string_literal: true
2
+
3
+ =begin
4
+ #Azure OpenAI Service API
5
+
6
+ #Azure OpenAI APIs for completions and search
7
+
8
+ OpenAPI spec version: 2023-05-15
9
+
10
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
11
+ Swagger Codegen version: 3.0.42
12
+ =end
13
+
14
+ require 'date'
15
+
16
+ module AzureOpenaiClient
17
+ class DeploymentidCompletionsBody
18
+ # The prompt(s) to generate completions for, encoded as a string or array of strings. Note that <|endoftext|> is the document separator that the model sees during training, so if a prompt is not specified the model will generate as if from the beginning of a new document. Maximum allowed size of string list is 2048.
19
+ attr_accessor :prompt
20
+
21
+ # 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.
22
+ attr_accessor :max_tokens
23
+
24
+ # 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.
25
+ attr_accessor :temperature
26
+
27
+ # 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.
28
+ attr_accessor :top_p
29
+
30
+ # 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 {\"50256\" &#58; -100} to prevent the <|endoftext|> token from being generated.
31
+ attr_accessor :logit_bias
32
+
33
+ # A unique identifier representing your end-user, which can help monitoring and detecting abuse
34
+ attr_accessor :user
35
+
36
+ # 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.
37
+ attr_accessor :n
38
+
39
+ # 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.
40
+ attr_accessor :stream
41
+
42
+ # 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.
43
+ attr_accessor :logprobs
44
+
45
+ # 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.
46
+ attr_accessor :model
47
+
48
+ # The suffix that comes after a completion of inserted text.
49
+ attr_accessor :suffix
50
+
51
+ # Echo back the prompt in addition to the completion
52
+ attr_accessor :echo
53
+
54
+ # Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.
55
+ attr_accessor :stop
56
+
57
+ attr_accessor :completion_config
58
+
59
+ # can be used to disable any server-side caching, 0=no cache, 1=prompt prefix enabled, 2=full cache
60
+ attr_accessor :cache_level
61
+
62
+ # 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.
63
+ attr_accessor :presence_penalty
64
+
65
+ # 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.
66
+ attr_accessor :frequency_penalty
67
+
68
+ # 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.
69
+ attr_accessor :best_of
70
+
71
+ # Attribute mapping from ruby-style variable name to JSON key.
72
+ def self.attribute_map
73
+ {
74
+ 'prompt': :'prompt',
75
+ 'max_tokens': :'max_tokens',
76
+ 'temperature': :'temperature',
77
+ 'top_p': :'top_p',
78
+ 'logit_bias': :'logit_bias',
79
+ 'user': :'user',
80
+ 'n': :'n',
81
+ 'stream': :'stream',
82
+ 'logprobs': :'logprobs',
83
+ 'model': :'model',
84
+ 'suffix': :'suffix',
85
+ 'echo': :'echo',
86
+ 'stop': :'stop',
87
+ 'completion_config': :'completion_config',
88
+ 'cache_level': :'cache_level',
89
+ 'presence_penalty': :'presence_penalty',
90
+ 'frequency_penalty': :'frequency_penalty',
91
+ 'best_of': :'best_of'
92
+ }
93
+ end
94
+
95
+ # Attribute type mapping.
96
+ def self.openapi_types
97
+ {
98
+ 'prompt': :'Object',
99
+ 'max_tokens': :'Object',
100
+ 'temperature': :'Object',
101
+ 'top_p': :'Object',
102
+ 'logit_bias': :'Object',
103
+ 'user': :'Object',
104
+ 'n': :'Object',
105
+ 'stream': :'Object',
106
+ 'logprobs': :'Object',
107
+ 'model': :'Object',
108
+ 'suffix': :'Object',
109
+ 'echo': :'Object',
110
+ 'stop': :'Object',
111
+ 'completion_config': :'Object',
112
+ 'cache_level': :'Object',
113
+ 'presence_penalty': :'Object',
114
+ 'frequency_penalty': :'Object',
115
+ 'best_of': :'Object'
116
+ }
117
+ end
118
+
119
+ # List of attributes with nullable: true
120
+ def self.openapi_nullable
121
+ Set.new([
122
+ :'max_tokens',
123
+ :'temperature',
124
+ :'top_p',
125
+ :'n',
126
+ :'stream',
127
+ :'logprobs',
128
+ :'model',
129
+ :'suffix',
130
+ :'echo',
131
+ :'completion_config',
132
+ :'cache_level',
133
+ ])
134
+ end
135
+
136
+ # Initializes the object
137
+ # @param [Hash] attributes Model attributes in the form of hash
138
+ def initialize(attributes = {})
139
+ if (!attributes.is_a?(Hash))
140
+ fail ArgumentError, "The input argument (attributes) must be a hash in `AzureOpenaiClient::DeploymentidCompletionsBody` initialize method"
141
+ end
142
+
143
+ # check to see if the attribute exists and convert string to symbol for hash key
144
+ attributes = attributes.each_with_object({}) { |(k, v), h|
145
+ if (!self.class.attribute_map.key?(k.to_sym))
146
+ fail ArgumentError, "`#{k}` is not a valid attribute in `AzureOpenaiClient::DeploymentidCompletionsBody`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
147
+ end
148
+ h[k.to_sym] = v
149
+ }
150
+
151
+ if attributes.key?(:'prompt')
152
+ self.prompt = attributes[:'prompt']
153
+ end
154
+
155
+ if attributes.key?(:'max_tokens')
156
+ self.max_tokens = attributes[:'max_tokens']
157
+ else
158
+ self.max_tokens = 16
159
+ end
160
+
161
+ if attributes.key?(:'temperature')
162
+ self.temperature = attributes[:'temperature']
163
+ else
164
+ self.temperature = 1
165
+ end
166
+
167
+ if attributes.key?(:'top_p')
168
+ self.top_p = attributes[:'top_p']
169
+ else
170
+ self.top_p = 1
171
+ end
172
+
173
+ if attributes.key?(:'logit_bias')
174
+ self.logit_bias = attributes[:'logit_bias']
175
+ end
176
+
177
+ if attributes.key?(:'user')
178
+ self.user = attributes[:'user']
179
+ end
180
+
181
+ if attributes.key?(:'n')
182
+ self.n = attributes[:'n']
183
+ else
184
+ self.n = 1
185
+ end
186
+
187
+ if attributes.key?(:'stream')
188
+ self.stream = attributes[:'stream']
189
+ else
190
+ self.stream = false
191
+ end
192
+
193
+ if attributes.key?(:'logprobs')
194
+ self.logprobs = attributes[:'logprobs']
195
+ end
196
+
197
+ if attributes.key?(:'model')
198
+ self.model = attributes[:'model']
199
+ end
200
+
201
+ if attributes.key?(:'suffix')
202
+ self.suffix = attributes[:'suffix']
203
+ end
204
+
205
+ if attributes.key?(:'echo')
206
+ self.echo = attributes[:'echo']
207
+ else
208
+ self.echo = false
209
+ end
210
+
211
+ if attributes.key?(:'stop')
212
+ self.stop = attributes[:'stop']
213
+ end
214
+
215
+ if attributes.key?(:'completion_config')
216
+ self.completion_config = attributes[:'completion_config']
217
+ end
218
+
219
+ if attributes.key?(:'cache_level')
220
+ self.cache_level = attributes[:'cache_level']
221
+ end
222
+
223
+ if attributes.key?(:'presence_penalty')
224
+ self.presence_penalty = attributes[:'presence_penalty']
225
+ else
226
+ self.presence_penalty = 0
227
+ end
228
+
229
+ if attributes.key?(:'frequency_penalty')
230
+ self.frequency_penalty = attributes[:'frequency_penalty']
231
+ else
232
+ self.frequency_penalty = 0
233
+ end
234
+
235
+ if attributes.key?(:'best_of')
236
+ self.best_of = attributes[:'best_of']
237
+ end
238
+ end
239
+
240
+ # Show invalid properties with the reasons. Usually used together with valid?
241
+ # @return Array for valid properties with the reasons
242
+ def list_invalid_properties
243
+ invalid_properties = Array.new
244
+ invalid_properties
245
+ end
246
+
247
+ # Check to see if the all the properties in the model are valid
248
+ # @return true if the model is valid
249
+ def valid?
250
+ true
251
+ end
252
+
253
+ # Checks equality by comparing each attribute.
254
+ # @param [Object] Object to be compared
255
+ def ==(o)
256
+ return true if self.equal?(o)
257
+ self.class == o.class &&
258
+ prompt == o.prompt &&
259
+ max_tokens == o.max_tokens &&
260
+ temperature == o.temperature &&
261
+ top_p == o.top_p &&
262
+ logit_bias == o.logit_bias &&
263
+ user == o.user &&
264
+ n == o.n &&
265
+ stream == o.stream &&
266
+ logprobs == o.logprobs &&
267
+ model == o.model &&
268
+ suffix == o.suffix &&
269
+ echo == o.echo &&
270
+ stop == o.stop &&
271
+ completion_config == o.completion_config &&
272
+ cache_level == o.cache_level &&
273
+ presence_penalty == o.presence_penalty &&
274
+ frequency_penalty == o.frequency_penalty &&
275
+ best_of == o.best_of
276
+ end
277
+
278
+ # @see the `==` method
279
+ # @param [Object] Object to be compared
280
+ def eql?(o)
281
+ self == o
282
+ end
283
+
284
+ # Calculates hash code according to all attributes.
285
+ # @return [Integer] Hash code
286
+ def hash
287
+ [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
288
+ end
289
+
290
+ # Builds the object from hash
291
+ # @param [Hash] attributes Model attributes in the form of hash
292
+ # @return [Object] Returns the model itself
293
+ def self.build_from_hash(attributes)
294
+ new.build_from_hash(attributes)
295
+ end
296
+
297
+ # Builds the object from hash
298
+ # @param [Hash] attributes Model attributes in the form of hash
299
+ # @return [Object] Returns the model itself
300
+ def build_from_hash(attributes)
301
+ return nil unless attributes.is_a?(Hash)
302
+ self.class.openapi_types.each_pair do |key, type|
303
+ if type =~ /\AArray<(.*)>/i
304
+ # check to ensure the input is an array given that the attribute
305
+ # is documented as an array but the input is not
306
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
307
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
308
+ end
309
+ elsif !attributes[self.class.attribute_map[key]].nil?
310
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
311
+ elsif attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
312
+ self.send("#{key}=", nil)
313
+ end
314
+ end
315
+
316
+ self
317
+ end
318
+
319
+ # Deserializes the data based on type
320
+ # @param string type Data type
321
+ # @param string value Value to be deserialized
322
+ # @return [Object] Deserialized data
323
+ def _deserialize(type, value)
324
+ case type.to_sym
325
+ when :DateTime
326
+ DateTime.parse(value)
327
+ when :Date
328
+ Date.parse(value)
329
+ when :String
330
+ value.to_s
331
+ when :Integer
332
+ value.to_i
333
+ when :Float
334
+ value.to_f
335
+ when :Boolean
336
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
337
+ true
338
+ else
339
+ false
340
+ end
341
+ when :Object
342
+ # generic object (usually a Hash), return directly
343
+ value
344
+ when /\AArray<(?<inner_type>.+)>\z/
345
+ inner_type = Regexp.last_match[:inner_type]
346
+ value.map { |v| _deserialize(inner_type, v) }
347
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
348
+ k_type = Regexp.last_match[:k_type]
349
+ v_type = Regexp.last_match[:v_type]
350
+ {}.tap do |hash|
351
+ value.each do |k, v|
352
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
353
+ end
354
+ end
355
+ else # model
356
+ AzureOpenaiClient.const_get(type).build_from_hash(value)
357
+ end
358
+ end
359
+
360
+ # Returns the string representation of the object
361
+ # @return [String] String presentation of the object
362
+ def to_s
363
+ to_hash.to_s
364
+ end
365
+
366
+ # to_body is an alias to to_hash (backward compatibility)
367
+ # @return [Hash] Returns the object in the form of hash
368
+ def to_body
369
+ to_hash
370
+ end
371
+
372
+ # Returns the object in the form of hash
373
+ # @return [Hash] Returns the object in the form of hash
374
+ def to_hash
375
+ hash = {}
376
+ self.class.attribute_map.each_pair do |attr, param|
377
+ value = self.send(attr)
378
+ if value.nil?
379
+ is_nullable = self.class.openapi_nullable.include?(attr)
380
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
381
+ end
382
+
383
+ hash[param] = _to_hash(value)
384
+ end
385
+ hash
386
+ end
387
+
388
+ # Outputs non-array value in the form of hash
389
+ # For object, use to_hash. Otherwise, just return the value
390
+ # @param [Object] value Any valid value
391
+ # @return [Hash] Returns the value in the form of hash
392
+ def _to_hash(value)
393
+ if value.is_a?(Array)
394
+ value.compact.map { |v| _to_hash(v) }
395
+ elsif value.is_a?(Hash)
396
+ {}.tap do |hash|
397
+ value.each { |k, v| hash[k] = _to_hash(v) }
398
+ end
399
+ elsif value.respond_to? :to_hash
400
+ value.to_hash
401
+ else
402
+ value
403
+ end
404
+ end
405
+ end
406
+ end
@@ -0,0 +1,202 @@
1
+ # frozen_string_literal: true
2
+
3
+ =begin
4
+ #Azure OpenAI Service API
5
+
6
+ #Azure OpenAI APIs for completions and search
7
+
8
+ OpenAPI spec version: 2023-05-15
9
+
10
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
11
+ Swagger Codegen version: 3.0.42
12
+ =end
13
+
14
+ require 'date'
15
+
16
+ module AzureOpenaiClient
17
+ class DeploymentidEmbeddingsBody
18
+ # Attribute mapping from ruby-style variable name to JSON key.
19
+ def self.attribute_map
20
+ {}
21
+ end
22
+
23
+ # Attribute type mapping.
24
+ def self.openapi_types
25
+ {}
26
+ end
27
+
28
+ # List of attributes with nullable: true
29
+ def self.openapi_nullable
30
+ Set.new([
31
+ ])
32
+ end
33
+
34
+ # Initializes the object
35
+ # @param [Hash] attributes Model attributes in the form of hash
36
+ def initialize(attributes = {})
37
+ if (!attributes.is_a?(Hash))
38
+ fail ArgumentError, "The input argument (attributes) must be a hash in `AzureOpenaiClient::DeploymentidEmbeddingsBody` initialize method"
39
+ end
40
+
41
+ # check to see if the attribute exists and convert string to symbol for hash key
42
+ attributes = attributes.each_with_object({}) { |(k, v), h|
43
+ if (!self.class.attribute_map.key?(k.to_sym))
44
+ fail ArgumentError, "`#{k}` is not a valid attribute in `AzureOpenaiClient::DeploymentidEmbeddingsBody`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
45
+ end
46
+ h[k.to_sym] = v
47
+ }
48
+
49
+ # call parent's initialize
50
+ super(attributes)
51
+ end
52
+
53
+ # Show invalid properties with the reasons. Usually used together with valid?
54
+ # @return Array for valid properties with the reasons
55
+ def list_invalid_properties
56
+ invalid_properties = super
57
+ invalid_properties
58
+ end
59
+
60
+ # Check to see if the all the properties in the model are valid
61
+ # @return true if the model is valid
62
+ def valid?
63
+ true
64
+ end
65
+
66
+ # Checks equality by comparing each attribute.
67
+ # @param [Object] Object to be compared
68
+ def ==(o)
69
+ return true if self.equal?(o)
70
+ self.class == o.class && super(o)
71
+ end
72
+
73
+ # @see the `==` method
74
+ # @param [Object] Object to be compared
75
+ def eql?(o)
76
+ self == o
77
+ end
78
+
79
+ # Calculates hash code according to all attributes.
80
+ # @return [Integer] Hash code
81
+ def hash
82
+ [].hash
83
+ end
84
+
85
+ # Builds the object from hash
86
+ # @param [Hash] attributes Model attributes in the form of hash
87
+ # @return [Object] Returns the model itself
88
+ def self.build_from_hash(attributes)
89
+ new.build_from_hash(attributes)
90
+ end
91
+
92
+ # Builds the object from hash
93
+ # @param [Hash] attributes Model attributes in the form of hash
94
+ # @return [Object] Returns the model itself
95
+ def build_from_hash(attributes)
96
+ return nil unless attributes.is_a?(Hash)
97
+ super(attributes)
98
+ self.class.openapi_types.each_pair do |key, type|
99
+ if type =~ /\AArray<(.*)>/i
100
+ # check to ensure the input is an array given that the attribute
101
+ # is documented as an array but the input is not
102
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
103
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
104
+ end
105
+ elsif !attributes[self.class.attribute_map[key]].nil?
106
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
107
+ elsif attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
108
+ self.send("#{key}=", nil)
109
+ end
110
+ end
111
+
112
+ self
113
+ end
114
+
115
+ # Deserializes the data based on type
116
+ # @param string type Data type
117
+ # @param string value Value to be deserialized
118
+ # @return [Object] Deserialized data
119
+ def _deserialize(type, value)
120
+ case type.to_sym
121
+ when :DateTime
122
+ DateTime.parse(value)
123
+ when :Date
124
+ Date.parse(value)
125
+ when :String
126
+ value.to_s
127
+ when :Integer
128
+ value.to_i
129
+ when :Float
130
+ value.to_f
131
+ when :Boolean
132
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
133
+ true
134
+ else
135
+ false
136
+ end
137
+ when :Object
138
+ # generic object (usually a Hash), return directly
139
+ value
140
+ when /\AArray<(?<inner_type>.+)>\z/
141
+ inner_type = Regexp.last_match[:inner_type]
142
+ value.map { |v| _deserialize(inner_type, v) }
143
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
144
+ k_type = Regexp.last_match[:k_type]
145
+ v_type = Regexp.last_match[:v_type]
146
+ {}.tap do |hash|
147
+ value.each do |k, v|
148
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
149
+ end
150
+ end
151
+ else # model
152
+ AzureOpenaiClient.const_get(type).build_from_hash(value)
153
+ end
154
+ end
155
+
156
+ # Returns the string representation of the object
157
+ # @return [String] String presentation of the object
158
+ def to_s
159
+ to_hash.to_s
160
+ end
161
+
162
+ # to_body is an alias to to_hash (backward compatibility)
163
+ # @return [Hash] Returns the object in the form of hash
164
+ def to_body
165
+ to_hash
166
+ end
167
+
168
+ # Returns the object in the form of hash
169
+ # @return [Hash] Returns the object in the form of hash
170
+ def to_hash
171
+ hash = super
172
+ self.class.attribute_map.each_pair do |attr, param|
173
+ value = self.send(attr)
174
+ if value.nil?
175
+ is_nullable = self.class.openapi_nullable.include?(attr)
176
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
177
+ end
178
+
179
+ hash[param] = _to_hash(value)
180
+ end
181
+ hash
182
+ end
183
+
184
+ # Outputs non-array value in the form of hash
185
+ # For object, use to_hash. Otherwise, just return the value
186
+ # @param [Object] value Any valid value
187
+ # @return [Hash] Returns the value in the form of hash
188
+ def _to_hash(value)
189
+ if value.is_a?(Array)
190
+ value.compact.map { |v| _to_hash(v) }
191
+ elsif value.is_a?(Hash)
192
+ {}.tap do |hash|
193
+ value.each { |k, v| hash[k] = _to_hash(v) }
194
+ end
195
+ elsif value.respond_to? :to_hash
196
+ value.to_hash
197
+ else
198
+ value
199
+ end
200
+ end
201
+ end
202
+ end