azure_openai_client 0.0.1 → 0.0.2

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 (107) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +10 -0
  3. data/Gemfile.lock +76 -0
  4. data/README.md +50 -87
  5. data/Rakefile +10 -0
  6. data/azure_openai_client.gemspec +38 -0
  7. data/docs/ChatCompletionsCreate200Response.md +28 -0
  8. data/docs/ChatCompletionsCreate200ResponseChoicesInner.md +22 -0
  9. data/docs/ChatCompletionsCreate200ResponseChoicesInnerMessage.md +20 -0
  10. data/docs/ChatCompletionsCreate200ResponseUsage.md +22 -0
  11. data/docs/ChatCompletionsCreateRequest.md +38 -0
  12. data/docs/ChatCompletionsCreateRequestMessagesInner.md +22 -0
  13. data/docs/ChatCompletionsCreateRequestStop.md +49 -0
  14. data/docs/CompletionsCreate200Response.md +28 -0
  15. data/docs/CompletionsCreate200ResponseChoicesInner.md +24 -0
  16. data/docs/CompletionsCreate200ResponseChoicesInnerLogprobs.md +24 -0
  17. data/docs/CompletionsCreate200ResponseUsage.md +22 -0
  18. data/docs/CompletionsCreateRequest.md +52 -0
  19. data/docs/CompletionsCreateRequestPrompt.md +49 -0
  20. data/docs/CompletionsCreateRequestStop.md +49 -0
  21. data/docs/DefaultApi.md +238 -0
  22. data/docs/EmbeddingsCreate200Response.md +24 -0
  23. data/docs/EmbeddingsCreate200ResponseDataInner.md +22 -0
  24. data/docs/EmbeddingsCreate200ResponseUsage.md +20 -0
  25. data/docs/EmbeddingsCreateRequest.md +24 -0
  26. data/docs/EmbeddingsCreateRequestInput.md +49 -0
  27. data/docs/ErrorResponse.md +18 -0
  28. data/docs/ErrorResponseError.md +24 -0
  29. data/git_push.sh +57 -0
  30. data/inference.json +816 -0
  31. data/lib/azure_openai_client/api/default_api.rb +120 -93
  32. data/lib/azure_openai_client/api_client.rb +77 -75
  33. data/lib/azure_openai_client/api_error.rb +5 -5
  34. data/lib/azure_openai_client/configuration.rb +114 -22
  35. data/lib/azure_openai_client/models/{inline_response_200_2.rb → chat_completions_create200_response.rb} +34 -26
  36. data/lib/azure_openai_client/models/{inline_response_200_2_choices.rb → chat_completions_create200_response_choices_inner.rb} +28 -20
  37. data/lib/azure_openai_client/models/{inline_response_200_2_message.rb → chat_completions_create200_response_choices_inner_message.rb} +28 -20
  38. data/lib/azure_openai_client/models/{inline_response_200_2_usage.rb → chat_completions_create200_response_usage.rb} +28 -20
  39. data/lib/azure_openai_client/models/{chat_completions_body.rb → chat_completions_create_request.rb} +183 -37
  40. data/lib/azure_openai_client/models/{deploymentsdeploymentidchatcompletions_messages.rb → chat_completions_create_request_messages_inner.rb} +30 -22
  41. data/lib/azure_openai_client/models/chat_completions_create_request_stop.rb +105 -0
  42. data/lib/azure_openai_client/models/{inline_response_200.rb → completions_create200_response.rb} +34 -26
  43. data/lib/azure_openai_client/models/{inline_response_200_choices.rb → completions_create200_response_choices_inner.rb} +30 -22
  44. data/lib/azure_openai_client/models/{inline_response_200_logprobs.rb → completions_create200_response_choices_inner_logprobs.rb} +30 -22
  45. data/lib/azure_openai_client/models/{inline_response_200_usage.rb → completions_create200_response_usage.rb} +28 -20
  46. data/lib/azure_openai_client/models/{deploymentid_completions_body.rb → completions_create_request.rb} +58 -52
  47. data/lib/azure_openai_client/models/completions_create_request_prompt.rb +105 -0
  48. data/lib/azure_openai_client/models/completions_create_request_stop.rb +105 -0
  49. data/lib/azure_openai_client/models/{inline_response_200_1.rb → embeddings_create200_response.rb} +30 -22
  50. data/lib/azure_openai_client/models/{inline_response_200_1_data.rb → embeddings_create200_response_data_inner.rb} +28 -20
  51. data/lib/azure_openai_client/models/{inline_response_200_1_usage.rb → embeddings_create200_response_usage.rb} +26 -18
  52. data/lib/azure_openai_client/models/embeddings_create_request.rb +252 -0
  53. data/lib/azure_openai_client/models/embeddings_create_request_input.rb +105 -0
  54. data/lib/azure_openai_client/models/error_response.rb +21 -13
  55. data/lib/azure_openai_client/models/error_response_error.rb +27 -19
  56. data/lib/azure_openai_client/version.rb +5 -6
  57. data/lib/azure_openai_client.rb +23 -23
  58. data/openapi-codegen.sh +12 -0
  59. data/openapi_config.yaml +14 -0
  60. data/spec/api/default_api_spec.rb +21 -22
  61. data/spec/api_client_spec.rb +15 -16
  62. data/spec/configuration_spec.rb +3 -3
  63. data/spec/models/chat_completions_create200_response_choices_inner_message_spec.rb +44 -0
  64. data/spec/models/chat_completions_create200_response_choices_inner_spec.rb +46 -0
  65. data/spec/models/chat_completions_create200_response_spec.rb +64 -0
  66. data/spec/models/chat_completions_create200_response_usage_spec.rb +46 -0
  67. data/spec/models/chat_completions_create_request_messages_inner_spec.rb +50 -0
  68. data/spec/models/chat_completions_create_request_spec.rb +94 -0
  69. data/spec/models/chat_completions_create_request_stop_spec.rb +31 -0
  70. data/spec/models/completions_create200_response_choices_inner_logprobs_spec.rb +52 -0
  71. data/spec/models/completions_create200_response_choices_inner_spec.rb +52 -0
  72. data/spec/models/completions_create200_response_spec.rb +64 -0
  73. data/spec/models/completions_create200_response_usage_spec.rb +46 -0
  74. data/spec/models/completions_create_request_prompt_spec.rb +31 -0
  75. data/spec/models/completions_create_request_spec.rb +136 -0
  76. data/spec/models/completions_create_request_stop_spec.rb +31 -0
  77. data/spec/models/embeddings_create200_response_data_inner_spec.rb +46 -0
  78. data/spec/models/embeddings_create200_response_spec.rb +52 -0
  79. data/spec/models/embeddings_create200_response_usage_spec.rb +40 -0
  80. data/spec/models/embeddings_create_request_input_spec.rb +31 -0
  81. data/spec/models/embeddings_create_request_spec.rb +52 -0
  82. data/spec/models/error_response_error_spec.rb +12 -20
  83. data/spec/models/error_response_spec.rb +9 -17
  84. data/spec/spec_helper.rb +4 -5
  85. metadata +91 -77
  86. data/lib/azure_openai_client/models/deploymentid_embeddings_body.rb +0 -202
  87. data/lib/azure_openai_client/models/one_ofchat_completions_body_stop.rb +0 -198
  88. data/lib/azure_openai_client/models/one_ofdeploymentid_completions_body_prompt.rb +0 -198
  89. data/lib/azure_openai_client/models/one_ofdeploymentid_completions_body_stop.rb +0 -198
  90. data/spec/models/chat_completions_body_spec.rb +0 -102
  91. data/spec/models/deploymentid_completions_body_spec.rb +0 -144
  92. data/spec/models/deploymentid_embeddings_body_spec.rb +0 -36
  93. data/spec/models/deploymentsdeploymentidchatcompletions_messages_spec.rb +0 -58
  94. data/spec/models/inline_response_200_1_data_spec.rb +0 -54
  95. data/spec/models/inline_response_200_1_spec.rb +0 -60
  96. data/spec/models/inline_response_200_1_usage_spec.rb +0 -48
  97. data/spec/models/inline_response_200_2_choices_spec.rb +0 -54
  98. data/spec/models/inline_response_200_2_message_spec.rb +0 -52
  99. data/spec/models/inline_response_200_2_spec.rb +0 -72
  100. data/spec/models/inline_response_200_2_usage_spec.rb +0 -54
  101. data/spec/models/inline_response_200_choices_spec.rb +0 -60
  102. data/spec/models/inline_response_200_logprobs_spec.rb +0 -60
  103. data/spec/models/inline_response_200_spec.rb +0 -72
  104. data/spec/models/inline_response_200_usage_spec.rb +0 -54
  105. data/spec/models/one_ofchat_completions_body_stop_spec.rb +0 -36
  106. data/spec/models/one_ofdeploymentid_completions_body_prompt_spec.rb +0 -36
  107. data/spec/models/one_ofdeploymentid_completions_body_stop_spec.rb +0 -36
@@ -1,20 +1,20 @@
1
- # frozen_string_literal: true
2
-
3
1
  =begin
4
2
  #Azure OpenAI Service API
5
3
 
6
4
  #Azure OpenAI APIs for completions and search
7
5
 
8
- OpenAPI spec version: 2023-05-15
6
+ The version of the OpenAPI document: 2023-05-15
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 6.6.0
9
10
 
10
- Generated by: https://github.com/swagger-api/swagger-codegen.git
11
- Swagger Codegen version: 3.0.42
12
11
  =end
13
12
 
14
13
  require 'date'
14
+ require 'time'
15
15
 
16
16
  module AzureOpenaiClient
17
- class InlineResponse2002Usage
17
+ class ChatCompletionsCreate200ResponseUsage
18
18
  attr_accessor :prompt_tokens
19
19
 
20
20
  attr_accessor :completion_tokens
@@ -24,18 +24,23 @@ module AzureOpenaiClient
24
24
  # Attribute mapping from ruby-style variable name to JSON key.
25
25
  def self.attribute_map
26
26
  {
27
- 'prompt_tokens': :'prompt_tokens',
28
- 'completion_tokens': :'completion_tokens',
29
- 'total_tokens': :'total_tokens'
27
+ :'prompt_tokens' => :'prompt_tokens',
28
+ :'completion_tokens' => :'completion_tokens',
29
+ :'total_tokens' => :'total_tokens'
30
30
  }
