azure_openai_client 0.0.2 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 379feaf10b0834ca74ac805a7418ade7e55432db2c612e2e55576c484eaa6495
4
- data.tar.gz: a6682bb67eb79c92b83cf9e3b3c80d502b3a60b94fef61ee84c3f08f03163e10
3
+ metadata.gz: e524b4910243d2294d7380cda8e404ccfd821cd25f489958dd24c423c9c62b93
4
+ data.tar.gz: dde4d1f009eb750848f162bcf1a841f4ebe733acc77b552f3dc6c22721f1a9a0
5
5
  SHA512:
6
- metadata.gz: 1f0d01ca96b49e659895d5e8a5a77cd11e2f087afdb4616c4e196b4d3be297a543b99b4c16619d587251ff77f957c8327968bbee481ee34f92277e34af742f1c
7
- data.tar.gz: f3c133d55d2f49941e1cf578894aeb539e00da1d201059e16eec309ae3535411cb8ef3b574d7d6367f0c6758bb10b4fd0894693eba1274a4f684035cd7a188e8
6
+ metadata.gz: c38f185b839a54dabc88d2b7c12e89defec15741b3db823d5db9c2d50ff2a2502dc6ed9eb58688f1584d91c9519cd04a88975df8f13bdd60da30b87bbd42dc09
7
+ data.tar.gz: 9e0b71e064a9616beddb65e27cd16cfda216020e99f276abe8dc17b90198787ce4f1c0a222b5896a0e68eaa95c214d13cff5d593684bbdb2d6c2f6b615d36180
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- azure_openai_client (0.0.2)
5
- typhoeus (~> 1.0, >= 1.0.1)
4
+ azure_openai_client (0.0.4)
5
+ faraday (>= 1.0.1, < 3.0)
6
+ faraday-multipart
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
@@ -11,11 +12,30 @@ GEM
11
12
  byebug (11.1.3)
12
13
  coderay (1.1.3)
13
14
  diff-lcs (1.5.0)
14
- ethon (0.16.0)
15
- ffi (>= 1.15.0)
16
- ffi (1.15.5)
15
+ faraday (1.8.0)
16
+ faraday-em_http (~> 1.0)
17
+ faraday-em_synchrony (~> 1.0)
18
+ faraday-excon (~> 1.1)
19
+ faraday-httpclient (~> 1.0.1)
20
+ faraday-net_http (~> 1.0)
21
+ faraday-net_http_persistent (~> 1.1)
22
+ faraday-patron (~> 1.0)
23
+ faraday-rack (~> 1.0)
24
+ multipart-post (>= 1.2, < 3)
25
+ ruby2_keywords (>= 0.0.4)
26
+ faraday-em_http (1.0.0)
27
+ faraday-em_synchrony (1.0.0)
28
+ faraday-excon (1.1.0)
29
+ faraday-httpclient (1.0.1)
30
+ faraday-multipart (1.0.4)
31
+ multipart-post (~> 2)
32
+ faraday-net_http (1.0.1)
33
+ faraday-net_http_persistent (1.2.0)
34
+ faraday-patron (1.0.0)
35
+ faraday-rack (1.0.0)
17
36
  json (2.6.3)
18
37
  method_source (1.0.0)
38
+ multipart-post (2.1.1)
19
39
  parallel (1.23.0)
20
40
  parser (3.2.2.1)
21
41
  ast (~> 2.4.1)
@@ -57,8 +77,7 @@ GEM
57
77
  rubocop-rspec (2.12.1)
58
78
  rubocop (~> 1.31)
59
79
  ruby-progressbar (1.13.0)
60
- typhoeus (1.4.0)
61
- ethon (>= 0.9.0)
80
+ ruby2_keywords (0.0.5)
62
81
  unicode-display_width (2.4.2)
63
82
 
64
83
  PLATFORMS
data/README.md CHANGED
@@ -7,7 +7,7 @@ Azure OpenAI APIs for completions and search
7
7
  This SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
8
8
 
9
9
  - API version: 2023-05-15
10
- - Package version: 0.0.2
10
+ - Package version: 0.0.4
11
11
  - Build package: org.openapitools.codegen.languages.RubyClientCodegen
12
12
 
13
13
  ## Installation
@@ -23,16 +23,16 @@ gem build azure_openai_client.gemspec
23
23
  Then either install the gem locally:
