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,274 @@
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 DeploymentsdeploymentidchatcompletionsMessages
18
+ # The role of the author of this message.
19
+ attr_accessor :role
20
+
21
+ # The contents of the message
22
+ attr_accessor :content
23
+
24
+ # The name of the user in a multi-user chat
25
+ attr_accessor :name
26
+
27
+ class EnumAttributeValidator
28
+ attr_reader :datatype
29
+ attr_reader :allowable_values
30
+
31
+ def initialize(datatype, allowable_values)
32
+ @allowable_values = allowable_values.map do |value|
33
+ case datatype.to_s
34
+ when /Integer/i
35
+ value.to_i
36
+ when /Float/i
37
+ value.to_f
38
+ else
39
+ value
40
+ end
41
+ end
42
+ end
43
+
44
+ def valid?(value)
45
+ !value || allowable_values.include?(value)
46
+ end
47
+ end
48
+
49
+ # Attribute mapping from ruby-style variable name to JSON key.
50
+ def self.attribute_map
51
+ {
52
+ 'role': :'role',
53
+ 'content': :'content',
54
+ 'name': :'name'
55
+ }
56
+ end
57
+
58
+ # Attribute type mapping.
59
+ def self.openapi_types
60
+ {
61
+ 'role': :'Object',
62
+ 'content': :'Object',
63
+ 'name': :'Object'
64
+ }
65
+ end
66
+
67
+ # List of attributes with nullable: true
68
+ def self.openapi_nullable
69
+ Set.new([
70
+ ])
71
+ end
72
+
73
+ # Initializes the object
74
+ # @param [Hash] attributes Model attributes in the form of hash
75
+ def initialize(attributes = {})
76
+ if (!attributes.is_a?(Hash))
77
+ fail ArgumentError, "The input argument (attributes) must be a hash in `AzureOpenaiClient::DeploymentsdeploymentidchatcompletionsMessages` initialize method"
78
+ end
79
+
80
+ # check to see if the attribute exists and convert string to symbol for hash key
81
+ attributes = attributes.each_with_object({}) { |(k, v), h|
82
+ if (!self.class.attribute_map.key?(k.to_sym))
83
+ fail ArgumentError, "`#{k}` is not a valid attribute in `AzureOpenaiClient::DeploymentsdeploymentidchatcompletionsMessages`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
84
+ end
85
+ h[k.to_sym] = v
86
+ }
87
+
88
+ if attributes.key?(:'role')
89
+ self.role = attributes[:'role']
90
+ end
91
+
92
+ if attributes.key?(:'content')
93
+ self.content = attributes[:'content']
94
+ end
95
+
96
+ if attributes.key?(:'name')
97
+ self.name = attributes[:'name']
98
+ end
99
+ end
100
+
101
+ # Show invalid properties with the reasons. Usually used together with valid?
102
+ # @return Array for valid properties with the reasons
103
+ def list_invalid_properties
104
+ invalid_properties = Array.new
105
+ if @role.nil?
106
+ invalid_properties.push('invalid value for "role", role cannot be nil.')
107
+ end
108
+
109
+ if @content.nil?
110
+ invalid_properties.push('invalid value for "content", content cannot be nil.')
111
+ end
112
+
113
+ invalid_properties
114
+ end
115
+
116
+ # Check to see if the all the properties in the model are valid
117
+ # @return true if the model is valid
118
+ def valid?
119
+ return false if @role.nil?
120
+ role_validator = EnumAttributeValidator.new('Object', ['system', 'user', 'assistant'])
121
+ return false unless role_validator.valid?(@role)
122
+ return false if @content.nil?
123
+ true
124
+ end
125
+
126
+ # Custom attribute writer method checking allowed values (enum).
127
+ # @param [Object] role Object to be assigned
128
+ def role=(role)
129
+ validator = EnumAttributeValidator.new('Object', ['system', 'user', 'assistant'])
130
+ unless validator.valid?(role)
131
+ fail ArgumentError, "invalid value for \"role\", must be one of #{validator.allowable_values}."
132
+ end
133
+ @role = role
134
+ end
135
+
136
+ # Checks equality by comparing each attribute.
137
+ # @param [Object] Object to be compared
138
+ def ==(o)
139
+ return true if self.equal?(o)
140
+ self.class == o.class &&
141
+ role == o.role &&
142
+ content == o.content &&
143
+ name == o.name
144
+ end
145
+
146
+ # @see the `==` method
147
+ # @param [Object] Object to be compared
148
+ def eql?(o)
149
+ self == o
150
+ end
151
+
152
+ # Calculates hash code according to all attributes.
153
+ # @return [Integer] Hash code
154
+ def hash
155
+ [role, content, name].hash
156
+ end
157
+
158
+ # Builds the object from hash
159
+ # @param [Hash] attributes Model attributes in the form of hash
160
+ # @return [Object] Returns the model itself
161
+ def self.build_from_hash(attributes)
162
+ new.build_from_hash(attributes)
163
+ end
164
+
165
+ # Builds the object from hash
166
+ # @param [Hash] attributes Model attributes in the form of hash
167
+ # @return [Object] Returns the model itself
168
+ def build_from_hash(attributes)
169
+ return nil unless attributes.is_a?(Hash)
170
+ self.class.openapi_types.each_pair do |key, type|
171
+ if type =~ /\AArray<(.*)>/i
172
+ # check to ensure the input is an array given that the attribute
173
+ # is documented as an array but the input is not
174
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
175
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
176
+ end
177
+ elsif !attributes[self.class.attribute_map[key]].nil?
178
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
179
+ elsif attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
180
+ self.send("#{key}=", nil)
181
+ end
182
+ end
183
+
184
+ self
185
+ end
186
+
187
+ # Deserializes the data based on type
188
+ # @param string type Data type
189
+ # @param string value Value to be deserialized
190
+ # @return [Object] Deserialized data
191
+ def _deserialize(type, value)
192
+ case type.to_sym
193
+ when :DateTime
194
+ DateTime.parse(value)
195
+ when :Date
196
+ Date.parse(value)
197
+ when :String
198
+ value.to_s
199
+ when :Integer
200
+ value.to_i
201
+ when :Float
202
+ value.to_f
203
+ when :Boolean
204
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
205
+ true
206
+ else
207
+ false
208
+ end
209
+ when :Object
210
+ # generic object (usually a Hash), return directly
211
+ value
212
+ when /\AArray<(?<inner_type>.+)>\z/
213
+ inner_type = Regexp.last_match[:inner_type]
214
+ value.map { |v| _deserialize(inner_type, v) }
215
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
216
+ k_type = Regexp.last_match[:k_type]
217
+ v_type = Regexp.last_match[:v_type]
218
+ {}.tap do |hash|
219
+ value.each do |k, v|
220
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
221
+ end
222
+ end
223
+ else # model
224
+ AzureOpenaiClient.const_get(type).build_from_hash(value)
225
+ end
226
+ end
227
+
228
+ # Returns the string representation of the object
229
+ # @return [String] String presentation of the object
230
+ def to_s
231
+ to_hash.to_s
232
+ end
233
+
234
+ # to_body is an alias to to_hash (backward compatibility)
235
+ # @return [Hash] Returns the object in the form of hash
236
+ def to_body
237
+ to_hash
238
+ end
239
+
240
+ # Returns the object in the form of hash
241
+ # @return [Hash] Returns the object in the form of hash
242
+ def to_hash
243
+ hash = {}
244
+ self.class.attribute_map.each_pair do |attr, param|
245
+ value = self.send(attr)
246
+ if value.nil?
247
+ is_nullable = self.class.openapi_nullable.include?(attr)
248
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
249
+ end
250
+
251
+ hash[param] = _to_hash(value)
252
+ end
253
+ hash
254
+ end
255
+
256
+ # Outputs non-array value in the form of hash
257
+ # For object, use to_hash. Otherwise, just return the value
258
+ # @param [Object] value Any valid value
259
+ # @return [Hash] Returns the value in the form of hash
260
+ def _to_hash(value)
261
+ if value.is_a?(Array)
262
+ value.compact.map { |v| _to_hash(v) }
263
+ elsif value.is_a?(Hash)
264
+ {}.tap do |hash|
265
+ value.each { |k, v| hash[k] = _to_hash(v) }
266
+ end
267
+ elsif value.respond_to? :to_hash
268
+ value.to_hash
269
+ else
270
+ value
271
+ end
272
+ end
273
+ end
274
+ end
@@ -0,0 +1,209 @@
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 ErrorResponse
18
+ attr_accessor :error
19
+
20
+ # Attribute mapping from ruby-style variable name to JSON key.
21
+ def self.attribute_map
22
+ {
23
+ 'error': :'error'
24
+ }
25
+ end
26
+
27
+ # Attribute type mapping.
28
+ def self.openapi_types
29
+ {
30
+ 'error': :'Object'
31
+ }
32
+ end
33
+
34
+ # List of attributes with nullable: true
35
+ def self.openapi_nullable
36
+ Set.new([
37
+ ])
38
+ end
39
+
40
+ # Initializes the object
41
+ # @param [Hash] attributes Model attributes in the form of hash
42
+ def initialize(attributes = {})
43
+ if (!attributes.is_a?(Hash))
44
+ fail ArgumentError, "The input argument (attributes) must be a hash in `AzureOpenaiClient::ErrorResponse` initialize method"
45
+ end
46
+
47
+ # check to see if the attribute exists and convert string to symbol for hash key
48
+ attributes = attributes.each_with_object({}) { |(k, v), h|
49
+ if (!self.class.attribute_map.key?(k.to_sym))
50
+ fail ArgumentError, "`#{k}` is not a valid attribute in `AzureOpenaiClient::ErrorResponse`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
51
+ end
52
+ h[k.to_sym] = v
53
+ }
54
+
55
+ if attributes.key?(:'error')
56
+ self.error = attributes[:'error']
57
+ end
58
+ end
59
+
60
+ # Show invalid properties with the reasons. Usually used together with valid?
61
+ # @return Array for valid properties with the reasons
62
+ def list_invalid_properties
63
+ invalid_properties = Array.new
64
+ invalid_properties
65
+ end
66
+
67
+ # Check to see if the all the properties in the model are valid
68
+ # @return true if the model is valid
69
+ def valid?
70
+ true
71
+ end
72
+
73
+ # Checks equality by comparing each attribute.
74
+ # @param [Object] Object to be compared
75
+ def ==(o)
76
+ return true if self.equal?(o)
77
+ self.class == o.class &&
78
+ error == o.error
79
+ end
80
+
81
+ # @see the `==` method
82
+ # @param [Object] Object to be compared
83
+ def eql?(o)
84
+ self == o
85
+ end
86
+
87
+ # Calculates hash code according to all attributes.
88
+ # @return [Integer] Hash code
89
+ def hash
90
+ [error].hash
91
+ end
92
+
93
+ # Builds the object from hash
94
+ # @param [Hash] attributes Model attributes in the form of hash
95
+ # @return [Object] Returns the model itself
96
+ def self.build_from_hash(attributes)
97
+ new.build_from_hash(attributes)
98
+ end
99
+
100
+ # Builds the object from hash
101
+ # @param [Hash] attributes Model attributes in the form of hash
102
+ # @return [Object] Returns the model itself
103
+ def build_from_hash(attributes)
104
+ return nil unless attributes.is_a?(Hash)
105
+ self.class.openapi_types.each_pair do |key, type|
106
+ if type =~ /\AArray<(.*)>/i
107
+ # check to ensure the input is an array given that the attribute
108
+ # is documented as an array but the input is not
109
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
110
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
111
+ end
112
+ elsif !attributes[self.class.attribute_map[key]].nil?
113
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
114
+ elsif attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
115
+ self.send("#{key}=", nil)
116
+ end
117
+ end
118
+
119
+ self
120
+ end
121
+
122
+ # Deserializes the data based on type
123
+ # @param string type Data type
124
+ # @param string value Value to be deserialized
125
+ # @return [Object] Deserialized data
126
+ def _deserialize(type, value)
127
+ case type.to_sym
128
+ when :DateTime
129
+ DateTime.parse(value)
130
+ when :Date
131
+ Date.parse(value)
132
+ when :String
133
+ value.to_s
134
+ when :Integer
135
+ value.to_i
136
+ when :Float
137
+ value.to_f
138
+ when :Boolean
139
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
140
+ true
141
+ else
142
+ false
143
+ end
144
+ when :Object
145
+ # generic object (usually a Hash), return directly
146
+ value
147
+ when /\AArray<(?<inner_type>.+)>\z/
148
+ inner_type = Regexp.last_match[:inner_type]
149
+ value.map { |v| _deserialize(inner_type, v) }
150
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
151
+ k_type = Regexp.last_match[:k_type]
152
+ v_type = Regexp.last_match[:v_type]
153
+ {}.tap do |hash|
154
+ value.each do |k, v|
155
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
156
+ end
157
+ end
158
+ else # model
159
+ AzureOpenaiClient.const_get(type).build_from_hash(value)
160
+ end
161
+ end
162
+
163
+ # Returns the string representation of the object
164
+ # @return [String] String presentation of the object
165
+ def to_s
166
+ to_hash.to_s
167
+ end
168
+
169
+ # to_body is an alias to to_hash (backward compatibility)
170
+ # @return [Hash] Returns the object in the form of hash
171
+ def to_body
172
+ to_hash
173
+ end
174
+
175
+ # Returns the object in the form of hash
176
+ # @return [Hash] Returns the object in the form of hash
177
+ def to_hash
178
+ hash = {}
179
+ self.class.attribute_map.each_pair do |attr, param|
180
+ value = self.send(attr)
181
+ if value.nil?
182
+ is_nullable = self.class.openapi_nullable.include?(attr)
183
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
184
+ end
185
+
186
+ hash[param] = _to_hash(value)
187
+ end
188
+ hash
189
+ end
190
+
191
+ # Outputs non-array value in the form of hash
192
+ # For object, use to_hash. Otherwise, just return the value
193
+ # @param [Object] value Any valid value
194
+ # @return [Hash] Returns the value in the form of hash
195
+ def _to_hash(value)
196
+ if value.is_a?(Array)
197
+ value.compact.map { |v| _to_hash(v) }
198
+ elsif value.is_a?(Hash)
199
+ {}.tap do |hash|
200
+ value.each { |k, v| hash[k] = _to_hash(v) }
201
+ end
202
+ elsif value.respond_to? :to_hash
203
+ value.to_hash
204
+ else
205
+ value
206
+ end
207
+ end
208
+ end
209
+ end
@@ -0,0 +1,236 @@
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 ErrorResponseError
18
+ attr_accessor :code
19
+
20
+ attr_accessor :message
21
+
22
+ attr_accessor :param
23
+
24
+ attr_accessor :type
25
+
26
+ # Attribute mapping from ruby-style variable name to JSON key.
27
+ def self.attribute_map
28
+ {
29
+ 'code': :'code',
30
+ 'message': :'message',
31
+ 'param': :'param',
32
+ 'type': :'type'
33
+ }
34
+ end
35
+
36
+ # Attribute type mapping.
37
+ def self.openapi_types
38
+ {
39
+ 'code': :'Object',
40
+ 'message': :'Object',
41
+ 'param': :'Object',
42
+ 'type': :'Object'
43
+ }
44
+ end
45
+
46
+ # List of attributes with nullable: true
47
+ def self.openapi_nullable
48
+ Set.new([
49
+ ])
50
+ end
51
+
52
+ # Initializes the object
53
+ # @param [Hash] attributes Model attributes in the form of hash
54
+ def initialize(attributes = {})
55
+ if (!attributes.is_a?(Hash))
56
+ fail ArgumentError, "The input argument (attributes) must be a hash in `AzureOpenaiClient::ErrorResponseError` initialize method"
57
+ end
58
+
59
+ # check to see if the attribute exists and convert string to symbol for hash key
60
+ attributes = attributes.each_with_object({}) { |(k, v), h|
61
+ if (!self.class.attribute_map.key?(k.to_sym))
62
+ fail ArgumentError, "`#{k}` is not a valid attribute in `AzureOpenaiClient::ErrorResponseError`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
63
+ end
64
+ h[k.to_sym] = v
65
+ }
66
+
67
+ if attributes.key?(:'code')
68
+ self.code = attributes[:'code']
69
+ end
70
+
71
+ if attributes.key?(:'message')
72
+ self.message = attributes[:'message']
73
+ end
74
+
75
+ if attributes.key?(:'param')
76
+ self.param = attributes[:'param']
77
+ end
78
+
79
+ if attributes.key?(:'type')
80
+ self.type = attributes[:'type']
81
+ end
82
+ end
83
+
84
+ # Show invalid properties with the reasons. Usually used together with valid?
85
+ # @return Array for valid properties with the reasons
86
+ def list_invalid_properties
87
+ invalid_properties = Array.new
88
+ invalid_properties
89
+ end
90
+
91
+ # Check to see if the all the properties in the model are valid
92
+ # @return true if the model is valid
93
+ def valid?
94
+ true
95
+ end
96
+
97
+ # Checks equality by comparing each attribute.
98
+ # @param [Object] Object to be compared
99
+ def ==(o)
100
+ return true if self.equal?(o)
101
+ self.class == o.class &&
102
+ code == o.code &&
103
+ message == o.message &&
104
+ param == o.param &&
105
+ type == o.type
106
+ end
107
+
108
+ # @see the `==` method
109
+ # @param [Object] Object to be compared
110
+ def eql?(o)
111
+ self == o
112
+ end
113
+
114
+ # Calculates hash code according to all attributes.
115
+ # @return [Integer] Hash code
116
+ def hash
117
+ [code, message, param, type].hash
118
+ end
119
+
120
+ # Builds the object from hash
121
+ # @param [Hash] attributes Model attributes in the form of hash
122
+ # @return [Object] Returns the model itself
123
+ def self.build_from_hash(attributes)
124
+ new.build_from_hash(attributes)
125
+ end
126
+
127
+ # Builds the object from hash
128
+ # @param [Hash] attributes Model attributes in the form of hash
129
+ # @return [Object] Returns the model itself
130
+ def build_from_hash(attributes)
131
+ return nil unless attributes.is_a?(Hash)
132
+ self.class.openapi_types.each_pair do |key, type|
133
+ if type =~ /\AArray<(.*)>/i
134
+ # check to ensure the input is an array given that the attribute
135
+ # is documented as an array but the input is not
136
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
137
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
138
+ end
139
+ elsif !attributes[self.class.attribute_map[key]].nil?
140
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
141
+ elsif attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
142
+ self.send("#{key}=", nil)
143
+ end
144
+ end
145
+
146
+ self
147
+ end
148
+
149
+ # Deserializes the data based on type
150
+ # @param string type Data type
151
+ # @param string value Value to be deserialized
152
+ # @return [Object] Deserialized data
153
+ def _deserialize(type, value)
154
+ case type.to_sym
155
+ when :DateTime
156
+ DateTime.parse(value)
157
+ when :Date
158
+ Date.parse(value)
159
+ when :String
160
+ value.to_s
161
+ when :Integer
162
+ value.to_i
163
+ when :Float
164
+ value.to_f
165
+ when :Boolean
166
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
167
+ true
168
+ else
169
+ false
170
+ end
171
+ when :Object
172
+ # generic object (usually a Hash), return directly
173
+ value
174
+ when /\AArray<(?<inner_type>.+)>\z/
175
+ inner_type = Regexp.last_match[:inner_type]
176
+ value.map { |v| _deserialize(inner_type, v) }
177
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
178
+ k_type = Regexp.last_match[:k_type]
179
+ v_type = Regexp.last_match[:v_type]
180
+ {}.tap do |hash|
181
+ value.each do |k, v|
182
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
183
+ end
184
+ end
185
+ else # model
186
+ AzureOpenaiClient.const_get(type).build_from_hash(value)
187
+ end
188
+ end
189
+
190
+ # Returns the string representation of the object
191
+ # @return [String] String presentation of the object
192
+ def to_s
193
+ to_hash.to_s
194
+ end
195
+
196
+ # to_body is an alias to to_hash (backward compatibility)
197
+ # @return [Hash] Returns the object in the form of hash
198
+ def to_body
199
+ to_hash
200
+ end
201
+
202
+ # Returns the object in the form of hash
203
+ # @return [Hash] Returns the object in the form of hash
204
+ def to_hash
205
+ hash = {}
206
+ self.class.attribute_map.each_pair do |attr, param|
207
+ value = self.send(attr)
208
+ if value.nil?
209
+ is_nullable = self.class.openapi_nullable.include?(attr)
210
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
211
+ end
212
+
213
+ hash[param] = _to_hash(value)
214
+ end
215
+ hash
216
+ end
217
+
218
+ # Outputs non-array value in the form of hash
219
+ # For object, use to_hash. Otherwise, just return the value
220
+ # @param [Object] value Any valid value
221
+ # @return [Hash] Returns the value in the form of hash
222
+ def _to_hash(value)
223
+ if value.is_a?(Array)
224
+ value.compact.map { |v| _to_hash(v) }
225
+ elsif value.is_a?(Hash)
226
+ {}.tap do |hash|
227
+ value.each { |k, v| hash[k] = _to_hash(v) }
228
+ end
229
+ elsif value.respond_to? :to_hash
230
+ value.to_hash
231
+ else
232
+ value
233
+ end
234
+ end
235
+ end
236
+ end