31
31
  end
32
32
 
33
+ # Returns all the JSON keys this model knows about
34
+ def self.acceptable_attributes
35
+ attribute_map.values
36
+ end
37
+
33
38
  # Attribute type mapping.
34
39
  def self.openapi_types
35
40
  {
36
- 'prompt_tokens': :'Object',
37
- 'completion_tokens': :'Object',
38
- 'total_tokens': :'Object'
41
+ :'prompt_tokens' => :'Integer',
42
+ :'completion_tokens' => :'Integer',
43
+ :'total_tokens' => :'Integer'
39
44
  }
40
45
  end
41
46
 
@@ -49,13 +54,13 @@ module AzureOpenaiClient
49
54
  # @param [Hash] attributes Model attributes in the form of hash
50
55
  def initialize(attributes = {})
51
56
  if (!attributes.is_a?(Hash))
52
- fail ArgumentError, "The input argument (attributes) must be a hash in `AzureOpenaiClient::InlineResponse2002Usage` initialize method"
57
+ fail ArgumentError, "The input argument (attributes) must be a hash in `AzureOpenaiClient::ChatCompletionsCreate200ResponseUsage` initialize method"
53
58
  end
54
59
 
55
60
  # check to see if the attribute exists and convert string to symbol for hash key
56
61
  attributes = attributes.each_with_object({}) { |(k, v), h|
57
62
  if (!self.class.attribute_map.key?(k.to_sym))
58
- fail ArgumentError, "`#{k}` is not a valid attribute in `AzureOpenaiClient::InlineResponse2002Usage`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
63
+ fail ArgumentError, "`#{k}` is not a valid attribute in `AzureOpenaiClient::ChatCompletionsCreate200ResponseUsage`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
59
64
  end
60
65
  h[k.to_sym] = v
61
66
  }
@@ -135,8 +140,11 @@ module AzureOpenaiClient
135
140
  # @return [Object] Returns the model itself
136
141
  def build_from_hash(attributes)
137
142
  return nil unless attributes.is_a?(Hash)
143
+ attributes = attributes.transform_keys(&:to_sym)
138
144
  self.class.openapi_types.each_pair do |key, type|
139
- if type =~ /\AArray<(.*)>/i
145
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
146
+ self.send("#{key}=", nil)
147
+ elsif type =~ /\AArray<(.*)>/i
140
148
  # check to ensure the input is an array given that the attribute
141
149
  # is documented as an array but the input is not
142
150
  if attributes[self.class.attribute_map[key]].is_a?(Array)
@@ -144,8 +152,6 @@ module AzureOpenaiClient
144
152
  end
145
153
  elsif !attributes[self.class.attribute_map[key]].nil?
146
154
  self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
147
- elsif attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
148
- self.send("#{key}=", nil)
149
155
  end
150
156
  end
151
157
 
@@ -158,8 +164,8 @@ module AzureOpenaiClient
158
164
  # @return [Object] Deserialized data
159
165
  def _deserialize(type, value)
160
166
  case type.to_sym
161
- when :DateTime
162
- DateTime.parse(value)
167
+ when :Time
168
+ Time.parse(value)
163
169
  when :Date
164
170
  Date.parse(value)
165
171
  when :String
