Skip to content

Commit 80da193

Browse files
authored
Merge pull request #389 from alexrudall/6.3
6.3
2 parents d25d085 + 4fe84da commit 80da193

22 files changed

+1401
-163
lines changed

Diff for: CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [6.3.0] - 2023-11-26
9+
10+
### Added
11+
12+
- Add ability to pass [Faraday middleware](https://lostisland.github.io/faraday/#/middleware/index) to the client in a block, eg. to enable verbose logging - shout out to [@obie](https://github.com/obie) for pushing for this.
13+
- Add better error logging to the client by default.
14+
- Bump Event Source to v1, thank you [@atesgoral](https://github.com/atesgoral) @ Shopify!
15+
816
## [6.2.0] - 2023-11-15
917

1018
### Added

Diff for: Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
ruby-openai (6.2.0)
4+
ruby-openai (6.3.0)
55
event_stream_parser (>= 0.3.0, < 2.0.0)
66
faraday (>= 1)
77
faraday-multipart (>= 1)

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ end
110110

111111
#### Verbose Logging
112112

113-
You can pass [Faraday middleware](https://lostisland.github.io/faraday/#/middleware/index) to the client in a block, eg. to enable verbose logging:
113+
You can pass [Faraday middleware](https://lostisland.github.io/faraday/#/middleware/index) to the client in a block, eg. to enable verbose logging with Ruby's [Logger](https://ruby-doc.org/3.2.2/stdlibs/logger/Logger.html):
114114

115115
```ruby
116116
client = OpenAI::Client.new do |f|

Diff for: lib/openai.rb

+16
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ module OpenAI
1919
class Error < StandardError; end
2020
class ConfigurationError < Error; end
2121

22+
class MiddlewareErrors < Faraday::Middleware
23+
def call(env)
24+
@app.call(env)
25+
rescue Faraday::Error => e
26+
raise e unless e.response.is_a?(Hash)
27+
28+
logger = Logger.new($stdout)
29+
logger.formatter = proc do |_severity, _datetime, _progname, msg|
30+
"\033[31mOpenAI HTTP Error (spotted in ruby-openai #{VERSION}): #{msg}\n\033[0m"
31+
end
32+
logger.error(e.response[:body])
33+
34+
raise e
35+
end
36+
end
37+
2238
class Configuration
2339
attr_writer :access_token
2440
attr_accessor :api_type, :api_version, :organization_id, :uri_base, :request_timeout,

Diff for: lib/openai/compatibility.rb

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ module OpenAI
55
Error = ::OpenAI::Error
66
ConfigurationError = ::OpenAI::ConfigurationError
77
Configuration = ::OpenAI::Configuration
8+
MiddlewareErrors = ::OpenAI::MiddlewareErrors
89
end
910
end

Diff for: lib/openai/http.rb

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def conn(multipart: false)
7474
connection = Faraday.new do |f|
7575
f.options[:timeout] = @request_timeout
7676
f.request(:multipart) if multipart
77+
f.use MiddlewareErrors
7778
f.response :raise_error
7879
f.response :json
7980
end

Diff for: lib/openai/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module OpenAI
2-
VERSION = "6.2.0".freeze
2+
VERSION = "6.3.0".freeze
33
end

Diff for: spec/fixtures/cassettes/gpt-3_5-turbo-0301_chat.yml

+17-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: spec/fixtures/cassettes/gpt-3_5-turbo_chat.yml

+19-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: spec/fixtures/cassettes/gpt-3_5-turbo_function_call_chat.yml

+22-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)