Project

cohere

0.0
The project is in a healthy, maintained state
Official SDK for Cohere AI
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies

Runtime

= 0.20.0
 Project Readme

Cohere::Ruby

The official SDK for the Cohere API.

Harness the power of language understanding. Join the developers and businesses who are using Cohere to generate, categorize and organize text at a scale that was previously unimaginable.

Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add cohere

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install cohere

Usage

    client = Cohere::Client.new access_token: "<COHERE_ACCESS_TOKEN>"

Embed

See full docs here.

  • texts: array of strings - required
  • truncate: Accepts "NONE", "LEFT" or "RIGHT, default NONE - optional
    client.embed(model: "medium",
                options: { texts: ["When are you open?", "When do you close?", "What are the hours?",
                                    "Are you open on weekends?", "Are you available on holidays?"] })

Classify

See full docs here.

  • inputs: array of strings - required
  • examples: array of {label:{},text:{}} - required
  • outputIndicator: string - optional
  • taskDescription: string - optional
    client.classify(model: "medium",
                    options: { inputs: [ "This item was broken when it arrived", "This item broke after 3 weeks" ], 
                    examples: [ 
                        { text: "The order came 5 days early", label: "positive" },
                        { text: "The item exceeded my expectations", label: "positive" }
                    ]})

Generate

See full docs here.

  • prompt: string - required
  • temperature: number. Default 0.75 - optional
  • p: number. Default 0.75 - optional
  • k: number. Default 0 - optional
  • frequency_penalty: number. Default 0 - optional
  • presence_penalty: number. Default 0 - optional
  • max_tokens: number. Default 50 - optional
  • stop_sequences: array of strings - optional
  • return_likelihoods: GENERATION|ALL|NONE. Default NONE - optional
  • num_generations: number. Default 1 - optional
    client.generate(model: "medium", options: { prompt: "What is your name?" })

Response

You can read more about the responses from the endpoints in our official API docs site.

A struct containing:

  • code: http status code of the request
  • body: the body contains a hash with the response body or a message if something went wrong

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also 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. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cohere-ruby. 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 Cohere::Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.