@@ -189,7 +195,9 @@ module AzureOpenaiClient
189
195
  end
190
196
  end
191
197
  else # model
192
- AzureOpenaiClient.const_get(type).build_from_hash(value)
198
+ # models (e.g. Pet) or oneOf
199
+ klass = AzureOpenaiClient.const_get(type)
200
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
193
201
  end
194
202
  end
195
203
 
@@ -1,20 +1,20 @@
1
- # frozen_string_literal: true
2
-
3
1
  =begin
4
2
  #Azure OpenAI Service API
5
3
 
6
4
  #Azure OpenAI APIs for completions and search
7
5
 
8
- OpenAPI spec version: 2023-05-15
6
+ The version of the OpenAPI document: 2023-05-15
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 6.6.0
9
10
 
10
- Generated by: https://github.com/swagger-api/swagger-codegen.git
11
- Swagger Codegen version: 3.0.42
12
11
  =end
13
12
 
14
13
  require 'date'
14
+ require 'time'
15
15
 
16
16
  module AzureOpenaiClient
17
- class ChatCompletionsBody
17
+ class ChatCompletionsCreateRequest
18
18
  # The messages to generate chat completions for, in the chat format.
19
19
  attr_accessor :messages
20
20
 
@@ -30,7 +30,6 @@ module AzureOpenaiClient
30
30
  # If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a `data: [DONE]` message.
31
31
  attr_accessor :stream
32
32
 
33
- # Up to 4 sequences where the API will stop generating further tokens.
34
33
  attr_accessor :stop
35
34
 
36
35
  # The maximum number of tokens allowed for the generated answer. By default, the number of tokens the model can return will be (4096 - prompt tokens).
@@ -51,34 +50,39 @@ module AzureOpenaiClient
51
50
  # Attribute mapping from ruby-style variable name to JSON key.
52
51
  def self.attribute_map
53
52
  {
54
- 'messages': :'messages',
55
- 'temperature': :'temperature',
56
- 'top_p': :'top_p',
57
- 'n': :'n',
58
- 'stream': :'stream',
59
- 'stop': :'stop',
60
- 'max_tokens': :'max_tokens',
61
- 'presence_penalty': :'presence_penalty',
62
- 'frequency_penalty': :'frequency_penalty',
63
- 'logit_bias': :'logit_bias',
64
- 'user': :'user'
53
+ :'messages' => :'messages',
54
+ :'temperature' => :'temperature',
55
+ :'top_p' => :'top_p',
56
+ :'n' => :'n',
57
+ :'stream' => :'stream',
58
+ :'stop' => :'stop',
59
+ :'max_tokens' => :'max_tokens',
60
+ :'presence_penalty' => :'presence_penalty',
61
+ :'frequency_penalty' => :'frequency_penalty',
62
+ :'logit_bias' => :'logit_bias',
63
+ :'user' => :'user'
65
64
  }
66
65
  end
67
66
 
67
+ # Returns all the JSON keys this model knows about
68
+ def self.acceptable_attributes
69
+ attribute_map.values
70
+ end
71
+
68
72
  # Attribute type mapping.
69
73
  def self.openapi_types
70
74
  {
71
- 'messages': :'Object',
72
- 'temperature': :'Object',
73
- 'top_p': :'Object',
74
- 'n': :'Object',
75
- 'stream': :'Object',
76
- 'stop': :'Object',
77
- 'max_tokens': :'Object',
78
- 'presence_penalty': :'Object',
79
- 'frequency_penalty': :'Object',
80
- 'logit_bias': :'Object',
81
- 'user': :'Object'
75
+ :'messages' => :'Array<ChatCompletionsCreateRequestMessagesInner>',
76
+ :'temperature' => :'Float',
77
+ :'top_p' => :'Float',
78
+ :'n' => :'Integer',
79
+ :'stream' => :'Boolean',
80
+ :'stop' => :'ChatCompletionsCreateRequestStop',
81
+ :'max_tokens' => :'Integer',
82
+ :'presence_penalty' => :'Float',
83
+ :'frequency_penalty' => :'Float',
84
+ :'logit_bias' => :'Object',
85
+ :'user' => :'String'
82
86
  }
83
87
  end
84
88
 
@@ -97,13 +101,13 @@ module AzureOpenaiClient
97
101
  # @param [Hash] attributes Model attributes in the form of hash
98
102
  def initialize(attributes = {})
99
103
  if (!attributes.is_a?(Hash))
100
- fail ArgumentError, "The input argument (attributes) must be a hash in `AzureOpenaiClient::ChatCompletionsBody` initialize method"
104
+ fail ArgumentError, "The input argument (attributes) must be a hash in `AzureOpenaiClient::ChatCompletionsCreateRequest` initialize method"
101
105
  end
