Skip to content
Open
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ and require with:
require "openai"
```

## Compatibility with offical OpenAI library

OpenAI now publishes their own [Ruby client library](https://github.com/openai/openai-ruby), which uses the same namespace as this one. If you are working with a codebase that uses both, you can require this one with this alternate path to avoid collisions:

```ruby
require "ruby/openai"
```

## How to use

- Get your API key from [https://platform.openai.com/account/api-keys](https://platform.openai.com/account/api-keys)
Expand Down
9 changes: 9 additions & 0 deletions lib/openai/compatibility.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Ruby
module OpenAI
VERSION = ::OpenAI::VERSION

Error = ::OpenAI::Error
ConfigurationError = ::OpenAI::ConfigurationError
Configuration = ::OpenAI::Configuration
end
end
1 change: 1 addition & 0 deletions lib/ruby/openai.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
require_relative "../openai"
require_relative "../openai/compatibility"
35 changes: 35 additions & 0 deletions spec/compatibility_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require "ruby/openai"

RSpec.describe "compatibility" do
context "for moved constants" do
describe "::Ruby::OpenAI::VERSION" do
it "is mapped to ::OpenAI::VERSION" do
expect(Ruby::OpenAI::VERSION).to eq(OpenAI::VERSION)
end
end

describe "::Ruby::OpenAI::Error" do
it "is mapped to ::OpenAI::Error" do
expect(Ruby::OpenAI::Error).to eq(OpenAI::Error)
expect(Ruby::OpenAI::Error.new).to be_a(OpenAI::Error)
expect(OpenAI::Error.new).to be_a(Ruby::OpenAI::Error)
end
end

describe "::Ruby::OpenAI::ConfigurationError" do
it "is mapped to ::OpenAI::ConfigurationError" do
expect(Ruby::OpenAI::ConfigurationError).to eq(OpenAI::ConfigurationError)
expect(Ruby::OpenAI::ConfigurationError.new).to be_a(OpenAI::ConfigurationError)
expect(OpenAI::ConfigurationError.new).to be_a(Ruby::OpenAI::ConfigurationError)
end
end

describe "::Ruby::OpenAI::Configuration" do
it "is mapped to ::OpenAI::Configuration" do
expect(Ruby::OpenAI::Configuration).to eq(OpenAI::Configuration)
expect(Ruby::OpenAI::Configuration.new).to be_a(OpenAI::Configuration)
expect(OpenAI::Configuration.new).to be_a(Ruby::OpenAI::Configuration)
end
end
end
end