azure_openai_client 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +178 -0
  3. data/lib/azure_openai_client/api/default_api.rb +232 -0
  4. data/lib/azure_openai_client/api_client.rb +390 -0
  5. data/lib/azure_openai_client/api_error.rb +58 -0
  6. data/lib/azure_openai_client/configuration.rb +214 -0
  7. data/lib/azure_openai_client/models/chat_completions_body.rb +334 -0
  8. data/lib/azure_openai_client/models/deploymentid_completions_body.rb +406 -0
  9. data/lib/azure_openai_client/models/deploymentid_embeddings_body.rb +202 -0
  10. data/lib/azure_openai_client/models/deploymentsdeploymentidchatcompletions_messages.rb +274 -0
  11. data/lib/azure_openai_client/models/error_response.rb +209 -0
  12. data/lib/azure_openai_client/models/error_response_error.rb +236 -0
  13. data/lib/azure_openai_client/models/inline_response_200.rb +281 -0
  14. data/lib/azure_openai_client/models/inline_response_200_1.rb +258 -0
  15. data/lib/azure_openai_client/models/inline_response_200_1_data.rb +244 -0
  16. data/lib/azure_openai_client/models/inline_response_200_1_usage.rb +228 -0
  17. data/lib/azure_openai_client/models/inline_response_200_2.rb +281 -0
  18. data/lib/azure_openai_client/models/inline_response_200_2_choices.rb +227 -0
  19. data/lib/azure_openai_client/models/inline_response_200_2_message.rb +264 -0
  20. data/lib/azure_openai_client/models/inline_response_200_2_usage.rb +242 -0
  21. data/lib/azure_openai_client/models/inline_response_200_choices.rb +236 -0
  22. data/lib/azure_openai_client/models/inline_response_200_logprobs.rb +244 -0
  23. data/lib/azure_openai_client/models/inline_response_200_usage.rb +242 -0
  24. data/lib/azure_openai_client/models/one_ofchat_completions_body_stop.rb +198 -0
  25. data/lib/azure_openai_client/models/one_ofdeploymentid_completions_body_prompt.rb +198 -0
  26. data/lib/azure_openai_client/models/one_ofdeploymentid_completions_body_stop.rb +198 -0
  27. data/lib/azure_openai_client/version.rb +16 -0
  28. data/lib/azure_openai_client.rb +61 -0
  29. data/spec/api/default_api_spec.rb +75 -0
  30. data/spec/api_client_spec.rb +229 -0
  31. data/spec/configuration_spec.rb +78 -0
  32. data/spec/models/chat_completions_body_spec.rb +102 -0
  33. data/spec/models/deploymentid_completions_body_spec.rb +144 -0
  34. data/spec/models/deploymentid_embeddings_body_spec.rb +36 -0
  35. data/spec/models/deploymentsdeploymentidchatcompletions_messages_spec.rb +58 -0
  36. data/spec/models/error_response_error_spec.rb +60 -0
  37. data/spec/models/error_response_spec.rb +42 -0
  38. data/spec/models/inline_response_200_1_data_spec.rb +54 -0
  39. data/spec/models/inline_response_200_1_spec.rb +60 -0
  40. data/spec/models/inline_response_200_1_usage_spec.rb +48 -0
  41. data/spec/models/inline_response_200_2_choices_spec.rb +54 -0
  42. data/spec/models/inline_response_200_2_message_spec.rb +52 -0
  43. data/spec/models/inline_response_200_2_spec.rb +72 -0
  44. data/spec/models/inline_response_200_2_usage_spec.rb +54 -0
  45. data/spec/models/inline_response_200_choices_spec.rb +60 -0
  46. data/spec/models/inline_response_200_logprobs_spec.rb +60 -0
  47. data/spec/models/inline_response_200_spec.rb +72 -0
  48. data/spec/models/inline_response_200_usage_spec.rb +54 -0
  49. data/spec/models/one_ofchat_completions_body_stop_spec.rb +36 -0
  50. data/spec/models/one_ofdeploymentid_completions_body_prompt_spec.rb +36 -0
  51. data/spec/models/one_ofdeploymentid_completions_body_stop_spec.rb +36 -0
  52. data/spec/spec_helper.rb +112 -0
  53. metadata +177 -0
@@ -0,0 +1,198 @@
1
+ # frozen_string_literal: true
2
+
3
+ =begin
4
+ #Azure OpenAI Service API
5
+
6
+ #Azure OpenAI APIs for completions and search
7
+
8
+ OpenAPI spec version: 2023-05-15
9
+
10
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
11
+ Swagger Codegen version: 3.0.42
12
+ =end
13
+
14
+ require 'date'
15
+
16
+ module AzureOpenaiClient
17
+ class OneOfdeploymentidCompletionsBodyStop
18
+ # Attribute mapping from ruby-style variable name to JSON key.
19
+ def self.attribute_map
20
+ {}
21
+ end
22
+
23
+ # Attribute type mapping.
24
+ def self.openapi_types
25
+ {}
26
+ end
27
+
28
+ # List of attributes with nullable: true
29
+ def self.openapi_nullable
30
+ Set.new([
31
+ ])
32
+ end
33
+
34
+ # Initializes the object
35
+ # @param [Hash] attributes Model attributes in the form of hash
36
+ def initialize(attributes = {})
37
+ if (!attributes.is_a?(Hash))
38
+ fail ArgumentError, "The input argument (attributes) must be a hash in `AzureOpenaiClient::OneOfdeploymentidCompletionsBodyStop` initialize method"
39
+ end
40
+
41
+ # check to see if the attribute exists and convert string to symbol for hash key
42
+ attributes = attributes.each_with_object({}) { |(k, v), h|
43
+ if (!self.class.attribute_map.key?(k.to_sym))
44
+ fail ArgumentError, "`#{k}` is not a valid attribute in `AzureOpenaiClient::OneOfdeploymentidCompletionsBodyStop`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
45
+ end
46
+ h[k.to_sym] = v
47
+ }
48
+ end
49
+
50
+ # Show invalid properties with the reasons. Usually used together with valid?
51
+ # @return Array for valid properties with the reasons
52
+ def list_invalid_properties
53
+ invalid_properties = Array.new
54
+ invalid_properties
55
+ end
56
+
57
+ # Check to see if the all the properties in the model are valid
58
+ # @return true if the model is valid
59
+ def valid?
60
+ true
61
+ end
62
+
63
+ # Checks equality by comparing each attribute.
64
+ # @param [Object] Object to be compared
65
+ def ==(o)
66
+ return true if self.equal?(o)
67
+ self.class == o.class
68
+ end
69
+
70
+ # @see the `==` method
71
+ # @param [Object] Object to be compared
72
+ def eql?(o)
73
+ self == o
74
+ end
75
+
76
+ # Calculates hash code according to all attributes.
77
+ # @return [Integer] Hash code
78
+ def hash
79
+ [].hash
80
+ end
81
+
82
+ # Builds the object from hash
83
+ # @param [Hash] attributes Model attributes in the form of hash
84
+ # @return [Object] Returns the model itself
85
+ def self.build_from_hash(attributes)
86
+ new.build_from_hash(attributes)
87
+ end
88
+
89
+ # Builds the object from hash
90
+ # @param [Hash] attributes Model attributes in the form of hash
91
+ # @return [Object] Returns the model itself
92
+ def build_from_hash(attributes)
93
+ return nil unless attributes.is_a?(Hash)
94
+ self.class.openapi_types.each_pair do |key, type|
95
+ if type =~ /\AArray<(.*)>/i
96
+ # check to ensure the input is an array given that the attribute
97
+ # is documented as an array but the input is not
98
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
99
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
100
+ end
101
+ elsif !attributes[self.class.attribute_map[key]].nil?
102
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
103
+ elsif attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
104
+ self.send("#{key}=", nil)
105
+ end
106
+ end
107
+
108
+ self
109
+ end
110
+
111
+ # Deserializes the data based on type
112
+ # @param string type Data type
113
+ # @param string value Value to be deserialized
114
+ # @return [Object] Deserialized data
115
+ def _deserialize(type, value)
116
+ case type.to_sym
117
+ when :DateTime
118
+ DateTime.parse(value)
119
+ when :Date
120
+ Date.parse(value)
121
+ when :String
122
+ value.to_s
123
+ when :Integer
124
+ value.to_i
125
+ when :Float
126
+ value.to_f
127
+ when :Boolean
128
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
129
+ true
130
+ else
131
+ false
132
+ end
133
+ when :Object
134
+ # generic object (usually a Hash), return directly
135
+ value
136
+ when /\AArray<(?<inner_type>.+)>\z/
137
+ inner_type = Regexp.last_match[:inner_type]
138
+ value.map { |v| _deserialize(inner_type, v) }
139
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
140
+ k_type = Regexp.last_match[:k_type]
141
+ v_type = Regexp.last_match[:v_type]
142
+ {}.tap do |hash|
143
+ value.each do |k, v|
144
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
145
+ end
146
+ end
147
+ else # model
148
+ AzureOpenaiClient.const_get(type).build_from_hash(value)
149
+ end
150
+ end
151
+
152
+ # Returns the string representation of the object
153
+ # @return [String] String presentation of the object
154
+ def to_s
155
+ to_hash.to_s
156
+ end
157
+
158
+ # to_body is an alias to to_hash (backward compatibility)
159
+ # @return [Hash] Returns the object in the form of hash
160
+ def to_body
161
+ to_hash
162
+ end
163
+
164
+ # Returns the object in the form of hash
165
+ # @return [Hash] Returns the object in the form of hash
166
+ def to_hash
167
+ hash = {}
168
+ self.class.attribute_map.each_pair do |attr, param|
169
+ value = self.send(attr)
170
+ if value.nil?
171
+ is_nullable = self.class.openapi_nullable.include?(attr)
172
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
173
+ end
174
+
175
+ hash[param] = _to_hash(value)
176
+ end
177
+ hash
178
+ end
179
+
180
+ # Outputs non-array value in the form of hash
181
+ # For object, use to_hash. Otherwise, just return the value
182
+ # @param [Object] value Any valid value
183
+ # @return [Hash] Returns the value in the form of hash
184
+ def _to_hash(value)
185
+ if value.is_a?(Array)
186
+ value.compact.map { |v| _to_hash(v) }
187
+ elsif value.is_a?(Hash)
188
+ {}.tap do |hash|
189
+ value.each { |k, v| hash[k] = _to_hash(v) }
190
+ end
191
+ elsif value.respond_to? :to_hash
192
+ value.to_hash
193
+ else
194
+ value
195
+ end
196
+ end
197
+ end
198
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ =begin
4
+ #Azure OpenAI Service API
5
+
6
+ #Azure OpenAI APIs for completions and search
7
+
8
+ OpenAPI spec version: 2023-05-15
9
+
10
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
11
+ Swagger Codegen version: 3.0.42
12
+ =end
13
+
14
+ module AzureOpenaiClient
15
+ VERSION = '0.0.1'
16
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ =begin
4
+ #Azure OpenAI Service API
5
+
6
+ #Azure OpenAI APIs for completions and search
7
+
8
+ OpenAPI spec version: 2023-05-15
9
+
10
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
11
+ Swagger Codegen version: 3.0.42
12
+ =end
13
+
14
+ # Common files
15
+ require 'azure_openai_client/api_client'
16
+ require 'azure_openai_client/api_error'
17
+ require 'azure_openai_client/version'
18
+ require 'azure_openai_client/configuration'
19
+
20
+ # Models
21
+ require 'azure_openai_client/models/chat_completions_body'
22
+ require 'azure_openai_client/models/deploymentid_completions_body'
23
+ require 'azure_openai_client/models/deploymentid_embeddings_body'
24
+ require 'azure_openai_client/models/deploymentsdeploymentidchatcompletions_messages'
25
+ require 'azure_openai_client/models/error_response'
26
+ require 'azure_openai_client/models/error_response_error'
27
+ require 'azure_openai_client/models/inline_response_200'
28
+ require 'azure_openai_client/models/inline_response_200_1'
29
+ require 'azure_openai_client/models/inline_response_200_1_data'
30
+ require 'azure_openai_client/models/inline_response_200_1_usage'
31
+ require 'azure_openai_client/models/inline_response_200_2'
32
+ require 'azure_openai_client/models/inline_response_200_2_choices'
33
+ require 'azure_openai_client/models/inline_response_200_2_message'
34
+ require 'azure_openai_client/models/inline_response_200_2_usage'
35
+ require 'azure_openai_client/models/inline_response_200_choices'
36
+ require 'azure_openai_client/models/inline_response_200_logprobs'
37
+ require 'azure_openai_client/models/inline_response_200_usage'
38
+ require 'azure_openai_client/models/one_ofchat_completions_body_stop'
39
+ require 'azure_openai_client/models/one_ofdeploymentid_completions_body_prompt'
40
+ require 'azure_openai_client/models/one_ofdeploymentid_completions_body_stop'
41
+
42
+ # APIs
43
+ require 'azure_openai_client/api/default_api'
44
+
45
+ module AzureOpenaiClient
46
+ class << self
47
+ # Customize default settings for the SDK using block.
48
+ # AzureOpenaiClient.configure do |config|
49
+ # config.username = "xxx"
50
+ # config.password = "xxx"
51
+ # end
52
+ # If no block given, return the default Configuration object.
53
+ def configure
54
+ if block_given?
55
+ yield(Configuration.default)
56
+ else
57
+ Configuration.default
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ =begin
4
+ #Azure OpenAI Service API
5
+
6
+ #Azure OpenAI APIs for completions and search
7
+
8
+ OpenAPI spec version: 2023-05-15
9
+
10
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
11
+ Swagger Codegen version: 3.0.42
12
+ =end
13
+
14
+ require 'spec_helper'
15
+ require 'json'
16
+
17
+ # Unit tests for AzureOpenaiClient::DefaultApi
18
+ # Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
19
+ # Please update as you see appropriate
20
+ describe 'DefaultApi' do
21
+ before do
22
+ # run before each test
23
+ @instance = AzureOpenaiClient::DefaultApi.new
24
+ end
25
+
26
+ after do
27
+ # run after each test
28
+ end
29
+
30
+ describe 'test an instance of DefaultApi' do
31
+ it 'should create an instance of DefaultApi' do
32
+ expect(@instance).to be_instance_of(AzureOpenaiClient::DefaultApi)
33
+ end
34
+ end
35
+
36
+ # unit tests for chat_completions_create
37
+ # Creates a completion for the chat message
38
+ # @param body
39
+ # @param api_version
40
+ # @param deployment_id
41
+ # @param [Hash] opts the optional parameters
42
+ # @return [InlineResponse2002]
43
+ describe 'chat_completions_create test' do
44
+ it 'should work' do
45
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
46
+ end
47
+ end
48
+
49
+ # unit tests for completions_create
50
+ # Creates a completion for the provided prompt, parameters and chosen model.
51
+ # @param body
52
+ # @param api_version
53
+ # @param deployment_id
54
+ # @param [Hash] opts the optional parameters
55
+ # @return [InlineResponse200]
56
+ describe 'completions_create test' do
57
+ it 'should work' do
58
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
59
+ end
60
+ end
61
+
62
+ # unit tests for embeddings_create
63
+ # Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.
64
+ # @param body
65
+ # @param api_version
66
+ # @param deployment_id The deployment id of the model which was deployed.
67
+ # @param [Hash] opts the optional parameters
68
+ # @return [InlineResponse2001]
69
+ describe 'embeddings_create test' do
70
+ it 'should work' do
71
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
72
+ end
73
+ end
74
+
75
+ end
@@ -0,0 +1,229 @@
1
+ # frozen_string_literal: true
2
+
3
+ =begin
4
+ #Azure OpenAI Service API
5
+
6
+ #Azure OpenAI APIs for completions and search
7
+
8
+ OpenAPI spec version: 2023-05-15
9
+
10
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
11
+ Swagger Codegen version: 3.0.42
12
+ =end
13
+
14
+ require 'spec_helper'
15
+
16
+ describe AzureOpenaiClient::ApiClient do
17
+ context 'initialization' do
18
+ context 'URL stuff' do
19
+ context 'host' do
20
+ it 'removes http from host' do
21
+ AzureOpenaiClient.configure { |c| c.host = 'http://example.com' }
22
+ expect(AzureOpenaiClient::Configuration.default.host).to eq('example.com')
23
+ end
24
+
25
+ it 'removes https from host' do
26
+ AzureOpenaiClient.configure { |c| c.host = 'https://wookiee.com' }
27
+ expect(AzureOpenaiClient::ApiClient.default.config.host).to eq('wookiee.com')
28
+ end
29
+
30
+ it 'removes trailing path from host' do
31
+ AzureOpenaiClient.configure { |c| c.host = 'hobo.com/v4' }
32
+ expect(AzureOpenaiClient::Configuration.default.host).to eq('hobo.com')
33
+ end
34
+ end
35
+
36
+ context 'base_path' do
37
+ it "prepends a slash to base_path" do
38
+ AzureOpenaiClient.configure { |c| c.base_path = 'v4/dog' }
39
+ expect(AzureOpenaiClient::Configuration.default.base_path).to eq('/v4/dog')
40
+ end
41
+
42
+ it "doesn't prepend a slash if one is already there" do
43
+ AzureOpenaiClient.configure { |c| c.base_path = '/v4/dog' }
44
+ expect(AzureOpenaiClient::Configuration.default.base_path).to eq('/v4/dog')
45
+ end
46
+
47
+ it "ends up as a blank string if nil" do
48
+ AzureOpenaiClient.configure { |c| c.base_path = nil }
49
+ expect(AzureOpenaiClient::Configuration.default.base_path).to eq('')
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ describe 'params_encoding in #build_request' do
56
+ let(:config) { AzureOpenaiClient::Configuration.new }
57
+ let(:api_client) { AzureOpenaiClient::ApiClient.new(config) }
58
+
59
+ it 'defaults to nil' do
60
+ expect(AzureOpenaiClient::Configuration.default.params_encoding).to eq(nil)
61
+ expect(config.params_encoding).to eq(nil)
62
+
63
+ request = api_client.build_request(:get, '/test')
64
+ expect(request.options[:params_encoding]).to eq(nil)
65
+ end
66
+
67
+ it 'can be customized' do
68
+ config.params_encoding = :multi
69
+ request = api_client.build_request(:get, '/test')
70
+ expect(request.options[:params_encoding]).to eq(:multi)
71
+ end
72
+ end
73
+
74
+ describe 'timeout in #build_request' do
75
+ let(:config) { AzureOpenaiClient::Configuration.new }
76
+ let(:api_client) { AzureOpenaiClient::ApiClient.new(config) }
77
+
78
+ it 'defaults to 0' do
79
+ expect(AzureOpenaiClient::Configuration.default.timeout).to eq(0)
80
+ expect(config.timeout).to eq(0)
81
+
82
+ request = api_client.build_request(:get, '/test')
83
+ expect(request.options[:timeout]).to eq(0)
84
+ end
85
+
86
+ it 'can be customized' do
87
+ config.timeout = 100
88
+ request = api_client.build_request(:get, '/test')
89
+ expect(request.options[:timeout]).to eq(100)
90
+ end
91
+ end
92
+
93
+ describe '#deserialize' do
94
+ it "handles Array<Integer>" do
95
+ api_client = AzureOpenaiClient::ApiClient.new
96
+ headers = { 'Content-Type' => 'application/json' }
97
+ response = double('response', headers: headers, body: '[12, 34]')
98
+ data = api_client.deserialize(response, 'Array<Integer>')
99
+ expect(data).to be_instance_of(Array)
100
+ expect(data).to eq([12, 34])
101
+ end
102
+
103
+ it 'handles Array<Array<Integer>>' do
104
+ api_client = AzureOpenaiClient::ApiClient.new
105
+ headers = { 'Content-Type' => 'application/json' }
106
+ response = double('response', headers: headers, body: '[[12, 34], [56]]')
107
+ data = api_client.deserialize(response, 'Array<Array<Integer>>')
108
+ expect(data).to be_instance_of(Array)
109
+ expect(data).to eq([[12, 34], [56]])
110
+ end
111
+
112
+ it 'handles Hash<String, String>' do
113
+ api_client = AzureOpenaiClient::ApiClient.new
114
+ headers = { 'Content-Type' => 'application/json' }
115
+ response = double('response', headers: headers, body: '{"message": "Hello"}')
116
+ data = api_client.deserialize(response, 'Hash<String, String>')
117
+ expect(data).to be_instance_of(Hash)
118
+ expect(data).to eq(message: 'Hello')
119
+ end
120
+ end
121
+
122
+ describe "#object_to_hash" do
123
+ it 'ignores nils and includes empty arrays' do
124
+ # uncomment below to test object_to_hash for model
125
+ api_client = AzureOpenaiClient::ApiClient.new
126
+ _model = AzureOpenaiClient::InlineResponse200.new
127
+ # update the model attribute below
128
+ _model.id = 1
129
+ # update the expected value (hash) below
130
+ expected = { id: 1 }
131
+ expect(api_client.object_to_hash(_model)).to eq(expected)
132
+ end
133
+ end
134
+
135
+ describe '#build_collection_param' do
136
+ let(:param) { ['aa', 'bb', 'cc'] }
137
+ let(:api_client) { AzureOpenaiClient::ApiClient.new }
138
+
139
+ it 'works for csv' do
140
+ expect(api_client.build_collection_param(param, :csv)).to eq('aa,bb,cc')
141
+ end
142
+
143
+ it 'works for ssv' do
144
+ expect(api_client.build_collection_param(param, :ssv)).to eq('aa bb cc')
145
+ end
146
+
147
+ it 'works for tsv' do
148
+ expect(api_client.build_collection_param(param, :tsv)).to eq("aa\tbb\tcc")
149
+ end
150
+
151
+ it 'works for pipes' do
152
+ expect(api_client.build_collection_param(param, :pipes)).to eq('aa|bb|cc')
153
+ end
154
+
155
+ it 'works for multi' do
156
+ expect(api_client.build_collection_param(param, :multi)).to eq(['aa', 'bb', 'cc'])
157
+ end
158
+
159
+ it 'fails for invalid collection format' do
160
+ expect {
161
+ api_client.build_collection_param(param, :INVALID)
162
+ }.to raise_error(RuntimeError, 'unknown collection format: :INVALID')
163
+ end
164
+ end
165
+
166
+ describe '#json_mime?' do
167
+ let(:api_client) { AzureOpenaiClient::ApiClient.new }
168
+
169
+ it 'works' do
170
+ expect(api_client.json_mime?(nil)).to eq false
171
+ expect(api_client.json_mime?('')).to eq false
172
+
173
+ expect(api_client.json_mime?('application/json')).to eq true
174
+ expect(api_client.json_mime?('application/json; charset=UTF8')).to eq true
175
+ expect(api_client.json_mime?('APPLICATION/JSON')).to eq true
176
+
177
+ expect(api_client.json_mime?('application/xml')).to eq false
178
+ expect(api_client.json_mime?('text/plain')).to eq false
179
+ expect(api_client.json_mime?('application/jsonp')).to eq false
180
+ end
181
+ end
182
+
183
+ describe '#select_header_accept' do
184
+ let(:api_client) { AzureOpenaiClient::ApiClient.new }
185
+
186
+ it 'works' do
187
+ expect(api_client.select_header_accept(nil)).to be_nil
188
+ expect(api_client.select_header_accept([])).to be_nil
189
+
190
+ expect(api_client.select_header_accept(['application/json'])).to eq('application/json')
191
+ expect(api_client.select_header_accept(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
192
+ expect(api_client.select_header_accept(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
193
+
194
+ expect(api_client.select_header_accept(['application/xml'])).to eq('application/xml')
195
+ expect(api_client.select_header_accept(['text/html', 'application/xml'])).to eq('text/html,application/xml')
196
+ end
197
+ end
198
+
199
+ describe '#select_header_content_type' do
200
+ let(:api_client) { AzureOpenaiClient::ApiClient.new }
201
+
202
+ it 'works' do
203
+ expect(api_client.select_header_content_type(nil)).to eq('application/json')
204
+ expect(api_client.select_header_content_type([])).to eq('application/json')
205
+
206
+ expect(api_client.select_header_content_type(['application/json'])).to eq('application/json')
207
+ expect(api_client.select_header_content_type(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
208
+ expect(api_client.select_header_content_type(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
209
+ expect(api_client.select_header_content_type(['application/xml'])).to eq('application/xml')
210
+ expect(api_client.select_header_content_type(['text/plain', 'application/xml'])).to eq('text/plain')
211
+ end
212
+ end
213
+
214
+ describe '#sanitize_filename' do
215
+ let(:api_client) { AzureOpenaiClient::ApiClient.new }
216
+
217
+ it 'works' do
218
+ expect(api_client.sanitize_filename('sun')).to eq('sun')
219
+ expect(api_client.sanitize_filename('sun.gif')).to eq('sun.gif')
220
+ expect(api_client.sanitize_filename('../sun.gif')).to eq('sun.gif')
221
+ expect(api_client.sanitize_filename('/var/tmp/sun.gif')).to eq('sun.gif')
222
+ expect(api_client.sanitize_filename('./sun.gif')).to eq('sun.gif')
223
+ expect(api_client.sanitize_filename('..\sun.gif')).to eq('sun.gif')
224
+ expect(api_client.sanitize_filename('\var\tmp\sun.gif')).to eq('sun.gif')
225
+ expect(api_client.sanitize_filename('c:\var\tmp\sun.gif')).to eq('sun.gif')
226
+ expect(api_client.sanitize_filename('.\sun.gif')).to eq('sun.gif')
227
+ end
228
+ end
229
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe AzureOpenaiClient::Configuration do
6
+ let(:config) { AzureOpenaiClient::Configuration.new }
7
+
8
+ describe '#initialize' do
9
+ it 'sets default values' do
10
+ expect(config.scheme).to eq('https')
11
+ expect(config.host).to eq('{endpoint}')
12
+ expect(config.base_path).to eq('https://{endpoint}/openai')
13
+ expect(config.api_key).to eq({})
14
+ expect(config.api_key_prefix).to eq({})
15
+ expect(config.timeout).to eq(0)
16
+ expect(config.client_side_validation).to be(true)
17
+ expect(config.verify_ssl).to be(true)
18
+ expect(config.verify_ssl_host).to be(true)
19
+ expect(config.params_encoding).to be_nil
20
+ expect(config.cert_file).to be_nil
21
+ expect(config.key_file).to be_nil
22
+ expect(config.debugging).to be(false)
23
+ expect(config.inject_format).to be(false)
24
+ expect(config.force_ending_format).to be(false)
25
+ end
26
+ end
27
+
28
+ describe '#base_url' do
29
+ it 'returns the base URL with the correct scheme, host, and base_path' do
30
+ config.scheme = 'https'
31
+ config.host = 'example.com'
32
+ config.base_path = '/openai'
33
+ expect(config.base_url).to eq('https://example.com/openai')
34
+ end
35
+ end
36
+
37
+ describe '#api_key_with_prefix' do
38
+ it 'returns the API key with prefix if set' do
39
+ config.api_key['api_key'] = '12345'
40
+ config.api_key_prefix['api_key'] = 'Token'
41
+ expect(config.api_key_with_prefix('api_key')).to eq('Token 12345')
42
+ end
43
+
44
+ it 'returns the API key without prefix if not set' do
45
+ config.api_key['api_key'] = '12345'
46
+ expect(config.api_key_with_prefix('api_key')).to eq('12345')
47
+ end
48
+ end
49
+
50
+ describe '#basic_auth_token' do
51
+ it 'returns the Basic Auth token string' do
52
+ config.username = 'user'
53
+ config.password = 'pass'
54
+ expect(config.basic_auth_token).to eq('Basic dXNlcjpwYXNz')
55
+ end
56
+ end
57
+
58
+ describe '#auth_settings' do
59
+ it 'returns the Auth Settings hash for the API client' do
60
+ config.api_key['api-key'] = '12345'
61
+ config.access_token = 'token_12345'
62
+ expect(config.auth_settings).to eq(
63
+ 'apiKey' => {
64
+ type: 'api_key',
65
+ in: 'header',
66
+ key: 'api-key',
67
+ value: '12345'
68
+ },
69
+ 'bearer' => {
70
+ type: 'oauth2',
71
+ in: 'header',
72
+ key: 'Authorization',
73
+ value: 'Bearer token_12345'
74
+ }
75
+ )
76
+ end
77
+ end
78
+ end