102
106
 
103
107
  # check to see if the attribute exists and convert string to symbol for hash key
104
108
  attributes = attributes.each_with_object({}) { |(k, v), h|
105
109
  if (!self.class.attribute_map.key?(k.to_sym))
106
- fail ArgumentError, "`#{k}` is not a valid attribute in `AzureOpenaiClient::ChatCompletionsBody`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
110
+ fail ArgumentError, "`#{k}` is not a valid attribute in `AzureOpenaiClient::ChatCompletionsCreateRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
107
111
  end
108
112
  h[k.to_sym] = v
109
113
  }
@@ -175,6 +179,50 @@ module AzureOpenaiClient
175
179
  invalid_properties.push('invalid value for "messages", messages cannot be nil.')
176
180
  end
177
181
 
182
+ if @messages.length < 1
183
+ invalid_properties.push('invalid value for "messages", number of items must be greater than or equal to 1.')
184
+ end
185
+
186
+ if !@temperature.nil? && @temperature > 2
187
+ invalid_properties.push('invalid value for "temperature", must be smaller than or equal to 2.')
188
+ end
189
+
190
+ if !@temperature.nil? && @temperature < 0
191
+ invalid_properties.push('invalid value for "temperature", must be greater than or equal to 0.')
192
+ end
193
+
194
+ if !@top_p.nil? && @top_p > 1
195
+ invalid_properties.push('invalid value for "top_p", must be smaller than or equal to 1.')
196
+ end
197
+
198
+ if !@top_p.nil? && @top_p < 0
199
+ invalid_properties.push('invalid value for "top_p", must be greater than or equal to 0.')
200
+ end
201
+
202
+ if !@n.nil? && @n > 128
203
+ invalid_properties.push('invalid value for "n", must be smaller than or equal to 128.')
204
+ end
205
+
206
+ if !@n.nil? && @n < 1
207
+ invalid_properties.push('invalid value for "n", must be greater than or equal to 1.')
208
+ end
209
+
210
+ if !@presence_penalty.nil? && @presence_penalty > 2
211
+ invalid_properties.push('invalid value for "presence_penalty", must be smaller than or equal to 2.')
212
+ end
213
+
214
+ if !@presence_penalty.nil? && @presence_penalty < -2
215
+ invalid_properties.push('invalid value for "presence_penalty", must be greater than or equal to -2.')
216
+ end
217
+
218
+ if !@frequency_penalty.nil? && @frequency_penalty > 2
219
+ invalid_properties.push('invalid value for "frequency_penalty", must be smaller than or equal to 2.')
220
+ end
221
+
222
+ if !@frequency_penalty.nil? && @frequency_penalty < -2
223
+ invalid_properties.push('invalid value for "frequency_penalty", must be greater than or equal to -2.')
224
+ end
225
+
178
226
  invalid_properties
179
227
  end
180
228
 
@@ -182,9 +230,104 @@ module AzureOpenaiClient
182
230
  # @return true if the model is valid
183
231
  def valid?
184
232
  return false if @messages.nil?
233
+ return false if @messages.length < 1
234
+ return false if !@temperature.nil? && @temperature > 2
235
+ return false if !@temperature.nil? && @temperature < 0
236
+ return false if !@top_p.nil? && @top_p > 1
237
+ return false if !@top_p.nil? && @top_p < 0
238
+ return false if !@n.nil? && @n > 128
239
+ return false if !@n.nil? && @n < 1
240
+ return false if !@presence_penalty.nil? && @presence_penalty > 2
241
+ return false if !@presence_penalty.nil? && @presence_penalty < -2
242
+ return false if !@frequency_penalty.nil? && @frequency_penalty > 2
243
+ return false if !@frequency_penalty.nil? && @frequency_penalty < -2
185
244
  true
186
245
  end
187
246
 
