openapi_openai 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (206) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/Gemfile.lock +72 -0
  4. data/README.md +171 -0
  5. data/Rakefile +10 -0
  6. data/bin/bundle +109 -0
  7. data/bin/byebug +27 -0
  8. data/bin/coderay +27 -0
  9. data/bin/htmldiff +27 -0
  10. data/bin/ldiff +27 -0
  11. data/bin/pry +27 -0
  12. data/bin/racc +27 -0
  13. data/bin/rake +27 -0
  14. data/bin/rspec +27 -0
  15. data/bin/rubocop +27 -0
  16. data/bin/ruby-parse +27 -0
  17. data/bin/ruby-rewrite +27 -0
  18. data/docs/ChatCompletionFunctions.md +22 -0
  19. data/docs/ChatCompletionRequestMessage.md +24 -0
  20. data/docs/ChatCompletionRequestMessageFunctionCall.md +20 -0
  21. data/docs/ChatCompletionResponseMessage.md +22 -0
  22. data/docs/ChatCompletionStreamResponseDelta.md +22 -0
  23. data/docs/CreateChatCompletionRequest.md +44 -0
  24. data/docs/CreateChatCompletionRequestFunctionCall.md +49 -0
  25. data/docs/CreateChatCompletionRequestFunctionCallOneOf.md +18 -0
  26. data/docs/CreateChatCompletionRequestModel.md +47 -0
  27. data/docs/CreateChatCompletionRequestStop.md +49 -0
  28. data/docs/CreateChatCompletionResponse.md +28 -0
  29. data/docs/CreateChatCompletionResponseChoicesInner.md +22 -0
  30. data/docs/CreateChatCompletionStreamResponse.md +26 -0
  31. data/docs/CreateChatCompletionStreamResponseChoicesInner.md +22 -0
  32. data/docs/CreateCompletionRequest.md +48 -0
  33. data/docs/CreateCompletionRequestModel.md +47 -0
  34. data/docs/CreateCompletionRequestPrompt.md +53 -0
  35. data/docs/CreateCompletionRequestStop.md +49 -0
  36. data/docs/CreateCompletionResponse.md +28 -0
  37. data/docs/CreateCompletionResponseChoicesInner.md +24 -0
  38. data/docs/CreateCompletionResponseChoicesInnerLogprobs.md +24 -0
  39. data/docs/CreateCompletionResponseUsage.md +22 -0
  40. data/docs/CreateEditRequest.md +28 -0
  41. data/docs/CreateEditRequestModel.md +47 -0
  42. data/docs/CreateEditResponse.md +24 -0
  43. data/docs/CreateEditResponseChoicesInner.md +24 -0
  44. data/docs/CreateEmbeddingRequest.md +22 -0
  45. data/docs/CreateEmbeddingRequestInput.md +53 -0
  46. data/docs/CreateEmbeddingRequestModel.md +47 -0
  47. data/docs/CreateEmbeddingResponse.md +24 -0
  48. data/docs/CreateEmbeddingResponseDataInner.md +22 -0
  49. data/docs/CreateEmbeddingResponseUsage.md +20 -0
  50. data/docs/CreateFineTuneRequest.md +40 -0
  51. data/docs/CreateFineTuneRequestModel.md +47 -0
  52. data/docs/CreateImageRequest.md +26 -0
  53. data/docs/CreateModerationRequest.md +20 -0
  54. data/docs/CreateModerationRequestInput.md +49 -0
  55. data/docs/CreateModerationRequestModel.md +47 -0
  56. data/docs/CreateModerationResponse.md +22 -0
  57. data/docs/CreateModerationResponseResultsInner.md +22 -0
  58. data/docs/CreateModerationResponseResultsInnerCategories.md +30 -0
  59. data/docs/CreateModerationResponseResultsInnerCategoryScores.md +30 -0
  60. data/docs/CreateTranscriptionRequestModel.md +47 -0
  61. data/docs/CreateTranscriptionResponse.md +18 -0
  62. data/docs/CreateTranslationResponse.md +18 -0
  63. data/docs/DeleteFileResponse.md +22 -0
  64. data/docs/DeleteModelResponse.md +22 -0
  65. data/docs/Error.md +24 -0
  66. data/docs/ErrorResponse.md +18 -0
  67. data/docs/FineTune.md +42 -0
  68. data/docs/FineTuneEvent.md +24 -0
  69. data/docs/ImagesResponse.md +20 -0
  70. data/docs/ImagesResponseDataInner.md +20 -0
  71. data/docs/ListFilesResponse.md +20 -0
  72. data/docs/ListFineTuneEventsResponse.md +20 -0
  73. data/docs/ListFineTunesResponse.md +20 -0
  74. data/docs/ListModelsResponse.md +20 -0
  75. data/docs/Model.md +24 -0
  76. data/docs/OpenAIApi.md +1499 -0
  77. data/docs/OpenAIFile.md +32 -0
  78. data/git_push.sh +57 -0
  79. data/lib/openapi_openai/api/open_ai_api.rb +1583 -0
  80. data/lib/openapi_openai/api_client.rb +393 -0
  81. data/lib/openapi_openai/api_error.rb +58 -0
  82. data/lib/openapi_openai/configuration.rb +291 -0
  83. data/lib/openapi_openai/models/chat_completion_functions.rb +244 -0
  84. data/lib/openapi_openai/models/chat_completion_request_message.rb +285 -0
  85. data/lib/openapi_openai/models/chat_completion_request_message_function_call.rb +226 -0
  86. data/lib/openapi_openai/models/chat_completion_response_message.rb +276 -0
  87. data/lib/openapi_openai/models/chat_completion_stream_response_delta.rb +269 -0
  88. data/lib/openapi_openai/models/create_chat_completion_request.rb +537 -0
  89. data/lib/openapi_openai/models/create_chat_completion_request_function_call.rb +106 -0
  90. data/lib/openapi_openai/models/create_chat_completion_request_function_call_one_of.rb +222 -0
  91. data/lib/openapi_openai/models/create_chat_completion_request_model.rb +105 -0
  92. data/lib/openapi_openai/models/create_chat_completion_request_stop.rb +106 -0
  93. data/lib/openapi_openai/models/create_chat_completion_response.rb +296 -0
  94. data/lib/openapi_openai/models/create_chat_completion_response_choices_inner.rb +266 -0
  95. data/lib/openapi_openai/models/create_chat_completion_stream_response.rb +287 -0
  96. data/lib/openapi_openai/models/create_chat_completion_stream_response_choices_inner.rb +266 -0
  97. data/lib/openapi_openai/models/create_completion_request.rb +586 -0
  98. data/lib/openapi_openai/models/create_completion_request_model.rb +105 -0
  99. data/lib/openapi_openai/models/create_completion_request_prompt.rb +108 -0
  100. data/lib/openapi_openai/models/create_completion_request_stop.rb +106 -0
  101. data/lib/openapi_openai/models/create_completion_response.rb +296 -0
  102. data/lib/openapi_openai/models/create_completion_response_choices_inner.rb +299 -0
  103. data/lib/openapi_openai/models/create_completion_response_choices_inner_logprobs.rb +249 -0
  104. data/lib/openapi_openai/models/create_completion_response_usage.rb +253 -0
  105. data/lib/openapi_openai/models/create_edit_request.rb +362 -0
  106. data/lib/openapi_openai/models/create_edit_request_model.rb +105 -0
  107. data/lib/openapi_openai/models/create_edit_response.rb +271 -0
  108. data/lib/openapi_openai/models/create_edit_response_choices_inner.rb +276 -0
  109. data/lib/openapi_openai/models/create_embedding_request.rb +247 -0
  110. data/lib/openapi_openai/models/create_embedding_request_input.rb +108 -0
  111. data/lib/openapi_openai/models/create_embedding_request_model.rb +105 -0
  112. data/lib/openapi_openai/models/create_embedding_response.rb +271 -0
  113. data/lib/openapi_openai/models/create_embedding_response_data_inner.rb +255 -0
  114. data/lib/openapi_openai/models/create_embedding_response_usage.rb +237 -0
  115. data/lib/openapi_openai/models/create_fine_tune_request.rb +374 -0
  116. data/lib/openapi_openai/models/create_fine_tune_request_model.rb +105 -0
  117. data/lib/openapi_openai/models/create_image_request.rb +341 -0
  118. data/lib/openapi_openai/models/create_moderation_request.rb +230 -0
  119. data/lib/openapi_openai/models/create_moderation_request_input.rb +106 -0
  120. data/lib/openapi_openai/models/create_moderation_request_model.rb +105 -0
  121. data/lib/openapi_openai/models/create_moderation_response.rb +255 -0
  122. data/lib/openapi_openai/models/create_moderation_response_results_inner.rb +253 -0
  123. data/lib/openapi_openai/models/create_moderation_response_results_inner_categories.rb +317 -0
  124. data/lib/openapi_openai/models/create_moderation_response_results_inner_category_scores.rb +317 -0
  125. data/lib/openapi_openai/models/create_transcription_request_model.rb +105 -0
  126. data/lib/openapi_openai/models/create_transcription_response.rb +221 -0
  127. data/lib/openapi_openai/models/create_translation_response.rb +221 -0
  128. data/lib/openapi_openai/models/delete_file_response.rb +253 -0
  129. data/lib/openapi_openai/models/delete_model_response.rb +253 -0
  130. data/lib/openapi_openai/models/error.rb +261 -0
  131. data/lib/openapi_openai/models/error_response.rb +221 -0
  132. data/lib/openapi_openai/models/fine_tune.rb +410 -0
  133. data/lib/openapi_openai/models/fine_tune_event.rb +269 -0
  134. data/lib/openapi_openai/models/images_response.rb +239 -0
  135. data/lib/openapi_openai/models/images_response_data_inner.rb +223 -0
  136. data/lib/openapi_openai/models/list_files_response.rb +239 -0
  137. data/lib/openapi_openai/models/list_fine_tune_events_response.rb +239 -0
  138. data/lib/openapi_openai/models/list_fine_tunes_response.rb +239 -0
  139. data/lib/openapi_openai/models/list_models_response.rb +239 -0
  140. data/lib/openapi_openai/models/model.rb +269 -0
  141. data/lib/openapi_openai/models/open_ai_file.rb +320 -0
  142. data/lib/openapi_openai/version.rb +15 -0
  143. data/lib/openapi_openai.rb +99 -0
  144. data/openapi_openai.gemspec +39 -0
  145. data/spec/api/open_ai_api_spec.rb +306 -0
  146. data/spec/models/chat_completion_functions_spec.rb +48 -0
  147. data/spec/models/chat_completion_request_message_function_call_spec.rb +42 -0
  148. data/spec/models/chat_completion_request_message_spec.rb +58 -0
  149. data/spec/models/chat_completion_response_message_spec.rb +52 -0
  150. data/spec/models/chat_completion_stream_response_delta_spec.rb +52 -0
  151. data/spec/models/create_chat_completion_request_function_call_one_of_spec.rb +36 -0
  152. data/spec/models/create_chat_completion_request_function_call_spec.rb +32 -0
  153. data/spec/models/create_chat_completion_request_model_spec.rb +32 -0
  154. data/spec/models/create_chat_completion_request_spec.rb +114 -0
  155. data/spec/models/create_chat_completion_request_stop_spec.rb +32 -0
  156. data/spec/models/create_chat_completion_response_choices_inner_spec.rb +52 -0
  157. data/spec/models/create_chat_completion_response_spec.rb +66 -0
  158. data/spec/models/create_chat_completion_stream_response_choices_inner_spec.rb +52 -0
  159. data/spec/models/create_chat_completion_stream_response_spec.rb +60 -0
  160. data/spec/models/create_completion_request_model_spec.rb +32 -0
  161. data/spec/models/create_completion_request_prompt_spec.rb +32 -0
  162. data/spec/models/create_completion_request_spec.rb +126 -0
  163. data/spec/models/create_completion_request_stop_spec.rb +32 -0
  164. data/spec/models/create_completion_response_choices_inner_logprobs_spec.rb +54 -0
  165. data/spec/models/create_completion_response_choices_inner_spec.rb +58 -0
  166. data/spec/models/create_completion_response_spec.rb +66 -0
  167. data/spec/models/create_completion_response_usage_spec.rb +48 -0
  168. data/spec/models/create_edit_request_model_spec.rb +32 -0
  169. data/spec/models/create_edit_request_spec.rb +66 -0
  170. data/spec/models/create_edit_response_choices_inner_spec.rb +58 -0
  171. data/spec/models/create_edit_response_spec.rb +54 -0
  172. data/spec/models/create_embedding_request_input_spec.rb +32 -0
  173. data/spec/models/create_embedding_request_model_spec.rb +32 -0
  174. data/spec/models/create_embedding_request_spec.rb +48 -0
  175. data/spec/models/create_embedding_response_data_inner_spec.rb +48 -0
  176. data/spec/models/create_embedding_response_spec.rb +54 -0
  177. data/spec/models/create_embedding_response_usage_spec.rb +42 -0
  178. data/spec/models/create_fine_tune_request_model_spec.rb +32 -0
  179. data/spec/models/create_fine_tune_request_spec.rb +102 -0
  180. data/spec/models/create_image_request_spec.rb +68 -0
  181. data/spec/models/create_moderation_request_input_spec.rb +32 -0
  182. data/spec/models/create_moderation_request_model_spec.rb +32 -0
  183. data/spec/models/create_moderation_request_spec.rb +42 -0
  184. data/spec/models/create_moderation_response_results_inner_categories_spec.rb +72 -0
  185. data/spec/models/create_moderation_response_results_inner_category_scores_spec.rb +72 -0
  186. data/spec/models/create_moderation_response_results_inner_spec.rb +48 -0
  187. data/spec/models/create_moderation_response_spec.rb +48 -0
  188. data/spec/models/create_transcription_request_model_spec.rb +32 -0
  189. data/spec/models/create_transcription_response_spec.rb +36 -0
  190. data/spec/models/create_translation_response_spec.rb +36 -0
  191. data/spec/models/delete_file_response_spec.rb +48 -0
  192. data/spec/models/delete_model_response_spec.rb +48 -0
  193. data/spec/models/error_response_spec.rb +36 -0
  194. data/spec/models/error_spec.rb +54 -0
  195. data/spec/models/fine_tune_event_spec.rb +54 -0
  196. data/spec/models/fine_tune_spec.rb +108 -0
  197. data/spec/models/images_response_data_inner_spec.rb +42 -0
  198. data/spec/models/images_response_spec.rb +42 -0
  199. data/spec/models/list_files_response_spec.rb +42 -0
  200. data/spec/models/list_fine_tune_events_response_spec.rb +42 -0
  201. data/spec/models/list_fine_tunes_response_spec.rb +42 -0
  202. data/spec/models/list_models_response_spec.rb +42 -0
  203. data/spec/models/model_spec.rb +54 -0
  204. data/spec/models/open_ai_file_spec.rb +78 -0
  205. data/spec/spec_helper.rb +111 -0
  206. metadata +348 -0
