Giter VIP home page Giter VIP logo

anthropic's Introduction

Anthropic

Gem Version GitHub license CircleCI Build Status

Use the Anthropic API with Ruby! ๐Ÿค–๐ŸŒŒ

You can apply for access to the API here.

๐Ÿšข Need someone to ship critical Rails features for you, fast? I'm taking on a few new clients at an experimental crazy low price, check it out: railsai.com

๐ŸŽฎ Ruby AI Builders Discord | ๐Ÿฆ Twitter | ๐Ÿค– OpenAI Gem | ๐Ÿš‚ Midjourney Gem

Bundler

Add this line to your application's Gemfile:

gem "anthropic"

And then execute:

$ bundle install

Gem install

Or install with:

$ gem install anthropic

and require with:

require "anthropic"

Usage

Quickstart

For a quick test you can pass your token directly to a new client:

client = Anthropic::Client.new(access_token: "access_token_goes_here")

With Config

For a more robust setup, you can configure the gem with your API keys, for example in an anthropic.rb initializer file. Never hardcode secrets into your codebase - instead use something like dotenv to pass the keys safely into your environments.

Anthropic.configure do |config|
    config.access_token = ENV.fetch("ANTHROPIC_API_KEY")
end

Then you can create a client like this:

client = Anthropic::Client.new

Change version or timeout

You can change to a different dated version (different from the URL version which is just v1) of Anthropic's API by passing anthropic_version when initializing the client. If you don't the default latest will be used, which is "2023-06-01". More info

The default timeout for any request using this library is 120 seconds. You can change that by passing a number of seconds to the request_timeout when initializing the client.

client = Anthropic::Client.new(
    access_token: "access_token_goes_here",
    anthropic_version: "2023-01-01", # Optional
    request_timeout: 240 # Optional
)

You can also set these keys when configuring the gem:

Anthropic.configure do |config|
    config.access_token = ENV.fetch("ANTHROPIC_API_KEY")
    config.anthropic_version = "2023-01-01" # Optional
    config.request_timeout = 240 # Optional
end

Completions

Hit the Anthropic API for a completion:

response = client.complete(
    parameters: {
        model: "claude-2",
        prompt: "How high is the sky?",
        max_tokens_to_sample: 5
    })
puts response["completion"]
# => " The sky has no definitive"

Note that all requests are prepended by this library with

\n\nHuman:

and appended with

\n\nAssistant:

so whatever prompt you pass will be sent to the API as

\n\nHuman: How high is the sky?\n\nAssistant:

This is a requirement of the API.

Development

After checking out the repo, run bin/setup to install dependencies. You can run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

Warning

If you have an ANTHROPIC_API_KEY in your ENV, running the specs will use this to run the specs against the actual API, which will be slow and cost you money - 2 cents or more! Remove it from your environment with unset or similar if you just want to run the specs against the stored VCR responses.

Release

First run the specs without VCR so they actually hit the API. This will cost 2 cents or more. Set ANTHROPIC_API_KEY in your environment or pass it in like this:

ANTHROPIC_API_KEY=123abc bundle exec rspec

Then update the version number in version.rb, update CHANGELOG.md, run bundle install to update Gemfile.lock, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/alexrudall/anthropic. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Ruby Anthropic project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

anthropic's People

Contributors

alexrudall avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.