247
+ # Custom attribute writer method with validation
248
+ # @param [Object] messages Value to be assigned
249
+ def messages=(messages)
250
+ if messages.nil?
251
+ fail ArgumentError, 'messages cannot be nil'
252
+ end
253
+
254
+ if messages.length < 1
255
+ fail ArgumentError, 'invalid value for "messages", number of items must be greater than or equal to 1.'
256
+ end
257
+
258
+ @messages = messages
259
+ end
260
+
261
+ # Custom attribute writer method with validation
262
+ # @param [Object] temperature Value to be assigned
263
+ def temperature=(temperature)
264
+ if !temperature.nil? && temperature > 2
265
+ fail ArgumentError, 'invalid value for "temperature", must be smaller than or equal to 2.'
266
+ end
267
+
268
+ if !temperature.nil? && temperature < 0
269
+ fail ArgumentError, 'invalid value for "temperature", must be greater than or equal to 0.'
270
+ end
271
+
272
+ @temperature = temperature
273
+ end
274
+
275
+ # Custom attribute writer method with validation
276
+ # @param [Object] top_p Value to be assigned
277
+ def top_p=(top_p)
278
+ if !top_p.nil? && top_p > 1
279
+ fail ArgumentError, 'invalid value for "top_p", must be smaller than or equal to 1.'
280
+ end
281
+
282
+ if !top_p.nil? && top_p < 0
283
+ fail ArgumentError, 'invalid value for "top_p", must be greater than or equal to 0.'
284
+ end
285
+
286
+ @top_p = top_p
287
+ end
288
+
289
+ # Custom attribute writer method with validation
290
+ # @param [Object] n Value to be assigned
291
+ def n=(n)
292
+ if !n.nil? && n > 128
293
+ fail ArgumentError, 'invalid value for "n", must be smaller than or equal to 128.'
294
+ end
295
+
296
+ if !n.nil? && n < 1
297
+ fail ArgumentError, 'invalid value for "n", must be greater than or equal to 1.'
298
+ end
299
+
300
+ @n = n
301
+ end
302
+
303
+ # Custom attribute writer method with validation
304
+ # @param [Object] presence_penalty Value to be assigned
305
+ def presence_penalty=(presence_penalty)
306
+ if !presence_penalty.nil? && presence_penalty > 2
307
+ fail ArgumentError, 'invalid value for "presence_penalty", must be smaller than or equal to 2.'
308
+ end
309
+
310
+ if !presence_penalty.nil? && presence_penalty < -2
311
+ fail ArgumentError, 'invalid value for "presence_penalty", must be greater than or equal to -2.'
312
+ end
313
+
314
+ @presence_penalty = presence_penalty
315
+ end
316
+
317
+ # Custom attribute writer method with validation
318
+ # @param [Object] frequency_penalty Value to be assigned
319
+ def frequency_penalty=(frequency_penalty)
320
+ if !frequency_penalty.nil? && frequency_penalty > 2
321
+ fail ArgumentError, 'invalid value for "frequency_penalty", must be smaller than or equal to 2.'
322
+ end
323
+
324
+ if !frequency_penalty.nil? && frequency_penalty < -2
325
+ fail ArgumentError, 'invalid value for "frequency_penalty", must be greater than or equal to -2.'
326
+ end
327
+
328
+ @frequency_penalty = frequency_penalty
329
+ end
330
+
188
331
  # Checks equality by comparing each attribute.
189
332
  # @param [Object] Object to be compared
190
333
  def ==(o)
@@ -227,8 +370,11 @@ module AzureOpenaiClient
227
370
  # @return [Object] Returns the model itself
228
371
  def build_from_hash(attributes)
229
372
  return nil unless attributes.is_a?(Hash)
373
+ attributes = attributes.transform_keys(&:to_sym)
230
374
  self.class.openapi_types.each_pair do |key, type|
231
- if type =~ /\AArray<(.*)>/i
375
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
376
+ self.send("#{key}=", nil)
377
+ elsif type =~ /\AArray<(.*)>/i
232
378
  # check to ensure the input is an array given that the attribute
233
379
  # is documented as an array but the input is not
234
380
  if attributes[self.class.attribute_map[key]].is_a?(Array)
@@ -236,8 +382,6 @@ module AzureOpenaiClient
236
382
  end
237
383
  elsif !attributes[self.class.attribute_map[key]].nil?
238
384
  self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
239
- elsif attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
240
- self.send("#{key}=", nil)
241
385
  end
242
386
  end
243
387
 
@@ -250,8 +394,8 @@ module AzureOpenaiClient
250
394
  # @return [Object] Deserialized data
251
395
  def _deserialize(type, value)
252
396
  case type.to_sym
253
- when :DateTime
254
- DateTime.parse(value)
397
+ when :Time
398
+ Time.parse(value)
255
399
  when :Date
256
400
  Date.parse(value)
257
401
  when :String
@@ -281,7 +425,9 @@ module AzureOpenaiClient
281
425
  end
282
426
  end
283
427
  else # model
284
- AzureOpenaiClient.const_get(type).build_from_hash(value)
428
+ # models (e.g. Pet) or oneOf
429
+ klass = AzureOpenaiClient.const_get(type)
430
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
285
431
  end
286
432
  end
287
433
 
