Skip to content

Commit f5c7ca4

Browse files
committed
Rubocop
1 parent 215a61b commit f5c7ca4

File tree

2 files changed

+12
-25
lines changed

2 files changed

+12
-25
lines changed

lib/openai/client.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,8 @@ class Client
33
include OpenAI::HTTP
44

55
SENSITIVE_ATTRIBUTES = %i[@access_token @admin_token @organization_id @extra_headers].freeze
6-
CONFIG_KEYS = %i[
7-
access_token
8-
admin_token
9-
api_type
10-
api_version
11-
extra_headers
12-
log_errors
13-
organization_id
14-
request_timeout
15-
uri_base
16-
].freeze
6+
CONFIG_KEYS = %i[access_token admin_token api_type api_version extra_headers
7+
log_errors organization_id request_timeout uri_base].freeze
178
attr_reader *CONFIG_KEYS, :faraday_middleware
189
attr_writer :access_token
1910

spec/spec_helper.rb

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
record: tokens_present ? :all : :new_episodes,
1717
match_requests_on: [:method, :uri, VCRMultipartMatcher.new]
1818
}
19-
c.filter_sensitive_data("<OPENAI_ACCESS_TOKEN>") { OpenAI.configuration.access_token }
20-
c.filter_sensitive_data("<OPENAI_ADMIN_TOKEN>") { OpenAI.configuration.admin_token }
21-
c.filter_sensitive_data("<OPENAI_ORGANIZATION_ID>") { OpenAI.configuration.organization_id }
22-
if (user_id = ENV.fetch("OPENAI_USER_ID", nil))
23-
c.filter_sensitive_data("<OPENAI_USER_ID>") { user_id }
19+
20+
%w[ACCESS_TOKEN ADMIN_TOKEN ORGANIZATION_ID USER_ID].each do |key|
21+
c.filter_sensitive_data("<OPENAI_#{key}>") do
22+
key == "USER_ID" ? ENV.fetch("OPENAI_#{key}", nil) : OpenAI.configuration.send(key.downcase)
23+
end
2424
end
2525
end
2626

@@ -31,14 +31,12 @@
3131
# Disable RSpec exposing methods globally on `Module` and `main`
3232
c.disable_monkey_patching!
3333

34-
c.expect_with :rspec do |rspec|
35-
rspec.syntax = :expect
36-
end
34+
c.expect_with(:rspec) { |rspec| rspec.syntax = :expect }
3735

3836
if tokens_present
39-
warning = "WARNING! Specs are hitting the OpenAI API using your OPENAI_ACCESS_TOKEN and OPENAI_ADMIN_TOKEN! This
40-
costs at least 2 cents per run and is very slow! If you don't want this, unset
41-
OPENAI_ACCESS_TOKEN or OPENAI_ADMIN_TOKEN to just run against the stored VCR responses.".freeze
37+
warning = "WARNING! Specs are hitting the OpenAI API using your OPENAI_ACCESS_TOKEN or
38+
OPENAI_ADMIN_TOKEN! This costs at least 2 cents per run and is very slow! If you don't want
39+
this, unset OPENAI_ACCESS_TOKEN to just run against the stored VCR responses.".freeze
4240
warning = RSpec::Core::Formatters::ConsoleCodes.wrap(warning, :bold_red)
4341

4442
c.before(:suite) { RSpec.configuration.reporter.message(warning) }
@@ -49,9 +47,7 @@
4947
OpenAI.configure do |config|
5048
config.access_token = ENV.fetch("OPENAI_ACCESS_TOKEN", "dummy-token")
5149
config.admin_token = ENV.fetch("OPENAI_ADMIN_TOKEN", "dummy-token")
52-
if (organization_id = ENV.fetch("OPENAI_ORGANIZATION_ID", nil))
53-
config.organization_id = organization_id
54-
end
50+
config.organization_id = ENV.fetch("OPENAI_ORGANIZATION_ID", nil)
5551
end
5652
end
5753
end

0 commit comments

Comments
 (0)