openapi_openai 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +72 -0
- data/README.md +171 -0
- data/Rakefile +10 -0
- data/bin/bundle +109 -0
- data/bin/byebug +27 -0
- data/bin/coderay +27 -0
- data/bin/htmldiff +27 -0
- data/bin/ldiff +27 -0
- data/bin/pry +27 -0
- data/bin/racc +27 -0
- data/bin/rake +27 -0
- data/bin/rspec +27 -0
- data/bin/rubocop +27 -0
- data/bin/ruby-parse +27 -0
- data/bin/ruby-rewrite +27 -0
- data/docs/ChatCompletionFunctions.md +22 -0
- data/docs/ChatCompletionRequestMessage.md +24 -0
- data/docs/ChatCompletionRequestMessageFunctionCall.md +20 -0
- data/docs/ChatCompletionResponseMessage.md +22 -0
- data/docs/ChatCompletionStreamResponseDelta.md +22 -0
- data/docs/CreateChatCompletionRequest.md +44 -0
- data/docs/CreateChatCompletionRequestFunctionCall.md +49 -0
- data/docs/CreateChatCompletionRequestFunctionCallOneOf.md +18 -0
- data/docs/CreateChatCompletionRequestModel.md +47 -0
- data/docs/CreateChatCompletionRequestStop.md +49 -0
- data/docs/CreateChatCompletionResponse.md +28 -0
- data/docs/CreateChatCompletionResponseChoicesInner.md +22 -0
- data/docs/CreateChatCompletionStreamResponse.md +26 -0
- data/docs/CreateChatCompletionStreamResponseChoicesInner.md +22 -0
- data/docs/CreateCompletionRequest.md +48 -0
- data/docs/CreateCompletionRequestModel.md +47 -0
- data/docs/CreateCompletionRequestPrompt.md +53 -0
- data/docs/CreateCompletionRequestStop.md +49 -0
- data/docs/CreateCompletionResponse.md +28 -0
- data/docs/CreateCompletionResponseChoicesInner.md +24 -0
- data/docs/CreateCompletionResponseChoicesInnerLogprobs.md +24 -0
- data/docs/CreateCompletionResponseUsage.md +22 -0
- data/docs/CreateEditRequest.md +28 -0
- data/docs/CreateEditRequestModel.md +47 -0
- data/docs/CreateEditResponse.md +24 -0
- data/docs/CreateEditResponseChoicesInner.md +24 -0
- data/docs/CreateEmbeddingRequest.md +22 -0
- data/docs/CreateEmbeddingRequestInput.md +53 -0
- data/docs/CreateEmbeddingRequestModel.md +47 -0
- data/docs/CreateEmbeddingResponse.md +24 -0
- data/docs/CreateEmbeddingResponseDataInner.md +22 -0
- data/docs/CreateEmbeddingResponseUsage.md +20 -0
- data/docs/CreateFineTuneRequest.md +40 -0
- data/docs/CreateFineTuneRequestModel.md +47 -0
- data/docs/CreateImageRequest.md +26 -0
- data/docs/CreateModerationRequest.md +20 -0
- data/docs/CreateModerationRequestInput.md +49 -0
- data/docs/CreateModerationRequestModel.md +47 -0
- data/docs/CreateModerationResponse.md +22 -0
- data/docs/CreateModerationResponseResultsInner.md +22 -0
- data/docs/CreateModerationResponseResultsInnerCategories.md +30 -0
- data/docs/CreateModerationResponseResultsInnerCategoryScores.md +30 -0
- data/docs/CreateTranscriptionRequestModel.md +47 -0
- data/docs/CreateTranscriptionResponse.md +18 -0
- data/docs/CreateTranslationResponse.md +18 -0
- data/docs/DeleteFileResponse.md +22 -0
- data/docs/DeleteModelResponse.md +22 -0
- data/docs/Error.md +24 -0
- data/docs/ErrorResponse.md +18 -0
- data/docs/FineTune.md +42 -0
- data/docs/FineTuneEvent.md +24 -0
- data/docs/ImagesResponse.md +20 -0
- data/docs/ImagesResponseDataInner.md +20 -0
- data/docs/ListFilesResponse.md +20 -0
- data/docs/ListFineTuneEventsResponse.md +20 -0
- data/docs/ListFineTunesResponse.md +20 -0
- data/docs/ListModelsResponse.md +20 -0
- data/docs/Model.md +24 -0
- data/docs/OpenAIApi.md +1499 -0
- data/docs/OpenAIFile.md +32 -0
- data/git_push.sh +57 -0
- data/lib/openapi_openai/api/open_ai_api.rb +1583 -0
- data/lib/openapi_openai/api_client.rb +393 -0
- data/lib/openapi_openai/api_error.rb +58 -0
- data/lib/openapi_openai/configuration.rb +291 -0
- data/lib/openapi_openai/models/chat_completion_functions.rb +244 -0
- data/lib/openapi_openai/models/chat_completion_request_message.rb +285 -0
- data/lib/openapi_openai/models/chat_completion_request_message_function_call.rb +226 -0
- data/lib/openapi_openai/models/chat_completion_response_message.rb +276 -0
- data/lib/openapi_openai/models/chat_completion_stream_response_delta.rb +269 -0
- data/lib/openapi_openai/models/create_chat_completion_request.rb +537 -0
- data/lib/openapi_openai/models/create_chat_completion_request_function_call.rb +106 -0
- data/lib/openapi_openai/models/create_chat_completion_request_function_call_one_of.rb +222 -0
- data/lib/openapi_openai/models/create_chat_completion_request_model.rb +105 -0
- data/lib/openapi_openai/models/create_chat_completion_request_stop.rb +106 -0
- data/lib/openapi_openai/models/create_chat_completion_response.rb +296 -0
- data/lib/openapi_openai/models/create_chat_completion_response_choices_inner.rb +266 -0
- data/lib/openapi_openai/models/create_chat_completion_stream_response.rb +287 -0
- data/lib/openapi_openai/models/create_chat_completion_stream_response_choices_inner.rb +266 -0
- data/lib/openapi_openai/models/create_completion_request.rb +586 -0
- data/lib/openapi_openai/models/create_completion_request_model.rb +105 -0
- data/lib/openapi_openai/models/create_completion_request_prompt.rb +108 -0
- data/lib/openapi_openai/models/create_completion_request_stop.rb +106 -0
- data/lib/openapi_openai/models/create_completion_response.rb +296 -0
- data/lib/openapi_openai/models/create_completion_response_choices_inner.rb +299 -0
- data/lib/openapi_openai/models/create_completion_response_choices_inner_logprobs.rb +249 -0
- data/lib/openapi_openai/models/create_completion_response_usage.rb +253 -0
- data/lib/openapi_openai/models/create_edit_request.rb +362 -0
- data/lib/openapi_openai/models/create_edit_request_model.rb +105 -0
- data/lib/openapi_openai/models/create_edit_response.rb +271 -0
- data/lib/openapi_openai/models/create_edit_response_choices_inner.rb +276 -0
- data/lib/openapi_openai/models/create_embedding_request.rb +247 -0
- data/lib/openapi_openai/models/create_embedding_request_input.rb +108 -0
- data/lib/openapi_openai/models/create_embedding_request_model.rb +105 -0
- data/lib/openapi_openai/models/create_embedding_response.rb +271 -0
- data/lib/openapi_openai/models/create_embedding_response_data_inner.rb +255 -0
- data/lib/openapi_openai/models/create_embedding_response_usage.rb +237 -0
- data/lib/openapi_openai/models/create_fine_tune_request.rb +374 -0
- data/lib/openapi_openai/models/create_fine_tune_request_model.rb +105 -0
- data/lib/openapi_openai/models/create_image_request.rb +341 -0
- data/lib/openapi_openai/models/create_moderation_request.rb +230 -0
- data/lib/openapi_openai/models/create_moderation_request_input.rb +106 -0
- data/lib/openapi_openai/models/create_moderation_request_model.rb +105 -0
- data/lib/openapi_openai/models/create_moderation_response.rb +255 -0
- data/lib/openapi_openai/models/create_moderation_response_results_inner.rb +253 -0
- data/lib/openapi_openai/models/create_moderation_response_results_inner_categories.rb +317 -0
- data/lib/openapi_openai/models/create_moderation_response_results_inner_category_scores.rb +317 -0
- data/lib/openapi_openai/models/create_transcription_request_model.rb +105 -0
- data/lib/openapi_openai/models/create_transcription_response.rb +221 -0
- data/lib/openapi_openai/models/create_translation_response.rb +221 -0
- data/lib/openapi_openai/models/delete_file_response.rb +253 -0
- data/lib/openapi_openai/models/delete_model_response.rb +253 -0
- data/lib/openapi_openai/models/error.rb +261 -0
- data/lib/openapi_openai/models/error_response.rb +221 -0
- data/lib/openapi_openai/models/fine_tune.rb +410 -0
- data/lib/openapi_openai/models/fine_tune_event.rb +269 -0
- data/lib/openapi_openai/models/images_response.rb +239 -0
- data/lib/openapi_openai/models/images_response_data_inner.rb +223 -0
- data/lib/openapi_openai/models/list_files_response.rb +239 -0
- data/lib/openapi_openai/models/list_fine_tune_events_response.rb +239 -0
- data/lib/openapi_openai/models/list_fine_tunes_response.rb +239 -0
- data/lib/openapi_openai/models/list_models_response.rb +239 -0
- data/lib/openapi_openai/models/model.rb +269 -0
- data/lib/openapi_openai/models/open_ai_file.rb +320 -0
- data/lib/openapi_openai/version.rb +15 -0
- data/lib/openapi_openai.rb +99 -0
- data/openapi_openai.gemspec +39 -0
- data/spec/api/open_ai_api_spec.rb +306 -0
- data/spec/models/chat_completion_functions_spec.rb +48 -0
- data/spec/models/chat_completion_request_message_function_call_spec.rb +42 -0
- data/spec/models/chat_completion_request_message_spec.rb +58 -0
- data/spec/models/chat_completion_response_message_spec.rb +52 -0
- data/spec/models/chat_completion_stream_response_delta_spec.rb +52 -0
- data/spec/models/create_chat_completion_request_function_call_one_of_spec.rb +36 -0
- data/spec/models/create_chat_completion_request_function_call_spec.rb +32 -0
- data/spec/models/create_chat_completion_request_model_spec.rb +32 -0
- data/spec/models/create_chat_completion_request_spec.rb +114 -0
- data/spec/models/create_chat_completion_request_stop_spec.rb +32 -0
- data/spec/models/create_chat_completion_response_choices_inner_spec.rb +52 -0
- data/spec/models/create_chat_completion_response_spec.rb +66 -0
- data/spec/models/create_chat_completion_stream_response_choices_inner_spec.rb +52 -0
- data/spec/models/create_chat_completion_stream_response_spec.rb +60 -0
- data/spec/models/create_completion_request_model_spec.rb +32 -0
- data/spec/models/create_completion_request_prompt_spec.rb +32 -0
- data/spec/models/create_completion_request_spec.rb +126 -0
- data/spec/models/create_completion_request_stop_spec.rb +32 -0
- data/spec/models/create_completion_response_choices_inner_logprobs_spec.rb +54 -0
- data/spec/models/create_completion_response_choices_inner_spec.rb +58 -0
- data/spec/models/create_completion_response_spec.rb +66 -0
- data/spec/models/create_completion_response_usage_spec.rb +48 -0
- data/spec/models/create_edit_request_model_spec.rb +32 -0
- data/spec/models/create_edit_request_spec.rb +66 -0
- data/spec/models/create_edit_response_choices_inner_spec.rb +58 -0
- data/spec/models/create_edit_response_spec.rb +54 -0
- data/spec/models/create_embedding_request_input_spec.rb +32 -0
- data/spec/models/create_embedding_request_model_spec.rb +32 -0
- data/spec/models/create_embedding_request_spec.rb +48 -0
- data/spec/models/create_embedding_response_data_inner_spec.rb +48 -0
- data/spec/models/create_embedding_response_spec.rb +54 -0
- data/spec/models/create_embedding_response_usage_spec.rb +42 -0
- data/spec/models/create_fine_tune_request_model_spec.rb +32 -0
- data/spec/models/create_fine_tune_request_spec.rb +102 -0
- data/spec/models/create_image_request_spec.rb +68 -0
- data/spec/models/create_moderation_request_input_spec.rb +32 -0
- data/spec/models/create_moderation_request_model_spec.rb +32 -0
- data/spec/models/create_moderation_request_spec.rb +42 -0
- data/spec/models/create_moderation_response_results_inner_categories_spec.rb +72 -0
- data/spec/models/create_moderation_response_results_inner_category_scores_spec.rb +72 -0
- data/spec/models/create_moderation_response_results_inner_spec.rb +48 -0
- data/spec/models/create_moderation_response_spec.rb +48 -0
- data/spec/models/create_transcription_request_model_spec.rb +32 -0
- data/spec/models/create_transcription_response_spec.rb +36 -0
- data/spec/models/create_translation_response_spec.rb +36 -0
- data/spec/models/delete_file_response_spec.rb +48 -0
- data/spec/models/delete_model_response_spec.rb +48 -0
- data/spec/models/error_response_spec.rb +36 -0
- data/spec/models/error_spec.rb +54 -0
- data/spec/models/fine_tune_event_spec.rb +54 -0
- data/spec/models/fine_tune_spec.rb +108 -0
- data/spec/models/images_response_data_inner_spec.rb +42 -0
- data/spec/models/images_response_spec.rb +42 -0
- data/spec/models/list_files_response_spec.rb +42 -0
- data/spec/models/list_fine_tune_events_response_spec.rb +42 -0
- data/spec/models/list_fine_tunes_response_spec.rb +42 -0
- data/spec/models/list_models_response_spec.rb +42 -0
- data/spec/models/model_spec.rb +54 -0
- data/spec/models/open_ai_file_spec.rb +78 -0
- data/spec/spec_helper.rb +111 -0
- metadata +348 -0
@@ -0,0 +1,108 @@
|
|
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
|
+
# The prompt(s) to generate completions for, encoded as a string, array of strings, array of tokens, or array of token arrays. Note that <|endoftext|> is the document separator that the model sees during training, so if a prompt is not specified the model will generate as if from the beginning of a new document.
|
18
|
+
module CreateCompletionRequestPrompt
|
19
|
+
class << self
|
20
|
+
# List of class defined in oneOf (OpenAPI v3)
|
21
|
+
def openapi_one_of
|
22
|
+
[
|
23
|
+
:'Array<Array<Integer>>',
|
24
|
+
:'Array<Integer>',
|
25
|
+
:'Array<String>',
|
26
|
+
:'String'
|
27
|
+
]
|
28
|
+
end
|
29
|
+
|
30
|
+
# Builds the object
|
31
|
+
# @param [Mixed] Data to be matched against the list of oneOf items
|
32
|
+
# @return [Object] Returns the model or the data itself
|
33
|
+
def build(data)
|
34
|
+
# Go through the list of oneOf items and attempt to identify the appropriate one.
|
35
|
+
# Note:
|
36
|
+
# - We do not attempt to check whether exactly one item matches.
|
37
|
+
# - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
|
38
|
+
# due to the way the deserialization is made in the base_object template (it just casts without verifying).
|
39
|
+
# - TODO: scalar values are de facto behaving as if they were nullable.
|
40
|
+
# - TODO: logging when debugging is set.
|
41
|
+
openapi_one_of.each do |klass|
|
42
|
+
begin
|
43
|
+
next if klass == :AnyType # "nullable: true"
|
44
|
+
typed_data = find_and_cast_into_type(klass, data)
|
45
|
+
return typed_data if typed_data
|
46
|
+
rescue # rescue all errors so we keep iterating even if the current item lookup raises
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
openapi_one_of.include?(:AnyType) ? data : nil
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
SchemaMismatchError = Class.new(StandardError)
|
56
|
+
|
57
|
+
# Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
|
58
|
+
def find_and_cast_into_type(klass, data)
|
59
|
+
return if data.nil?
|
60
|
+
|
61
|
+
case klass.to_s
|
62
|
+
when 'Boolean'
|
63
|
+
return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
|
64
|
+
when 'Float'
|
65
|
+
return data if data.instance_of?(Float)
|
66
|
+
when 'Integer'
|
67
|
+
return data if data.instance_of?(Integer)
|
68
|
+
when 'Time'
|
69
|
+
return Time.parse(data)
|
70
|
+
when 'Date'
|
71
|
+
return Date.parse(data)
|
72
|
+
when 'String'
|
73
|
+
return data if data.instance_of?(String)
|
74
|
+
when 'Object' # "type: object"
|
75
|
+
return data if data.instance_of?(Hash)
|
76
|
+
when /\AArray<(?<sub_type>.+)>\z/ # "type: array"
|
77
|
+
if data.instance_of?(Array)
|
78
|
+
sub_type = Regexp.last_match[:sub_type]
|
79
|
+
return data.map { |item| find_and_cast_into_type(sub_type, item) }
|
80
|
+
end
|
81
|
+
when /\AHash<String, (?<sub_type>.+)>\z/ # "type: object" with "additionalProperties: { ... }"
|
82
|
+
if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
|
83
|
+
sub_type = Regexp.last_match[:sub_type]
|
84
|
+
return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
|
85
|
+
end
|
86
|
+
else # model
|
87
|
+
const = OpenApiOpenAIClient.const_get(klass)
|
88
|
+
if const
|
89
|
+
if const.respond_to?(:openapi_one_of) # nested oneOf model
|
90
|
+
model = const.build(data)
|
91
|
+
return model if model
|
92
|
+
else
|
93
|
+
# raise if data contains keys that are not known to the model
|
94
|
+
raise if const.respond_to?(:acceptable_attributes) && !(data.keys - const.acceptable_attributes).empty?
|
95
|
+
model = const.build_from_hash(data)
|
96
|
+
return model if model
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
raise # if no match by now, raise
|
102
|
+
rescue
|
103
|
+
raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
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
|
+
# Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.
|
18
|
+
module CreateCompletionRequestStop
|
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 = 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
|
@@ -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 CreateCompletionResponse
|
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<CreateCompletionResponseChoicesInner>',
|
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::CreateCompletionResponse` 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::CreateCompletionResponse`. 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
|