-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from alexrudall/0.1.0
MVP library!
- Loading branch information
Showing
14 changed files
with
321 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
anthropic (0.0.0) | ||
anthropic (0.1.0) | ||
faraday (>= 1) | ||
faraday-multipart (>= 1) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Anthropic | ||
VERSION = "0.0.0".freeze | ||
VERSION = "0.1.0".freeze | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
RSpec.describe Anthropic::Client do | ||
describe "#complete" do | ||
context "with a prompt and max_tokens", :vcr do | ||
let(:prompt) { "How high is the sky?" } | ||
let(:max_tokens) { 5 } | ||
|
||
let(:response) do | ||
Anthropic::Client.new.complete( | ||
parameters: { | ||
model: model, | ||
max_tokens_to_sample: max_tokens, | ||
prompt: prompt | ||
} | ||
) | ||
end | ||
let(:text) { response.dig("choices", 0, "text") } | ||
let(:cassette) { "#{model} complete #{prompt}".downcase } | ||
|
||
context "with model: claude-2" do | ||
let(:model) { "claude-2" } | ||
|
||
it "succeeds" do | ||
VCR.use_cassette(cassette) do | ||
expect(response["completion"].empty?).to eq(false) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
RSpec.describe Anthropic do | ||
it "has a version number" do | ||
expect(Anthropic::VERSION).not_to be nil | ||
end | ||
|
||
describe "#configure" do | ||
let(:access_token) { "abc123" } | ||
let(:api_version) { "v2" } | ||
let(:organization_id) { "def456" } | ||
let(:custom_uri_base) { "ghi789" } | ||
let(:custom_request_timeout) { 25 } | ||
let(:extra_headers) { { "User-Agent" => "Anthropic Ruby Gem #{Anthropic::VERSION}" } } | ||
|
||
before do | ||
Anthropic.configure do |config| | ||
config.access_token = access_token | ||
config.api_version = api_version | ||
config.organization_id = organization_id | ||
config.extra_headers = extra_headers | ||
end | ||
end | ||
|
||
it "returns the config" do | ||
expect(Anthropic.configuration.access_token).to eq(access_token) | ||
expect(Anthropic.configuration.api_version).to eq(api_version) | ||
expect(Anthropic.configuration.organization_id).to eq(organization_id) | ||
expect(Anthropic.configuration.uri_base).to eq("https://api.anthropic.com/") | ||
expect(Anthropic.configuration.request_timeout).to eq(120) | ||
expect(Anthropic.configuration.extra_headers).to eq(extra_headers) | ||
end | ||
|
||
context "without an access token" do | ||
let(:access_token) { nil } | ||
|
||
it "raises an error" do | ||
expect { Anthropic::Client.new.complete }.to raise_error(Anthropic::ConfigurationError) | ||
end | ||
end | ||
|
||
context "with custom timeout and uri base" do | ||
before do | ||
Anthropic.configure do |config| | ||
config.uri_base = custom_uri_base | ||
config.request_timeout = custom_request_timeout | ||
end | ||
end | ||
|
||
it "returns the config" do | ||
expect(Anthropic.configuration.access_token).to eq(access_token) | ||
expect(Anthropic.configuration.api_version).to eq(api_version) | ||
expect(Anthropic.configuration.organization_id).to eq(organization_id) | ||
expect(Anthropic.configuration.uri_base).to eq(custom_uri_base) | ||
expect(Anthropic.configuration.request_timeout).to eq(custom_request_timeout) | ||
expect(Anthropic.configuration.extra_headers).to eq(extra_headers) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
RSpec.describe "compatibility" do | ||
context "for moved constants" do | ||
describe "::Ruby::Anthropic::VERSION" do | ||
it "is mapped to ::Anthropic::VERSION" do | ||
expect(Ruby::Anthropic::VERSION).to eq(Anthropic::VERSION) | ||
end | ||
end | ||
|
||
describe "::Ruby::Anthropic::Error" do | ||
it "is mapped to ::Anthropic::Error" do | ||
expect(Ruby::Anthropic::Error).to eq(Anthropic::Error) | ||
expect(Ruby::Anthropic::Error.new).to be_a(Anthropic::Error) | ||
expect(Anthropic::Error.new).to be_a(Ruby::Anthropic::Error) | ||
end | ||
end | ||
|
||
describe "::Ruby::Anthropic::ConfigurationError" do | ||
it "is mapped to ::Anthropic::ConfigurationError" do | ||
expect(Ruby::Anthropic::ConfigurationError).to eq(Anthropic::ConfigurationError) | ||
expect(Ruby::Anthropic::ConfigurationError.new).to be_a(Anthropic::ConfigurationError) | ||
expect(Anthropic::ConfigurationError.new).to be_a(Ruby::Anthropic::ConfigurationError) | ||
end | ||
end | ||
|
||
describe "::Ruby::Anthropic::Configuration" do | ||
it "is mapped to ::Anthropic::Configuration" do | ||
expect(Ruby::Anthropic::Configuration).to eq(Anthropic::Configuration) | ||
expect(Ruby::Anthropic::Configuration.new).to be_a(Anthropic::Configuration) | ||
expect(Anthropic::Configuration.new).to be_a(Ruby::Anthropic::Configuration) | ||
end | ||
end | ||
end | ||
end |
48 changes: 48 additions & 0 deletions
48
spec/fixtures/cassettes/claude-2_complete_how_high_is_the_sky_.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.