@@ -1,20 +1,20 @@
1
- # frozen_string_literal: true
2
-
3
1
  =begin
4
2
  #Azure OpenAI Service API
5
3
 
6
4
  #Azure OpenAI APIs for completions and search
7
5
 
8
- OpenAPI spec version: 2023-05-15
6
+ The version of the OpenAPI document: 2023-05-15
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 6.6.0
9
10
 
10
- Generated by: https://github.com/swagger-api/swagger-codegen.git
11
- Swagger Codegen version: 3.0.42
12
11
  =end
13
12
 
14
13
  require 'date'
14
+ require 'time'
15
15
 
16
16
  module AzureOpenaiClient
17
- class DeploymentsdeploymentidchatcompletionsMessages
17
+ class ChatCompletionsCreateRequestMessagesInner
18
18
  # The role of the author of this message.
19
19
  attr_accessor :role
20
20
 
@@ -49,18 +49,23 @@ module AzureOpenaiClient
49
49
  # Attribute mapping from ruby-style variable name to JSON key.
50
50
  def self.attribute_map
51
51
  {
52
- 'role': :'role',
53
- 'content': :'content',
54
- 'name': :'name'
52
+ :'role' => :'role',
53
+ :'content' => :'content',
54
+ :'name' => :'name'
55
55
  }
56
56
  end
57
57
 
58
+ # Returns all the JSON keys this model knows about
59
+ def self.acceptable_attributes
60
+ attribute_map.values
61
+ end
62
+
58
63
  # Attribute type mapping.
59
64
  def self.openapi_types
60
65
  {
61
- 'role': :'Object',
62
- 'content': :'Object',
63
- 'name': :'Object'
66
+ :'role' => :'String',
67
+ :'content' => :'String',
68
+ :'name' => :'String'
64
69
  }
65
70
  end
66
71
 
@@ -74,13 +79,13 @@ module AzureOpenaiClient
74
79
  # @param [Hash] attributes Model attributes in the form of hash
75
80
  def initialize(attributes = {})
76
81
  if (!attributes.is_a?(Hash))
77
- fail ArgumentError, "The input argument (attributes) must be a hash in `AzureOpenaiClient::DeploymentsdeploymentidchatcompletionsMessages` initialize method"
82
+ fail ArgumentError, "The input argument (attributes) must be a hash in `AzureOpenaiClient::ChatCompletionsCreateRequestMessagesInner` initialize method"
78
83
  end
79
84
 
80
85
  # check to see if the attribute exists and convert string to symbol for hash key
81
86
  attributes = attributes.each_with_object({}) { |(k, v), h|
82
87
  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
88
+ fail ArgumentError, "`#{k}` is not a valid attribute in `AzureOpenaiClient::ChatCompletionsCreateRequestMessagesInner`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
84
89
  end
85
90
  h[k.to_sym] = v
86
91
  }
@@ -117,7 +122,7 @@ module AzureOpenaiClient
117
122
  # @return true if the model is valid
118
123
  def valid?
119
124
  return false if @role.nil?
120
- role_validator = EnumAttributeValidator.new('Object', ['system', 'user', 'assistant'])
125
+ role_validator = EnumAttributeValidator.new('String', ["system", "user", "assistant"])
121
126
  return false unless role_validator.valid?(@role)
122
127
  return false if @content.nil?
123
128
  true
@@ -126,7 +131,7 @@ module AzureOpenaiClient
126
131
  # Custom attribute writer method checking allowed values (enum).
127
132
  # @param [Object] role Object to be assigned
128
133
  def role=(role)
129
- validator = EnumAttributeValidator.new('Object', ['system', 'user', 'assistant'])
134
+ validator = EnumAttributeValidator.new('String', ["system", "user", "assistant"])
130
135
  unless validator.valid?(role)
131
136
  fail ArgumentError, "invalid value for \"role\", must be one of #{validator.allowable_values}."
132
137
  end
@@ -167,8 +172,11 @@ module AzureOpenaiClient
167
172
  # @return [Object] Returns the model itself
168
173
  def build_from_hash(attributes)
169
174
  return nil unless attributes.is_a?(Hash)
175
+ attributes = attributes.transform_keys(&:to_sym)
170
176
  self.class.openapi_types.each_pair do |key, type|
171
- if type =~ /\AArray<(.*)>/i
177
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
178
+ self.send("#{key}=", nil)
179
+ elsif type =~ /\AArray<(.*)>/i
172
180
  # check to ensure the input is an array given that the attribute
173
181
  # is documented as an array but the input is not
174
182
  if attributes[self.class.attribute_map[key]].is_a?(Array)
