openapi_openai 1.0.0

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 (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,537 @@
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 CreateChatCompletionRequest
18
+ attr_accessor :model
19
+
20
+ # A list of messages comprising the conversation so far. [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb).
21
+ attr_accessor :messages
22
+
23
+ # A list of functions the model may generate JSON inputs for.
24
+ attr_accessor :functions
25
+
26
+ attr_accessor :function_call
27
+
28
+ # What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both.
29
+ attr_accessor :temperature
30
+
31
+ # 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.
32
+ attr_accessor :top_p
33
+
34
+ # How many chat completion choices to generate for each input message.
35
+ attr_accessor :n
36
+
37
+ # If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format) as they become available, with the stream terminated by a `data: [DONE]` message. [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_stream_completions.ipynb).
38
+ attr_accessor :stream
39
+
40
+ attr_accessor :stop
41
+
42
+ # The maximum number of [tokens](/tokenizer) to generate in the chat completion. The total length of input tokens and generated tokens is limited by the model's context length. [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb) for counting tokens.
43
+ attr_accessor :max_tokens
44
+
45
+ # 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. [See more information about frequency and presence penalties.](/docs/api-reference/parameter-details)
46
+ attr_accessor :presence_penalty
47
+
48
+ # 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. [See more information about frequency and presence penalties.](/docs/api-reference/parameter-details)
49
+ attr_accessor :frequency_penalty
50
+
51
+ # Modify the likelihood of specified tokens appearing in the completion. Accepts a json object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. 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.
52
+ attr_accessor :logit_bias
53
+
54
+ # A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids).
55
+ attr_accessor :user
56
+
57
+ # Attribute mapping from ruby-style variable name to JSON key.
58
+ def self.attribute_map
59
+ {
60
+ :'model' => :'model',
61
+ :'messages' => :'messages',
62
+ :'functions' => :'functions',
63
+ :'function_call' => :'function_call',
64
+ :'temperature' => :'temperature',
65
+ :'top_p' => :'top_p',
66
+ :'n' => :'n',
67
+ :'stream' => :'stream',
68
+ :'stop' => :'stop',
69
+ :'max_tokens' => :'max_tokens',
70
+ :'presence_penalty' => :'presence_penalty',
71
+ :'frequency_penalty' => :'frequency_penalty',
72
+ :'logit_bias' => :'logit_bias',
73
+ :'user' => :'user'
74
+ }
75
+ end
76
+
77
+ # Returns all the JSON keys this model knows about
78
+ def self.acceptable_attributes
79
+ attribute_map.values
80
+ end
81
+
82
+ # Attribute type mapping.
83
+ def self.openapi_types
84
+ {
85
+ :'model' => :'CreateChatCompletionRequestModel',
86
+ :'messages' => :'Array<ChatCompletionRequestMessage>',
87
+ :'functions' => :'Array<ChatCompletionFunctions>',
88
+ :'function_call' => :'CreateChatCompletionRequestFunctionCall',
89
+ :'temperature' => :'Float',
90
+ :'top_p' => :'Float',
91
+ :'n' => :'Integer',
92
+ :'stream' => :'Boolean',
93
+ :'stop' => :'CreateChatCompletionRequestStop',
94
+ :'max_tokens' => :'Integer',
95
+ :'presence_penalty' => :'Float',
96
+ :'frequency_penalty' => :'Float',
97
+ :'logit_bias' => :'Object',
98
+ :'user' => :'String'
99
+ }
100
+ end
101
+
102
+ # List of attributes with nullable: true
103
+ def self.openapi_nullable
104
+ Set.new([
105
+ :'temperature',
106
+ :'top_p',
107
+ :'n',
108
+ :'stream',
109
+ :'presence_penalty',
110
+ :'frequency_penalty',
111
+ :'logit_bias',
112
+ ])
113
+ end
114
+
115
+ # Initializes the object
116
+ # @param [Hash] attributes Model attributes in the form of hash
117
+ def initialize(attributes = {})
118
+ if (!attributes.is_a?(Hash))
119
+ fail ArgumentError, "The input argument (attributes) must be a hash in `OpenApiOpenAIClient::CreateChatCompletionRequest` initialize method"
120
+ end
121
+
122
+ # check to see if the attribute exists and convert string to symbol for hash key
123
+ attributes = attributes.each_with_object({}) { |(k, v), h|
124
+ if (!self.class.attribute_map.key?(k.to_sym))
125
+ fail ArgumentError, "`#{k}` is not a valid attribute in `OpenApiOpenAIClient::CreateChatCompletionRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
126
+ end
127
+ h[k.to_sym] = v
128
+ }
129
+
130
+ if attributes.key?(:'model')
131
+ self.model = attributes[:'model']
132
+ else
133
+ self.model = nil
134
+ end
135
+
136
+ if attributes.key?(:'messages')
137
+ if (value = attributes[:'messages']).is_a?(Array)
138
+ self.messages = value
139
+ end
140
+ else
141
+ self.messages = nil
142
+ end
143
+
144
+ if attributes.key?(:'functions')
145
+ if (value = attributes[:'functions']).is_a?(Array)
146
+ self.functions = value
147
+ end
148
+ end
149
+
150
+ if attributes.key?(:'function_call')
151
+ self.function_call = attributes[:'function_call']
152
+ end
153
+
154
+ if attributes.key?(:'temperature')
155
+ self.temperature = attributes[:'temperature']
156
+ else
157
+ self.temperature = 1
158
+ end
159
+
160
+ if attributes.key?(:'top_p')
161
+ self.top_p = attributes[:'top_p']
162
+ else
163
+ self.top_p = 1
164
+ end
165
+
166
+ if attributes.key?(:'n')
167
+ self.n = attributes[:'n']
168
+ else
169
+ self.n = 1
170
+ end
171
+
172
+ if attributes.key?(:'stream')
173
+ self.stream = attributes[:'stream']
174
+ else
175
+ self.stream = false
176
+ end
177
+
178
+ if attributes.key?(:'stop')
179
+ self.stop = attributes[:'stop']
180
+ end
181
+
182
+ if attributes.key?(:'max_tokens')
183
+ self.max_tokens = attributes[:'max_tokens']
184
+ end
185
+
186
+ if attributes.key?(:'presence_penalty')
187
+ self.presence_penalty = attributes[:'presence_penalty']
188
+ else
189
+ self.presence_penalty = 0
190
+ end
191
+
192
+ if attributes.key?(:'frequency_penalty')
193
+ self.frequency_penalty = attributes[:'frequency_penalty']
194
+ else
195
+ self.frequency_penalty = 0
196
+ end
197
+
198
+ if attributes.key?(:'logit_bias')
199
+ self.logit_bias = attributes[:'logit_bias']
200
+ end
201
+
202
+ if attributes.key?(:'user')
203
+ self.user = attributes[:'user']
204
+ end
205
+ end
206
+
207
+ # Show invalid properties with the reasons. Usually used together with valid?
208
+ # @return Array for valid properties with the reasons
209
+ def list_invalid_properties
210
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
211
+ invalid_properties = Array.new
212
+ if @model.nil?
213
+ invalid_properties.push('invalid value for "model", model cannot be nil.')
214
+ end
215
+
216
+ if @messages.nil?
217
+ invalid_properties.push('invalid value for "messages", messages cannot be nil.')
218
+ end
219
+
220
+ if @messages.length < 1
221
+ invalid_properties.push('invalid value for "messages", number of items must be greater than or equal to 1.')
222
+ end
223
+
224
+ if !@functions.nil? && @functions.length < 1
225
+ invalid_properties.push('invalid value for "functions", number of items must be greater than or equal to 1.')
226
+ end
227
+
228
+ if !@temperature.nil? && @temperature > 2
229
+ invalid_properties.push('invalid value for "temperature", must be smaller than or equal to 2.')
230
+ end
231
+
232
+ if !@temperature.nil? && @temperature < 0
233
+ invalid_properties.push('invalid value for "temperature", must be greater than or equal to 0.')
234
+ end
235
+
236
+ if !@top_p.nil? && @top_p > 1
237
+ invalid_properties.push('invalid value for "top_p", must be smaller than or equal to 1.')
238
+ end
239
+
240
+ if !@top_p.nil? && @top_p < 0
241
+ invalid_properties.push('invalid value for "top_p", must be greater than or equal to 0.')
242
+ end
243
+
244
+ if !@n.nil? && @n > 128
245
+ invalid_properties.push('invalid value for "n", must be smaller than or equal to 128.')
246
+ end
247
+
248
+ if !@n.nil? && @n < 1
249
+ invalid_properties.push('invalid value for "n", must be greater than or equal to 1.')
250
+ end
251
+
252
+ if !@presence_penalty.nil? && @presence_penalty > 2
253
+ invalid_properties.push('invalid value for "presence_penalty", must be smaller than or equal to 2.')
254
+ end
255
+
256
+ if !@presence_penalty.nil? && @presence_penalty < -2
257
+ invalid_properties.push('invalid value for "presence_penalty", must be greater than or equal to -2.')
258
+ end
259
+
260
+ if !@frequency_penalty.nil? && @frequency_penalty > 2
261
+ invalid_properties.push('invalid value for "frequency_penalty", must be smaller than or equal to 2.')
262
+ end
263
+
264
+ if !@frequency_penalty.nil? && @frequency_penalty < -2
265
+ invalid_properties.push('invalid value for "frequency_penalty", must be greater than or equal to -2.')
266
+ end
267
+
268
+ invalid_properties
269
+ end
270
+
271
+ # Check to see if the all the properties in the model are valid
272
+ # @return true if the model is valid
273
+ def valid?
274
+ warn '[DEPRECATED] the `valid?` method is obsolete'
275
+ return false if @model.nil?
276
+ return false if @messages.nil?
277
+ return false if @messages.length < 1
278
+ return false if !@functions.nil? && @functions.length < 1
279
+ return false if !@temperature.nil? && @temperature > 2
280
+ return false if !@temperature.nil? && @temperature < 0
281
+ return false if !@top_p.nil? && @top_p > 1
282
+ return false if !@top_p.nil? && @top_p < 0
283
+ return false if !@n.nil? && @n > 128
284
+ return false if !@n.nil? && @n < 1
285
+ return false if !@presence_penalty.nil? && @presence_penalty > 2
286
+ return false if !@presence_penalty.nil? && @presence_penalty < -2
287
+ return false if !@frequency_penalty.nil? && @frequency_penalty > 2
288
+ return false if !@frequency_penalty.nil? && @frequency_penalty < -2
289
+ true
290
+ end
291
+
292
+ # Custom attribute writer method with validation
293
+ # @param [Object] messages Value to be assigned
294
+ def messages=(messages)
295
+ if messages.nil?
296
+ fail ArgumentError, 'messages cannot be nil'
297
+ end
298
+
299
+ if messages.length < 1
300
+ fail ArgumentError, 'invalid value for "messages", number of items must be greater than or equal to 1.'
301
+ end
302
+
303
+ @messages = messages
304
+ end
305
+
306
+ # Custom attribute writer method with validation
307
+ # @param [Object] functions Value to be assigned
308
+ def functions=(functions)
309
+ if functions.nil?
310
+ fail ArgumentError, 'functions cannot be nil'
311
+ end
312
+
313
+ if functions.length < 1
314
+ fail ArgumentError, 'invalid value for "functions", number of items must be greater than or equal to 1.'
315
+ end
316
+
317
+ @functions = functions
318
+ end
319
+
320
+ # Custom attribute writer method with validation
321
+ # @param [Object] temperature Value to be assigned
322
+ def temperature=(temperature)
323
+ if !temperature.nil? && temperature > 2
324
+ fail ArgumentError, 'invalid value for "temperature", must be smaller than or equal to 2.'
325
+ end
326
+
327
+ if !temperature.nil? && temperature < 0
328
+ fail ArgumentError, 'invalid value for "temperature", must be greater than or equal to 0.'
329
+ end
330
+
331
+ @temperature = temperature
332
+ end
333
+
334
+ # Custom attribute writer method with validation
335
+ # @param [Object] top_p Value to be assigned
336
+ def top_p=(top_p)
337
+ if !top_p.nil? && top_p > 1
338
+ fail ArgumentError, 'invalid value for "top_p", must be smaller than or equal to 1.'
339
+ end
340
+
341
+ if !top_p.nil? && top_p < 0
342
+ fail ArgumentError, 'invalid value for "top_p", must be greater than or equal to 0.'
343
+ end
344
+
345
+ @top_p = top_p
346
+ end
347
+
348
+ # Custom attribute writer method with validation
349
+ # @param [Object] n Value to be assigned
350
+ def n=(n)
351
+ if !n.nil? && n > 128
352
+ fail ArgumentError, 'invalid value for "n", must be smaller than or equal to 128.'
353
+ end
354
+
355
+ if !n.nil? && n < 1
356
+ fail ArgumentError, 'invalid value for "n", must be greater than or equal to 1.'
357
+ end
358
+
359
+ @n = n
360
+ end
361
+
362
+ # Custom attribute writer method with validation
363
+ # @param [Object] presence_penalty Value to be assigned
364
+ def presence_penalty=(presence_penalty)
365
+ if !presence_penalty.nil? && presence_penalty > 2
366
+ fail ArgumentError, 'invalid value for "presence_penalty", must be smaller than or equal to 2.'
367
+ end
368
+
369
+ if !presence_penalty.nil? && presence_penalty < -2
370
+ fail ArgumentError, 'invalid value for "presence_penalty", must be greater than or equal to -2.'
371
+ end
372
+
373
+ @presence_penalty = presence_penalty
374
+ end
375
+
376
+ # Custom attribute writer method with validation
377
+ # @param [Object] frequency_penalty Value to be assigned
378
+ def frequency_penalty=(frequency_penalty)
379
+ if !frequency_penalty.nil? && frequency_penalty > 2
380
+ fail ArgumentError, 'invalid value for "frequency_penalty", must be smaller than or equal to 2.'
381
+ end
382
+
383
+ if !frequency_penalty.nil? && frequency_penalty < -2
384
+ fail ArgumentError, 'invalid value for "frequency_penalty", must be greater than or equal to -2.'
385
+ end
386
+
387
+ @frequency_penalty = frequency_penalty
388
+ end
389
+
390
+ # Checks equality by comparing each attribute.
391
+ # @param [Object] Object to be compared
392
+ def ==(o)
393
+ return true if self.equal?(o)
394
+ self.class == o.class &&
395
+ model == o.model &&
396
+ messages == o.messages &&
397
+ functions == o.functions &&
398
+ function_call == o.function_call &&
399
+ temperature == o.temperature &&
400
+ top_p == o.top_p &&
401
+ n == o.n &&
402
+ stream == o.stream &&
403
+ stop == o.stop &&
404
+ max_tokens == o.max_tokens &&
405
+ presence_penalty == o.presence_penalty &&
406
+ frequency_penalty == o.frequency_penalty &&
407
+ logit_bias == o.logit_bias &&
408
+ user == o.user
409
+ end
410
+
411
+ # @see the `==` method
412
+ # @param [Object] Object to be compared
413
+ def eql?(o)
414
+ self == o
415
+ end
416
+
417
+ # Calculates hash code according to all attributes.
418
+ # @return [Integer] Hash code
419
+ def hash
420
+ [model, messages, functions, function_call, temperature, top_p, n, stream, stop, max_tokens, presence_penalty, frequency_penalty, logit_bias, user].hash
421
+ end
422
+
423
+ # Builds the object from hash
424
+ # @param [Hash] attributes Model attributes in the form of hash
425
+ # @return [Object] Returns the model itself
426
+ def self.build_from_hash(attributes)
427
+ return nil unless attributes.is_a?(Hash)
428
+ attributes = attributes.transform_keys(&:to_sym)
429
+ transformed_hash = {}
430
+ openapi_types.each_pair do |key, type|
431
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
432
+ transformed_hash["#{key}"] = nil
433
+ elsif type =~ /\AArray<(.*)>/i
434
+ # check to ensure the input is an array given that the attribute
435
+ # is documented as an array but the input is not
436
+ if attributes[attribute_map[key]].is_a?(Array)
437
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
438
+ end
439
+ elsif !attributes[attribute_map[key]].nil?
440
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
441
+ end
442
+ end
443
+ new(transformed_hash)
444
+ end
445
+
446
+ # Deserializes the data based on type
447
+ # @param string type Data type
448
+ # @param string value Value to be deserialized
449
+ # @return [Object] Deserialized data
450
+ def self._deserialize(type, value)
451
+ case type.to_sym
452
+ when :Time
453
+ Time.parse(value)
454
+ when :Date
455
+ Date.parse(value)
456
+ when :String
457
+ value.to_s
458
+ when :Integer
459
+ value.to_i
460
+ when :Float
461
+ value.to_f
462
+ when :Boolean
463
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
464
+ true
465
+ else
466
+ false
467
+ end
468
+ when :Object
469
+ # generic object (usually a Hash), return directly
470
+ value
471
+ when /\AArray<(?<inner_type>.+)>\z/
472
+ inner_type = Regexp.last_match[:inner_type]
473
+ value.map { |v| _deserialize(inner_type, v) }
474
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
475
+ k_type = Regexp.last_match[:k_type]
476
+ v_type = Regexp.last_match[:v_type]
477
+ {}.tap do |hash|
478
+ value.each do |k, v|
479
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
480
+ end
481
+ end
482
+ else # model
483
+ # models (e.g. Pet) or oneOf
484
+ klass = OpenApiOpenAIClient.const_get(type)
485
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
486
+ end
487
+ end
488
+
489
+ # Returns the string representation of the object
490
+ # @return [String] String presentation of the object
491
+ def to_s
492
+ to_hash.to_s
493
+ end
494
+
495
+ # to_body is an alias to to_hash (backward compatibility)
496
+ # @return [Hash] Returns the object in the form of hash
497
+ def to_body
498
+ to_hash
499
+ end
500
+
501
+ # Returns the object in the form of hash
502
+ # @return [Hash] Returns the object in the form of hash
503
+ def to_hash
504
+ hash = {}
505
+ self.class.attribute_map.each_pair do |attr, param|
506
+ value = self.send(attr)
507
+ if value.nil?
508
+ is_nullable = self.class.openapi_nullable.include?(attr)
509
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
510
+ end
511
+
512
+ hash[param] = _to_hash(value)
513
+ end
514
+ hash
515
+ end
516
+
517
+ # Outputs non-array value in the form of hash
518
+ # For object, use to_hash. Otherwise, just return the value
519
+ # @param [Object] value Any valid value
520
+ # @return [Hash] Returns the value in the form of hash
521
+ def _to_hash(value)
522
+ if value.is_a?(Array)
523
+ value.compact.map { |v| _to_hash(v) }
524
+ elsif value.is_a?(Hash)
525
+ {}.tap do |hash|
526
+ value.each { |k, v| hash[k] = _to_hash(v) }
527
+ end
528
+ elsif value.respond_to? :to_hash
529
+ value.to_hash
530
+ else
531
+ value
532
+ end
533
+ end
534
+
535
+ end
536
+
537
+ end
@@ -0,0 +1,106 @@
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
+ # Controls how the model responds to function calls. \"none\" means the model does not call a function, and responds to the end-user. \"auto\" means the model can pick between an end-user or calling a function. Specifying a particular function via `{\"name\":\\ \"my_function\"}` forces the model to call that function. \"none\" is the default when no functions are present. \"auto\" is the default if functions are present.
18
+ module CreateChatCompletionRequestFunctionCall
19
+ class << self
20
+ # List of class defined in oneOf (OpenAPI v3)
21
+ def openapi_one_of
22
+ [
23
+ :'CreateChatCompletionRequestFunctionCallOneOf',
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 = OpenApiOpenAIClient.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 if const.respond_to?(:acceptable_attributes) && !(data.keys - const.acceptable_attributes).empty?
93
+ model = const.build_from_hash(data)
94
+ return model if model
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
+
106
+ end