Skip to content

6.3 #389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 26, 2023
Merged

6.3 #389

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [6.3.0] - 2023-11-26

### Added

- 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.
- Add better error logging to the client by default.
- Bump Event Source to v1, thank you [@atesgoral](https://github.com/atesgoral) @ Shopify!

## [6.2.0] - 2023-11-15

### Added
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
ruby-openai (6.2.0)
ruby-openai (6.3.0)
event_stream_parser (>= 0.3.0, < 2.0.0)
faraday (>= 1)
faraday-multipart (>= 1)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ end

#### Verbose Logging

You can pass [Faraday middleware](https://lostisland.github.io/faraday/#/middleware/index) to the client in a block, eg. to enable verbose logging:
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):

```ruby
client = OpenAI::Client.new do |f|
Expand Down
16 changes: 16 additions & 0 deletions lib/openai.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ module OpenAI
class Error < StandardError; end
class ConfigurationError < Error; end

class MiddlewareErrors < Faraday::Middleware
def call(env)
@app.call(env)
rescue Faraday::Error => e
raise e unless e.response.is_a?(Hash)

logger = Logger.new($stdout)
logger.formatter = proc do |_severity, _datetime, _progname, msg|
"\033[31mOpenAI HTTP Error (spotted in ruby-openai #{VERSION}): #{msg}\n\033[0m"
end
logger.error(e.response[:body])

raise e
end
end

class Configuration
attr_writer :access_token
attr_accessor :api_type, :api_version, :organization_id, :uri_base, :request_timeout,
Expand Down
1 change: 1 addition & 0 deletions lib/openai/compatibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ module OpenAI
Error = ::OpenAI::Error
ConfigurationError = ::OpenAI::ConfigurationError
Configuration = ::OpenAI::Configuration
MiddlewareErrors = ::OpenAI::MiddlewareErrors
end
end
1 change: 1 addition & 0 deletions lib/openai/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def conn(multipart: false)
connection = Faraday.new do |f|
f.options[:timeout] = @request_timeout
f.request(:multipart) if multipart
f.use MiddlewareErrors
f.response :raise_error
f.response :json
end
Expand Down
2 changes: 1 addition & 1 deletion lib/openai/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module OpenAI
VERSION = "6.2.0".freeze
VERSION = "6.3.0".freeze
end
28 changes: 17 additions & 11 deletions spec/fixtures/cassettes/gpt-3_5-turbo-0301_chat.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 19 additions & 13 deletions spec/fixtures/cassettes/gpt-3_5-turbo_chat.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 22 additions & 16 deletions spec/fixtures/cassettes/gpt-3_5-turbo_function_call_chat.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading