openai.rb 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +1 -1
- data/bin/console +0 -2
- data/lib/openai/api/client.rb +7 -5
- data/lib/openai/version.rb +1 -1
- data/lib/openai.rb +2 -2
- data/spec/unit/openai_spec.rb +19 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96f82f97fa18d7fc75b7efd8e01fe015b50c0d4e33c06894b37b2f807315138b
|
4
|
+
data.tar.gz: b563a01a6b737282477a7e47c29f1d514b0bcecd806f0b3d9b0ad3f9394fb605
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a51cc63b3023d1bd0ca33e3ab6325ea8bd9d8a64fbff301b2e044b113e656c0245fdcb891a2633fb0d9edd18a59073e02ff4ca14fd5d32a571f71e43948402c8
|
7
|
+
data.tar.gz: 8eea70ae9c26df48a0b0651354bf6aa4cf7996e348bc6a6e5714aaa239a6815e1831a063c9c3efe912f283aeacaf794908189709f4ebd34209192ab42942af55
|
data/CHANGELOG.md
ADDED
data/Gemfile.lock
CHANGED
data/bin/console
CHANGED
data/lib/openai/api/client.rb
CHANGED
@@ -3,18 +3,18 @@
|
|
3
3
|
class OpenAI
|
4
4
|
class API
|
5
5
|
class Client
|
6
|
-
include Concord.new(:api_key, :http)
|
6
|
+
include Concord.new(:api_key, :organization_id, :http)
|
7
7
|
|
8
8
|
public :api_key
|
9
9
|
|
10
10
|
HOST = Addressable::URI.parse('https://api.openai.com/v1')
|
11
11
|
|
12
|
-
def initialize(api_key, http: HTTP)
|
13
|
-
super(api_key, http)
|
12
|
+
def initialize(api_key, organization_id: nil, http: HTTP)
|
13
|
+
super(api_key, organization_id, http)
|
14
14
|
end
|
15
15
|
|
16
16
|
def inspect
|
17
|
-
"#<#{self.class}>"
|
17
|
+
"#<#{self.class} organization_id=#{organization_id.inspect}>"
|
18
18
|
end
|
19
19
|
|
20
20
|
def get(route)
|
@@ -79,7 +79,9 @@ class OpenAI
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def http_client
|
82
|
-
|
82
|
+
headers = { 'Authorization' => "Bearer #{api_key}" }
|
83
|
+
headers['OpenAI-Organization'] = organization_id if organization_id
|
84
|
+
http.headers(headers)
|
83
85
|
end
|
84
86
|
end
|
85
87
|
end
|
data/lib/openai/version.rb
CHANGED
data/lib/openai.rb
CHANGED
@@ -28,8 +28,8 @@ class OpenAI
|
|
28
28
|
|
29
29
|
ROOT = Pathname.new(__dir__).parent.expand_path.freeze
|
30
30
|
|
31
|
-
def self.create(api_key, cache: nil, logger: Logger.new('/dev/null'))
|
32
|
-
client = API::Client.new(api_key)
|
31
|
+
def self.create(api_key, cache: nil, organization: nil, logger: Logger.new('/dev/null'))
|
32
|
+
client = API::Client.new(api_key, organization_id: organization)
|
33
33
|
|
34
34
|
if cache.is_a?(Pathname) && cache.directory?
|
35
35
|
client = API::Cache.new(
|
data/spec/unit/openai_spec.rb
CHANGED
@@ -37,6 +37,25 @@ RSpec.describe OpenAI do
|
|
37
37
|
)
|
38
38
|
end
|
39
39
|
|
40
|
+
context 'when the organization ID is given to the client' do
|
41
|
+
let(:api_client) do
|
42
|
+
OpenAI::API::Client.new(
|
43
|
+
'sk-123',
|
44
|
+
organization_id: 'org-123',
|
45
|
+
http: http
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'authenticates the request and includes the organization id' do
|
50
|
+
resource.create(model: 'text-davinci-002', prompt: 'Hello, world!')
|
51
|
+
|
52
|
+
expect(http).to have_received(:headers).with(
|
53
|
+
'OpenAI-Organization' => 'org-123',
|
54
|
+
'Authorization' => 'Bearer sk-123'
|
55
|
+
)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
40
59
|
context 'when the request is not 2xx' do
|
41
60
|
let(:response_body) do
|
42
61
|
{
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openai.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-04-
|
12
|
+
date: 2023-04-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: abstract_type
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- ".rspec"
|
128
128
|
- ".rubocop.yml"
|
129
129
|
- ".ruby-version"
|
130
|
+
- CHANGELOG.md
|
130
131
|
- Gemfile
|
131
132
|
- Gemfile.lock
|
132
133
|
- README.md
|