24
24
 
25
25
  ```shell
26
- gem install ./azure_openai_client-0.0.2.gem
26
+ gem install ./azure_openai_client-0.0.4.gem
27
27
  ```
28
28
 
29
- (for development, run `gem install --dev ./azure_openai_client-0.0.2.gem` to install the development dependencies)
29
+ (for development, run `gem install --dev ./azure_openai_client-0.0.4.gem` to install the development dependencies)
30
30
 
31
31
  or publish the gem to a gem hosting service, e.g. [RubyGems](https://rubygems.org/).
32
32
 
33
33
  Finally add this to the Gemfile:
34
34
 
35
- gem 'azure_openai_client', '~> 0.0.2'
35
+ gem 'azure_openai_client', '~> 0.0.4'
36
36
 
37
37
  ### Install from Git
38
38
 
@@ -62,11 +62,15 @@ AzureOpenaiClient.configure do |config|
62
62
  config.api_key['apiKey'] = 'YOUR API KEY'
63
63
  # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
64
64
  # config.api_key_prefix['apiKey'] = 'Bearer'
65
+ # Configure faraday connection
66
+ config.configure_faraday_connection { |connection| 'YOUR CONNECTION CONFIG PROC' }
65
67
 
66
68
  # Configure OAuth2 access token for authorization: bearer
67
69
  config.access_token = 'YOUR ACCESS TOKEN'
68
70
  # Configure a proc to get access tokens in lieu of the static access_token configuration
69
71
  config.access_token_getter = -> { 'YOUR TOKEN GETTER PROC' }
72
+ # Configure faraday connection
73
+ config.configure_faraday_connection { |connection| 'YOUR CONNECTION CONFIG PROC' }
70
74
  end
71
75
 
72
76
  api_instance = AzureOpenaiClient::DefaultApi.new
@@ -25,9 +25,10 @@ Gem::Specification.new do |s|
25
25
  s.summary = "Azure OpenAI Service API Ruby Gem"
26
26
  s.description = "Azure OpenAI APIs for completions and search"
27
27
  s.license = "MIT"
28
- s.required_ruby_version = ">= 2.7"
28
+ s.required_ruby_version = ">= 2.5"
29
29
 
30
- s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1'
30
+ s.add_runtime_dependency 'faraday', '>= 1.0.1', '< 3.0'
31
+ s.add_runtime_dependency 'faraday-multipart'
31
32
 
32
33
  s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0'
33
34
 
data/git_push.sh CHANGED
@@ -24,7 +24,7 @@ if [ "$git_repo_id" = "" ]; then
24
24
  fi
25
25
 
26
26
  if [ "$release_note" = "" ]; then
27
- release_note="Moving to openapi generator"
27
+ release_note="Downgrading required ruby version"
28
28
  echo "[INFO] No command line input provided. Set \$release_note to $release_note"
29
29
  fi
30
30
 
@@ -50,8 +50,4 @@ if [ "$git_remote" = "" ]; then # git remote not defined
50
50
 
51
51
  fi
52
52
 
53
- git pull origin master
54
-
55
- # Pushes (Forces) the changes in the local repository up to the remote repository
56
- echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
57
- git push origin master 2>&1 | grep -v 'To https'
53
+ git pull origin main
@@ -15,7 +15,8 @@ require 'json'
15
15
  require 'logger'
16
16
  require 'tempfile'
17
17
  require 'time'
18
- require 'typhoeus'
18
+ require 'faraday'
19
+ require 'faraday/multipart' if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
19
20
 
20
21
  module AzureOpenaiClient
21
22
  class ApiClient
@@ -47,26 +48,31 @@ module AzureOpenaiClient
47
48
  # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
48
49
  # the data deserialized from response body (could be nil), response status code and response headers.
49
50
  def call_api(http_method, path, opts = {})
50
- request = build_request(http_method, path, opts)
51
- response = request.run
51
+ begin
52
+ response = connection(opts).public_send(http_method.to_sym.downcase) do |req|
53
+ build_request(http_method, path, req, opts)
54
+ end
52
55
 
53
- if @config.debugging
54
- @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
55
- end
56
+ if config.debugging
57
+ config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
58
+ end
56
59
 
57
- unless response.success?
58
- if response.timed_out?
59
- fail ApiError.new('Connection timed out')
60
- elsif response.code == 0
61
- # Errors from libcurl will be made visible here
62
- fail ApiError.new(:code => 0,
63
- :message => response.return_message)
64
- else
65
- fail ApiError.new(:code => response.code,
66
- :response_headers => response.headers,
67
- :response_body => response.body),
68
- response.status_message
60
+ unless response.success?
61
+ if response.status == 0 && response.respond_to?(:return_message)
62
+ # Errors from libcurl will be made visible here
63
+ fail ApiError.new(code: 0,
64
+ message: response.return_message)
65
+ else
66
+ fail ApiError.new(code: response.status,
67
+ response_headers: response.headers,
68
+ response_body: response.body),
69
+ response.reason_phrase
70
+ end
69
71
  end
72
+ rescue Faraday::TimeoutError
73
+ fail ApiError.new('Connection timed out')
74
+ rescue Faraday::ConnectionFailed
75
+ fail ApiError.new('Connection failed')
70
76
  end
71
77
 
72
78
  if opts[:return_type]
@@ -74,7 +80,7 @@ module AzureOpenaiClient
74
80
  else
75
81
  data = nil
76
82
  end
77
- return data, response.code, response.headers
83
+ return data, response.status, response.headers
78
84
  end
79
85
 
80
86
  # Builds the HTTP request
@@ -85,48 +91,33 @@ module AzureOpenaiClient
85
91
  # @option opts [Hash] :query_params Query parameters
86
92
  # @option opts [Hash] :form_params Query parameters
87
93
  # @option opts [Object] :body HTTP body (JSON/XML)
88
- # @return [Typhoeus::Request] A Typhoeus Request
89
- def build_request(http_method, path, opts = {})
94
+ # @return [Faraday::Request] A Faraday Request
95
+ def build_request(http_method, path, request, opts = {})
90
96
  url = build_request_url(path, opts)
91
97
  http_method = http_method.to_sym.downcase
92
98
 
93
99
  header_params = @default_headers.merge(opts[:header_params] || {})
94
100
  query_params = opts[:query_params] || {}
95
101
  form_params = opts[:form_params] || {}
96
- follow_location = opts[:follow_location] || true
97
102
 
98
103
  update_params_for_auth! header_params, query_params, opts[:auth_names]
99
104
 
100
- # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
101
- _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
102
-
103
- req_opts = {
104
- :method => http_method,
105
- :headers => header_params,
106
- :params => query_params,
107
- :params_encoding => @config.params_encoding,
108
- :timeout => @config.timeout,
109
- :ssl_verifypeer => @config.verify_ssl,
110
- :ssl_verifyhost => _verify_ssl_host,
111
- :sslcert => @config.cert_file,
112
- :sslkey => @config.key_file,
113
- :verbose => @config.debugging,
114
- :followlocation => follow_location
115
- }
116
-
117
- # set custom cert, if provided
118
- req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
119
-
120
105
  if [:post, :patch, :put, :delete].include?(http_method)
121
106
  req_body = build_request_body(header_params, form_params, opts[:body])
122
- req_opts.update :body => req_body
123
- if @config.debugging
124
- @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
107
+ if config.debugging
108
+ config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
125
109
  end
126
110
  end
111
+ request.headers = header_params
112
+ request.body = req_body
113
+
114
+ # Overload default options only if provided
115
+ request.options.params_encoder = config.params_encoder if config.params_encoder
116
+ request.options.timeout = config.timeout if config.timeout
127
117
 
128
- request = Typhoeus::Request.new(url, req_opts)
129
- download_file(request) if opts[:return_type] == 'File'
118
+ request.url url
119
+ request.params = query_params
120
+ download_file(request) if opts[:return_type] == 'File' || opts[:return_type] == 'Binary'
130
121
  request
131
122
  end
132
123
 
@@ -138,13 +129,17 @@ module AzureOpenaiClient
138
129
  # @return [String] HTTP body data in the form of string
139
130
  def build_request_body(header_params, form_params, body)
140
131
  # http form
141
- if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
142
- header_params['Content-Type'] == 'multipart/form-data'
132
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded'
133
+ data = URI.encode_www_form(form_params)
134
+ elsif header_params['Content-Type'] == 'multipart/form-data'
143
135
  data = {}
144
136
  form_params.each do |key, value|
145
137
  case value
146
- when ::File, ::Array, nil
147
- # let typhoeus handle File, Array and nil parameters
138
+ when ::File, ::Tempfile
139
+ # TODO hardcode to application/octet-stream, need better way to detect content type
140
+ data[key] = Faraday::FilePart.new(value.path, 'application/octet-stream', value.path)
141
+ when ::Array, nil
142
+ # let Faraday handle Array and nil parameters
148
143
  data[key] = value
149
144
  else
150
145
  data[key] = value.to_s
@@ -158,40 +153,56 @@ module AzureOpenaiClient
158
153
  data
159
154
  end
160
155
 
161
- # Save response body into a file in (the defined) temporary folder, using the filename
162
- # from the "Content-Disposition" header if provided, otherwise a random filename.
163
- # The response body is written to the file in chunks in order to handle files which
164
- # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
165
- # process can use.
166
- #
167
- # @see Configuration#temp_folder_path
168
156
  def download_file(request)
169
- tempfile = nil
170
- encoding = nil
171
- request.on_headers do |response|
172
- content_disposition = response.headers['Content-Disposition']
173
- if content_disposition && content_disposition =~ /filename=/i
174
- filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
175
- prefix = sanitize_filename(filename)
176
- else
177
- prefix = 'download-'
178
- end
179
- prefix = prefix + '-' unless prefix.end_with?('-')
180
- encoding = response.body.encoding
181
- tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
182
- @tempfile = tempfile
157
+ @stream = []
158
+
159
+ # handle streaming Responses
160
+ request.options.on_data = Proc.new do |chunk, overall_received_bytes|
161
+ @stream << chunk
183
162
  end
184
- request.on_body do |chunk|
185
- chunk.force_encoding(encoding)
186
- tempfile.write(chunk)
163
+ end
164
+
165
+ def connection(opts)
166
+ opts[:header_params]['Content-Type'] == 'multipart/form-data' ? connection_multipart : connection_regular
167
+ end
168
+
169
+ def connection_multipart
170
+ @connection_multipart ||= build_connection do |conn|
171
+ conn.request :multipart
172
+ conn.request :url_encoded
187
173
  end
188
- request.on_complete do |response|
189
- if tempfile
190
- tempfile.close
191
- @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
192
- "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
193
- "will be deleted automatically with GC. It's also recommended to delete the temp file "\
194
- "explicitly with `tempfile.delete`"
174
+ end
175
+
176
+ def connection_regular
177
+ @connection_regular ||= build_connection
178
+ end
179
+
180
+ def build_connection
181
+ Faraday.new(url: config.base_url, ssl: ssl_options, proxy: config.proxy) do |conn|
182
+ basic_auth(conn)
183
+ config.configure_middleware(conn)
184
+ yield(conn) if block_given?
185
+ conn.adapter(Faraday.default_adapter)
186
+ config.configure_connection(conn)
187
+ end
188
+ end
189
+
190
+ def ssl_options
191
+ {
192
+ ca_file: config.ssl_ca_file,
193
+ verify: config.ssl_verify,
194
+ verify_mode: config.ssl_verify_mode,
195
+ client_cert: config.ssl_client_cert,
196
+ client_key: config.ssl_client_key
197
+ }
198
+ end
199
+
200
+ def basic_auth(conn)
201
+ if config.username && config.password
202
+ if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
203
+ conn.request(:authorization, :basic, config.username, config.password)
204
+ else
205
+ conn.request(:basic_auth, config.username, config.password)
195
206
  end
196
207
  end
197
208
  end
@@ -217,7 +228,32 @@ module AzureOpenaiClient
217
228
 
218
229
  # handle file downloading - return the File instance processed in request callbacks
219
230
  # note that response body is empty when the file is written in chunks in request on_body callback
220
- return @tempfile if return_type == 'File'
231
+ if return_type == 'File'
232
+ if @config.return_binary_data == true
233
+ # return byte stream
234
+ encoding = body.encoding
235
+ return @stream.join.force_encoding(encoding)
236
+ else
237
+ # return file instead of binary data
238
+ content_disposition = response.headers['Content-Disposition']
239
+ if content_disposition && content_disposition =~ /filename=/i
240
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
241
+ prefix = sanitize_filename(filename)
242
+ else
243
+ prefix = 'download-'
244
+ end
245
+ prefix = prefix + '-' unless prefix.end_with?('-')
246
+ encoding = body.encoding
247
+ @tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
248
+ @tempfile.write(@stream.join.force_encoding(encoding))
249
+ @tempfile.close
250
+ @config.logger.info "Temp file written to #{@tempfile.path}, please copy the file to a proper folder "\
251
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
252
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
253
+ "explicitly with `tempfile.delete`"
254
+ return @tempfile
255
+ end
256
+ end
221
257
 
222
258
  return nil if body.nil? || body.empty?
223
259
 
@@ -108,40 +108,39 @@ module AzureOpenaiClient
108
108
  # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
109
109
  #
110
110
  # @return [true, false]
111
- attr_accessor :verify_ssl
111
+ attr_accessor :ssl_verify
112
112
 
113
113
  ### TLS/SSL setting
114
- # Set this to false to skip verifying SSL host name
115
- # Default to true.
114
+ # Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html)
116
115
  #
117
116
  # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
118
117
  #
119
- # @return [true, false]
120
- attr_accessor :verify_ssl_host
118
+ attr_accessor :ssl_verify_mode
121
119
 
122
120
  ### TLS/SSL setting
123
121
  # Set this to customize the certificate file to verify the peer.
124
122
  #
125
123
  # @return [String] the path to the certificate file
126
- #
127
- # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
128
- # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
129
- attr_accessor :ssl_ca_cert
124
+ attr_accessor :ssl_ca_file
130
125
 
131
126
  ### TLS/SSL setting
132
127
  # Client certificate file (for client certificate)
133
- attr_accessor :cert_file
128
+ attr_accessor :ssl_client_cert
134
129
 
135
130
  ### TLS/SSL setting
136
131
  # Client private key file (for client certificate)
137
- attr_accessor :key_file
132
+ attr_accessor :ssl_client_key
138
133
 
139
- # Set this to customize parameters encoding of array parameter with multi collectionFormat.
140
- # Default to nil.
134
+ ### Proxy setting
135
+ # HTTP Proxy settings
136
+ attr_accessor :proxy
137
+
138
+ # Set this to customize parameters encoder of array parameter.
139
+ # Default to nil. Faraday uses NestedParamsEncoder when nil.
141
140
  #
142
- # @see The params_encoding option of Ethon. Related source code:
143
- # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
144
- attr_accessor :params_encoding
141
+ # @see The params_encoder option of Faraday. Related source code:
142
+ # https://github.com/lostisland/faraday/tree/main/lib/faraday/encoders
143
+ attr_accessor :params_encoder
145
144
 
146
145
 
147
146
  attr_accessor :inject_format
@@ -159,12 +158,17 @@ module AzureOpenaiClient
159
158
  @api_key = {}
160
159
  @api_key_prefix = {}
161
160
  @client_side_validation = true
162
- @verify_ssl = true
163
- @verify_ssl_host = true
164
- @cert_file = nil
165
- @key_file = nil
166
- @timeout = 0
167
- @params_encoding = nil
161
+ @ssl_verify = true
162
+ @ssl_verify_mode = nil
163
+ @ssl_ca_file = nil
164
+ @ssl_client_cert = nil
165
+ @ssl_client_key = nil
166
+ @middlewares = Hash.new { |h, k| h[k] = [] }
167
+ @configure_connection_blocks = []
168
+ @timeout = 60
169
+ # return data as binary instead of file
170
+ @return_binary_data = false
171
+ @params_encoder = nil
168
172
  @debugging = false
169
173
  @inject_format = false
170
174
  @force_ending_format = false
@@ -302,5 +306,86 @@ module AzureOpenaiClient
302
306
 
303
307
  url
304
308
  end
309
+
310
+ # Configure Faraday connection directly.
311
+ #
312
+ # ```
313
+ # c.configure_faraday_connection do |conn|
314
+ # conn.use Faraday::HttpCache, shared_cache: false, logger: logger
315
+ # conn.response :logger, nil, headers: true, bodies: true, log_level: :debug do |logger|
316
+ # logger.filter(/(Authorization: )(.*)/, '\1[REDACTED]')
317
+ # end
318
+ # end
319
+ #
320
+ # c.configure_faraday_connection do |conn|
321
+ # conn.adapter :typhoeus
322
+ # end
323
+ # ```
324
+ #
325
+ # @param block [Proc] `#call`able object that takes one arg, the connection
326
+ def configure_faraday_connection(&block)
327
+ @configure_connection_blocks << block
328
+ end
329
+
330
+ def configure_connection(conn)
331
+ @configure_connection_blocks.each do |block|
332
+ block.call(conn)
333
+ end
334
+ end
335
+
336
+ # Adds middleware to the stack
337
+ def use(*middleware)
338
+ set_faraday_middleware(:use, *middleware)
339
+ end
340
+
341
+ # Adds request middleware to the stack
342
+ def request(*middleware)
343
+ set_faraday_middleware(:request, *middleware)
344
+ end
345
+
346
+ # Adds response middleware to the stack
347
+ def response(*middleware)
348
+ set_faraday_middleware(:response, *middleware)
349
+ end
350
+
351
+ # Adds Faraday middleware setting information to the stack
352
+ #
353
+ # @example Use the `set_faraday_middleware` method to set middleware information
354
+ # config.set_faraday_middleware(:request, :retry, max: 3, methods: [:get, :post], retry_statuses: [503])
355
+ # config.set_faraday_middleware(:response, :logger, nil, { bodies: true, log_level: :debug })
356
+ # config.set_faraday_middleware(:use, Faraday::HttpCache, store: Rails.cache, shared_cache: false)
357
+ # config.set_faraday_middleware(:insert, 0, FaradayMiddleware::FollowRedirects, { standards_compliant: true, limit: 1 })
358
+ # config.set_faraday_middleware(:swap, 0, Faraday::Response::Logger)
359
+ # config.set_faraday_middleware(:delete, Faraday::Multipart::Middleware)
360
+ #
361
+ # @see https://github.com/lostisland/faraday/blob/v2.3.0/lib/faraday/rack_builder.rb#L92-L143
362
+ def set_faraday_middleware(operation, key, *args, &block)
363
+ unless [:request, :response, :use, :insert, :insert_before, :insert_after, :swap, :delete].include?(operation)
364
+ fail ArgumentError, "Invalid faraday middleware operation #{operation}. Must be" \
365
+ " :request, :response, :use, :insert, :insert_before, :insert_after, :swap or :delete."
366
+ end
367
+
368
+ @middlewares[operation] << [key, args, block]
369
+ end
370
+ ruby2_keywords(:set_faraday_middleware) if respond_to?(:ruby2_keywords, true)
371
+
372
+ # Set up middleware on the connection
373
+ def configure_middleware(connection)
374
+ return if @middlewares.empty?
375
+
376
+ [:request, :response, :use, :insert, :insert_before, :insert_after, :swap].each do |operation|
377
+ next unless @middlewares.key?(operation)
378
+
379
+ @middlewares[operation].each do |key, args, block|
380
+ connection.builder.send(operation, key, *args, &block)
381
+ end
382
+ end
383
+
384
+ if @middlewares.key?(:delete)
385
+ @middlewares[:delete].each do |key, _args, _block|
386
+ connection.builder.delete(key)
387
+ end
388
+ end
389
+ end
305
390
  end
306
391
  end
@@ -11,5 +11,5 @@ OpenAPI Generator version: 6.6.0
11
11
  =end
12
12
 
13
13
  module AzureOpenaiClient
14
- VERSION = '0.0.2'
14
+ VERSION = '0.0.4'
15
15
  end
data/openapi-codegen.sh CHANGED
@@ -5,7 +5,7 @@ release_notes=$2
5
5
 
6
6
  openapi-generator generate -c openapi_config.yaml \
7
7
  --additional-properties gemVersion="$gem_version",\
8
- --release-note "$release_notes"
8
+ --release-note "$release_notes" --library=faraday
9
9
 
10
10
 
11
11
  echo "Running Linter"
data/openapi_config.yaml CHANGED
@@ -8,6 +8,8 @@ additionalProperties:
8
8
  gemAuthor: "Josh Etsenake"
9
9
  gemAuthorEmail: "josh.etsenake@fullscript.com"
10
10
  hideGenerationTimestamp: true
11
+ gemRequiredRubyVersion: ">= 2.5"
12
+ library: "faraday"
11
13
  gitUserId: etsenake
12
14
  gitRepoId: azure-openai-client
13
15
  globalProperties:
@@ -51,45 +51,40 @@ describe AzureOpenaiClient::ApiClient do
51
51
  end
52
52
  end
53
53
 
54
- describe 'params_encoding in #build_request' do
54
+
55
+ describe 'proxy in #build_connection' do
55
56
  let(:config) { AzureOpenaiClient::Configuration.new }
56
57
  let(:api_client) { AzureOpenaiClient::ApiClient.new(config) }
58
+ let(:proxy_uri) { URI('http://example.org:8080') }
57
59
 
58
60
  it 'defaults to nil' do
59
- expect(AzureOpenaiClient::Configuration.default.params_encoding).to eq(nil)
60
- expect(config.params_encoding).to eq(nil)
61
+ expect(AzureOpenaiClient::Configuration.default.proxy).to be_nil
62
+ expect(config.proxy).to be_nil
61
63
 
62
- request = api_client.build_request(:get, '/test')
63
- expect(request.options[:params_encoding]).to eq(nil)
64
+ connection = api_client.build_connection
65
+ expect(connection.proxy_for_request('/test')).to be_nil
64
66
  end
65
67
 
66
- it 'can be customized' do
67
- config.params_encoding = :multi
68
- request = api_client.build_request(:get, '/test')
69
- expect(request.options[:params_encoding]).to eq(:multi)
70
- end
71
- end
72
-
73
- describe 'timeout in #build_request' do
74
- let(:config) { AzureOpenaiClient::Configuration.new }
75
- let(:api_client) { AzureOpenaiClient::ApiClient.new(config) }
68
+ it 'can be customized with a string' do
69
+ config.proxy = proxy_uri.to_s
76
70
 
77
- it 'defaults to 0' do
78
- expect(AzureOpenaiClient::Configuration.default.timeout).to eq(0)
79
- expect(config.timeout).to eq(0)
71
+ connection = api_client.build_connection
72
+ configured_proxy = connection.proxy_for_request('/test')
80
73
 
81
- request = api_client.build_request(:get, '/test')
82
- expect(request.options[:timeout]).to eq(0)
74
+ expect(configured_proxy).not_to be_nil
75
+ expect(configured_proxy.uri.to_s).to eq proxy_uri.to_s
83
76
  end
84
77
 
85
- it 'can be customized' do
86
- config.timeout = 100
87
- request = api_client.build_request(:get, '/test')
88
- expect(request.options[:timeout]).to eq(100)
89
- end
90
- end
78
+ it 'can be customized with a hash' do
79
+ config.proxy = { uri: proxy_uri }
91
80
 
81
+ connection = api_client.build_connection
82
+ configured_proxy = connection.proxy_for_request('/test')
92
83
 
84
+ expect(configured_proxy).not_to be_nil
85
+ expect(configured_proxy.uri).to eq proxy_uri
86
+ end
87
+ end
93
88
 
94
89
  describe '#deserialize' do
95
90
  it "handles Array<Integer>" do
@@ -12,13 +12,8 @@ RSpec.describe AzureOpenaiClient::Configuration do
12
12
  expect(config.base_path).to eq('/openai')
13
13
  expect(config.api_key).to eq({})
14
14
  expect(config.api_key_prefix).to eq({})
15
- expect(config.timeout).to eq(0)
15
+ expect(config.timeout).to eq(60)
16
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
17
  expect(config.debugging).to be(false)
23
18
  expect(config.inject_format).to be(false)
24
19
  expect(config.force_ending_format).to be(false)
metadata CHANGED
@@ -1,35 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: azure_openai_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Etsenake
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-12 00:00:00.000000000 Z
11
+ date: 2023-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: typhoeus
14
+ name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.0'
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
19
  version: 1.0.1
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '1.0'
30
27
  - - ">="
31
28
  - !ruby/object:Gem::Version
32
29
  version: 1.0.1
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: faraday-multipart
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: rspec
35
49
  requirement: !ruby/object:Gem::Requirement
@@ -152,7 +166,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
166
  requirements:
153
167
  - - ">="
154
168
  - !ruby/object:Gem::Version
155
- version: '2.7'
169
+ version: '2.5'
156
170
  required_rubygems_version: !ruby/object:Gem::Requirement
157
171
  requirements:
158
172
  - - ">="