@@ -176,8 +184,6 @@ module AzureOpenaiClient
176
184
  end
177
185
  elsif !attributes[self.class.attribute_map[key]].nil?
178
186
  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
187
  end
182
188
  end
183
189
 
@@ -190,8 +196,8 @@ module AzureOpenaiClient
190
196
  # @return [Object] Deserialized data
191
197
  def _deserialize(type, value)
192
198
  case type.to_sym
193
- when :DateTime
194
- DateTime.parse(value)
199
+ when :Time
200
+ Time.parse(value)
195
201
  when :Date
196
202
  Date.parse(value)
197
203
  when :String
@@ -221,7 +227,9 @@ module AzureOpenaiClient
221
227
  end
222
228
  end
223
229
  else # model
224
- AzureOpenaiClient.const_get(type).build_from_hash(value)
230
+ # models (e.g. Pet) or oneOf
231
+ klass = AzureOpenaiClient.const_get(type)
232
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
225
233
  end
226
234
  end
227
235
 
@@ -0,0 +1,105 @@
1
+ =begin
2
+ #Azure OpenAI Service API
3
+
4
+ #Azure OpenAI APIs for completions and search
5
+
6
+ The version of the OpenAPI document: 2023-05-15
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 6.6.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module AzureOpenaiClient
17
+ # Up to 4 sequences where the API will stop generating further tokens.
18
+ module ChatCompletionsCreateRequestStop
19
+ class << self
20
+ # List of class defined in oneOf (OpenAPI v3)
21
+ def openapi_one_of
22
+ [
23
+ :'Array<String>',
24
+ :'String'
25
+ ]
26
+ end
27
+
28
+ # Builds the object
29
+ # @param [Mixed] Data to be matched against the list of oneOf items
30
+ # @return [Object] Returns the model or the data itself
31
+ def build(data)
32
+ # Go through the list of oneOf items and attempt to identify the appropriate one.
33
+ # Note:
34
+ # - We do not attempt to check whether exactly one item matches.
35
+ # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
36
+ # due to the way the deserialization is made in the base_object template (it just casts without verifying).
37
+ # - TODO: scalar values are de facto behaving as if they were nullable.
38
+ # - TODO: logging when debugging is set.
39
+ openapi_one_of.each do |klass|
40
+ begin
41
+ next if klass == :AnyType # "nullable: true"
42
+ typed_data = find_and_cast_into_type(klass, data)
43
+ return typed_data if typed_data
44
+ rescue # rescue all errors so we keep iterating even if the current item lookup raises
45
+ end
46
+ end
47
+
48
+ openapi_one_of.include?(:AnyType) ? data : nil
49
+ end
50
+
51
+ private
52
+
53
+ SchemaMismatchError = Class.new(StandardError)
54
+
55
+ # Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
56
+ def find_and_cast_into_type(klass, data)
57
+ return if data.nil?
58
+
59
+ case klass.to_s
60
+ when 'Boolean'
61
+ return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
62
+ when 'Float'
63
+ return data if data.instance_of?(Float)
64
+ when 'Integer'
65
+ return data if data.instance_of?(Integer)
66
+ when 'Time'
67
+ return Time.parse(data)
68
+ when 'Date'
69
+ return Date.parse(data)
70
+ when 'String'
71
+ return data if data.instance_of?(String)
72
+ when 'Object' # "type: object"
73
+ return data if data.instance_of?(Hash)
74
+ when /\AArray<(?<sub_type>.+)>\z/ # "type: array"
75
+ if data.instance_of?(Array)
76
+ sub_type = Regexp.last_match[:sub_type]
77
+ return data.map { |item| find_and_cast_into_type(sub_type, item) }
78
+ end
79
+ when /\AHash<String, (?<sub_type>.+)>\z/ # "type: object" with "additionalProperties: { ... }"
80
+ if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
81
+ sub_type = Regexp.last_match[:sub_type]
82
+ return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
83
+ end
84
+ else # model
85
+ const = AzureOpenaiClient.const_get(klass)
86
+ if const
87
+ if const.respond_to?(:openapi_one_of) # nested oneOf model
88
+ model = const.build(data)
89
+ return model if model
90
+ else
91
+ # raise if data contains keys that are not known to the model
92
+ raise unless (data.keys - const.acceptable_attributes).empty?
93
+ model = const.build_from_hash(data)
94
+ return model if model && model.valid?
95
+ end
96
+ end
97
+ end
98
+
99
+ raise # if no match by now, raise
100
+ rescue
101
+ raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
102
+ end
103
+ end
104
+ end
105
+ end