@@ -0,0 +1,296 @@
1
+ =begin
2
+ #OpenAI API
3
+
4
+ #APIs for sampling from and fine-tuning language models
5
+
6
+ The version of the OpenAPI document: 2.0.0
7
+ Contact: blah+oapicf@cliffano.com
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.4.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module OpenApiOpenAIClient
17
+ class CreateChatCompletionResponse
18
+ attr_accessor :id
19
+
20
+ attr_accessor :object
21
+
22
+ attr_accessor :created
23
+
24
+ attr_accessor :model
25
+
26
+ attr_accessor :choices
27
+
28
+ attr_accessor :usage
29
+
30
+ # Attribute mapping from ruby-style variable name to JSON key.
31
+ def self.attribute_map
32
+ {
33
+ :'id' => :'id',
34
+ :'object' => :'object',
35
+ :'created' => :'created',
36
+ :'model' => :'model',
37
+ :'choices' => :'choices',
38
+ :'usage' => :'usage'
39
+ }
40
+ end
41
+
42
+ # Returns all the JSON keys this model knows about
43
+ def self.acceptable_attributes
44
+ attribute_map.values
45
+ end
46
+
47
+ # Attribute type mapping.
48
+ def self.openapi_types
49
+ {
50
+ :'id' => :'String',
51
+ :'object' => :'String',
52
+ :'created' => :'Integer',
53
+ :'model' => :'String',
54
+ :'choices' => :'Array<CreateChatCompletionResponseChoicesInner>',
55
+ :'usage' => :'CreateCompletionResponseUsage'
56
+ }
57
+ end
58
+
59
+ # List of attributes with nullable: true
60
+ def self.openapi_nullable
61
+ Set.new([
62
+ ])
63
+ end
64
+
65
+ # Initializes the object
66
+ # @param [Hash] attributes Model attributes in the form of hash
67
+ def initialize(attributes = {})
68
+ if (!attributes.is_a?(Hash))
69
+ fail ArgumentError, "The input argument (attributes) must be a hash in `OpenApiOpenAIClient::CreateChatCompletionResponse` initialize method"
70
+ end
71
+
72
+ # check to see if the attribute exists and convert string to symbol for hash key
73
+ attributes = attributes.each_with_object({}) { |(k, v), h|
74
+ if (!self.class.attribute_map.key?(k.to_sym))
75
+ fail ArgumentError, "`#{k}` is not a valid attribute in `OpenApiOpenAIClient::CreateChatCompletionResponse`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
76
+ end
77
+ h[k.to_sym] = v
78
+ }
79
+
80
+ if attributes.key?(:'id')
81
+ self.id = attributes[:'id']
82
+ else
83
+ self.id = nil
84
+ end
85
+
86
+ if attributes.key?(:'object')
87
+ self.object = attributes[:'object']
88
+ else
89
+ self.object = nil
90
+ end
91
+
92
+ if attributes.key?(:'created')
93
+ self.created = attributes[:'created']
94
+ else
95
+ self.created = nil
96
+ end
97
+
98
+ if attributes.key?(:'model')
99
+ self.model = attributes[:'model']
100
+ else
101
+ self.model = nil
102
+ end
103
+
104
+ if attributes.key?(:'choices')
105
+ if (value = attributes[:'choices']).is_a?(Array)
106
+ self.choices = value
107
+ end
108
+ else
109
+ self.choices = nil
110
+ end
111
+
112
+ if attributes.key?(:'usage')
113
+ self.usage = attributes[:'usage']
114
+ end
115
+ end
116
+
117
+ # Show invalid properties with the reasons. Usually used together with valid?
118
+ # @return Array for valid properties with the reasons
119
+ def list_invalid_properties
120
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
121
+ invalid_properties = Array.new
122
+ if @id.nil?
123
+ invalid_properties.push('invalid value for "id", id cannot be nil.')
124
+ end
125
+
126
+ if @object.nil?
127
+ invalid_properties.push('invalid value for "object", object cannot be nil.')
128
+ end
129
+
130
+ if @created.nil?
131
+ invalid_properties.push('invalid value for "created", created cannot be nil.')
132
+ end
133
+
134
+ if @model.nil?
135
+ invalid_properties.push('invalid value for "model", model cannot be nil.')
136
+ end
137
+
138
+ if @choices.nil?
139
+ invalid_properties.push('invalid value for "choices", choices cannot be nil.')
140
+ end
141
+
142
+ invalid_properties
143
+ end
144
+
145
+ # Check to see if the all the properties in the model are valid
146
+ # @return true if the model is valid
147
+ def valid?
148
+ warn '[DEPRECATED] the `valid?` method is obsolete'
149
+ return false if @id.nil?
150
+ return false if @object.nil?
151
+ return false if @created.nil?
152
+ return false if @model.nil?
153
+ return false if @choices.nil?
154
+ true
155
+ end
156
+
157
+ # Checks equality by comparing each attribute.
158
+ # @param [Object] Object to be compared
159
+ def ==(o)
160
+ return true if self.equal?(o)
161
+ self.class == o.class &&
162
+ id == o.id &&
163
+ object == o.object &&
164
+ created == o.created &&
165
+ model == o.model &&
166
+ choices == o.choices &&
167
+ usage == o.usage
168
+ end
169
+
170
+ # @see the `==` method
171
+ # @param [Object] Object to be compared
172
+ def eql?(o)
173
+ self == o
174
+ end
175
+
176
+ # Calculates hash code according to all attributes.
177
+ # @return [Integer] Hash code
178
+ def hash
179
+ [id, object, created, model, choices, usage].hash
180
+ end
181
+
182
+ # Builds the object from hash
183
+ # @param [Hash] attributes Model attributes in the form of hash
184
+ # @return [Object] Returns the model itself
185
+ def self.build_from_hash(attributes)
186
+ return nil unless attributes.is_a?(Hash)
187
+ attributes = attributes.transform_keys(&:to_sym)
188
+ transformed_hash = {}
189
+ openapi_types.each_pair do |key, type|
190
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
191
+ transformed_hash["#{key}"] = nil
192
+ elsif type =~ /\AArray<(.*)>/i
193
+ # check to ensure the input is an array given that the attribute
194
+ # is documented as an array but the input is not
195
+ if attributes[attribute_map[key]].is_a?(Array)
196
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
197
+ end
198
+ elsif !attributes[attribute_map[key]].nil?
199
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
200
+ end
201
+ end
202
+ new(transformed_hash)
203
+ end
204
+
205
+ # Deserializes the data based on type
206
+ # @param string type Data type
207
+ # @param string value Value to be deserialized
208
+ # @return [Object] Deserialized data
209
+ def self._deserialize(type, value)
210
+ case type.to_sym
211
+ when :Time
212
+ Time.parse(value)
213
+ when :Date
214
+ Date.parse(value)
215
+ when :String
216
+ value.to_s
217
+ when :Integer
218
+ value.to_i
219
+ when :Float
220
+ value.to_f
221
+ when :Boolean
222
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
223
+ true
224
+ else
225
+ false
226
+ end
227
+ when :Object
228
+ # generic object (usually a Hash), return directly
229
+ value
230
+ when /\AArray<(?<inner_type>.+)>\z/
231
+ inner_type = Regexp.last_match[:inner_type]
232
+ value.map { |v| _deserialize(inner_type, v) }
233
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
234
+ k_type = Regexp.last_match[:k_type]
235
+ v_type = Regexp.last_match[:v_type]
236
+ {}.tap do |hash|
237
+ value.each do |k, v|
238
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
239
+ end
240
+ end
241
+ else # model
242
+ # models (e.g. Pet) or oneOf
243
+ klass = OpenApiOpenAIClient.const_get(type)
244
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
245
+ end
246
+ end
247
+
248
+ # Returns the string representation of the object
249
+ # @return [String] String presentation of the object
250
+ def to_s
251
+ to_hash.to_s
252
+ end
253
+
254
+ # to_body is an alias to to_hash (backward compatibility)
255
+ # @return [Hash] Returns the object in the form of hash
256
+ def to_body
257
+ to_hash
258
+ end
259
+
260
+ # Returns the object in the form of hash
261
+ # @return [Hash] Returns the object in the form of hash
262
+ def to_hash
263
+ hash = {}
264
+ self.class.attribute_map.each_pair do |attr, param|
265
+ value = self.send(attr)
266
+ if value.nil?
267
+ is_nullable = self.class.openapi_nullable.include?(attr)
268
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
269
+ end
270
+
271
+ hash[param] = _to_hash(value)
272
+ end
273
+ hash
274
+ end
275
+
276
+ # Outputs non-array value in the form of hash
277
+ # For object, use to_hash. Otherwise, just return the value
278
+ # @param [Object] value Any valid value
279
+ # @return [Hash] Returns the value in the form of hash
280
+ def _to_hash(value)
281
+ if value.is_a?(Array)
282
+ value.compact.map { |v| _to_hash(v) }
283
+ elsif value.is_a?(Hash)
284
+ {}.tap do |hash|
285
+ value.each { |k, v| hash[k] = _to_hash(v) }
286
+ end
287
+ elsif value.respond_to? :to_hash
288
+ value.to_hash
289
+ else
290
+ value
291
+ end
292
+ end
293
+
294
+ end
295
+
296
+ end
@@ -0,0 +1,266 @@
1
+ =begin
2
+ #OpenAI API
3
+
4
+ #APIs for sampling from and fine-tuning language models
5
+
6
+ The version of the OpenAPI document: 2.0.0
7
+ Contact: blah+oapicf@cliffano.com
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.4.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module OpenApiOpenAIClient
17
+ class CreateChatCompletionResponseChoicesInner
18
+ attr_accessor :index
19
+
20
+ attr_accessor :message
21
+
22
+ attr_accessor :finish_reason
23
+
24
+ class EnumAttributeValidator
25
+ attr_reader :datatype
26
+ attr_reader :allowable_values
27
+
28
+ def initialize(datatype, allowable_values)
29
+ @allowable_values = allowable_values.map do |value|
30
+ case datatype.to_s
31
+ when /Integer/i
32
+ value.to_i
33
+ when /Float/i
34
+ value.to_f
35
+ else
36
+ value
37
+ end
38
+ end
39
+ end
40
+
41
+ def valid?(value)
42
+ !value || allowable_values.include?(value)
43
+ end
44
+ end
45
+
46
+ # Attribute mapping from ruby-style variable name to JSON key.
47
+ def self.attribute_map
48
+ {
49
+ :'index' => :'index',
50
+ :'message' => :'message',
51
+ :'finish_reason' => :'finish_reason'
52
+ }
53
+ end
54
+
55
+ # Returns all the JSON keys this model knows about
56
+ def self.acceptable_attributes
57
+ attribute_map.values
58
+ end
59
+
60
+ # Attribute type mapping.
61
+ def self.openapi_types
62
+ {
63
+ :'index' => :'Integer',
64
+ :'message' => :'ChatCompletionResponseMessage',
65
+ :'finish_reason' => :'String'
66
+ }
67
+ end
68
+
69
+ # List of attributes with nullable: true
70
+ def self.openapi_nullable
71
+ Set.new([
72
+ ])
73
+ end
74
+
75
+ # Initializes the object
76
+ # @param [Hash] attributes Model attributes in the form of hash
77
+ def initialize(attributes = {})
78
+ if (!attributes.is_a?(Hash))
79
+ fail ArgumentError, "The input argument (attributes) must be a hash in `OpenApiOpenAIClient::CreateChatCompletionResponseChoicesInner` initialize method"
80
+ end
81
+
82
+ # check to see if the attribute exists and convert string to symbol for hash key
83
+ attributes = attributes.each_with_object({}) { |(k, v), h|
84
+ if (!self.class.attribute_map.key?(k.to_sym))
85
+ fail ArgumentError, "`#{k}` is not a valid attribute in `OpenApiOpenAIClient::CreateChatCompletionResponseChoicesInner`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
86
+ end
87
+ h[k.to_sym] = v
88
+ }
89
+
90
+ if attributes.key?(:'index')
91
+ self.index = attributes[:'index']
92
+ end
93
+
94
+ if attributes.key?(:'message')
95
+ self.message = attributes[:'message']
96
+ end
97
+
98
+ if attributes.key?(:'finish_reason')
99
+ self.finish_reason = attributes[:'finish_reason']
100
+ end
101
+ end
102
+
103
+ # Show invalid properties with the reasons. Usually used together with valid?
104
+ # @return Array for valid properties with the reasons
105
+ def list_invalid_properties
106
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
107
+ invalid_properties = Array.new
108
+ invalid_properties
109
+ end
110
+
111
+ # Check to see if the all the properties in the model are valid
112
+ # @return true if the model is valid
113
+ def valid?
114
+ warn '[DEPRECATED] the `valid?` method is obsolete'
115
+ finish_reason_validator = EnumAttributeValidator.new('String', ["stop", "length", "function_call"])
116
+ return false unless finish_reason_validator.valid?(@finish_reason)
117
+ true
118
+ end
119
+
120
+ # Custom attribute writer method checking allowed values (enum).
121
+ # @param [Object] finish_reason Object to be assigned
122
+ def finish_reason=(finish_reason)
123
+ validator = EnumAttributeValidator.new('String', ["stop", "length", "function_call"])
124
+ unless validator.valid?(finish_reason)
125
+ fail ArgumentError, "invalid value for \"finish_reason\", must be one of #{validator.allowable_values}."
126
+ end
127
+ @finish_reason = finish_reason
128
+ end
129
+
130
+ # Checks equality by comparing each attribute.
131
+ # @param [Object] Object to be compared
132
+ def ==(o)
133
+ return true if self.equal?(o)
134
+ self.class == o.class &&
135
+ index == o.index &&
136
+ message == o.message &&
137
+ finish_reason == o.finish_reason
138
+ end
139
+
140
+ # @see the `==` method
141
+ # @param [Object] Object to be compared
142
+ def eql?(o)
143
+ self == o
144
+ end
145
+
146
+ # Calculates hash code according to all attributes.
147
+ # @return [Integer] Hash code
148
+ def hash
149
+ [index, message, finish_reason].hash
150
+ end
151
+
152
+ # Builds the object from hash
153
+ # @param [Hash] attributes Model attributes in the form of hash
154
+ # @return [Object] Returns the model itself
155
+ def self.build_from_hash(attributes)
156
+ return nil unless attributes.is_a?(Hash)
157
+ attributes = attributes.transform_keys(&:to_sym)
158
+ transformed_hash = {}
159
+ openapi_types.each_pair do |key, type|
160
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
161
+ transformed_hash["#{key}"] = nil
162
+ elsif type =~ /\AArray<(.*)>/i
163
+ # check to ensure the input is an array given that the attribute
164
+ # is documented as an array but the input is not
165
+ if attributes[attribute_map[key]].is_a?(Array)
166
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
167
+ end
168
+ elsif !attributes[attribute_map[key]].nil?
169
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
170
+ end
171
+ end
172
+ new(transformed_hash)
173
+ end
174
+
175
+ # Deserializes the data based on type
176
+ # @param string type Data type
177
+ # @param string value Value to be deserialized
178
+ # @return [Object] Deserialized data
179
+ def self._deserialize(type, value)
180
+ case type.to_sym
181
+ when :Time
182
+ Time.parse(value)
183
+ when :Date
184
+ Date.parse(value)
185
+ when :String
186
+ value.to_s
187
+ when :Integer
188
+ value.to_i
189
+ when :Float
190
+ value.to_f
191
+ when :Boolean
192
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
193
+ true
194
+ else
195
+ false
196
+ end
197
+ when :Object
198
+ # generic object (usually a Hash), return directly
199
+ value
200
+ when /\AArray<(?<inner_type>.+)>\z/
201
+ inner_type = Regexp.last_match[:inner_type]
202
+ value.map { |v| _deserialize(inner_type, v) }
203
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
204
+ k_type = Regexp.last_match[:k_type]
205
+ v_type = Regexp.last_match[:v_type]
206
+ {}.tap do |hash|
207
+ value.each do |k, v|
208
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
209
+ end
210
+ end
211
+ else # model
212
+ # models (e.g. Pet) or oneOf
213
+ klass = OpenApiOpenAIClient.const_get(type)
214
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
215
+ end
216
+ end
217
+
218
+ # Returns the string representation of the object
219
+ # @return [String] String presentation of the object
220
+ def to_s
221
+ to_hash.to_s
222
+ end
223
+
224
+ # to_body is an alias to to_hash (backward compatibility)
225
+ # @return [Hash] Returns the object in the form of hash
226
+ def to_body
227
+ to_hash
228
+ end
229
+
230
+ # Returns the object in the form of hash
231
+ # @return [Hash] Returns the object in the form of hash
232
+ def to_hash
233
+ hash = {}
234
+ self.class.attribute_map.each_pair do |attr, param|
235
+ value = self.send(attr)
236
+ if value.nil?
237
+ is_nullable = self.class.openapi_nullable.include?(attr)
238
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
239
+ end
240
+
241
+ hash[param] = _to_hash(value)
242
+ end
243
+ hash
244
+ end
245
+
246
+ # Outputs non-array value in the form of hash
247
+ # For object, use to_hash. Otherwise, just return the value
248
+ # @param [Object] value Any valid value
249
+ # @return [Hash] Returns the value in the form of hash
250
+ def _to_hash(value)
251
+ if value.is_a?(Array)
252
+ value.compact.map { |v| _to_hash(v) }
253
+ elsif value.is_a?(Hash)
254
+ {}.tap do |hash|
255
+ value.each { |k, v| hash[k] = _to_hash(v) }
256
+ end
257
+ elsif value.respond_to? :to_hash
258
+ value.to_hash
259
+ else
260
+ value
261
+ end
262
+ end
263
+
264
+ end
265
+
266
+ end