Skip to main content

A Python library for the Cohere API

Project description

Cohere Python SDK

This package provides functionality developed to simplify interfacing with the cohere.ai natural language API in Python 3.

Documentation

See the API's documentation.

Also see some code examples for the SDK here.

Installation

If you want the package, you can install it through pip:

pip install --upgrade cohere

Install from source:

python setup.py install

Requirements

  • Python 3.6+

Usage

import cohere

# initialize the Cohere Client with an API Key
co = cohere.CohereClient('YOUR_API_KEY')

# generate a prediction for a prompt 
prediction = co.generate(
            model="baseline-shrimp",
            prompt="co:here",
            max_tokens=10)

# print the predicted text          
print('prediction: {}'.format(prediction.text))

More usage examples can be found here.

Endpoints

For a full breakdown of endpoints and arguments, please consult the Cohere Docs.

Cohere Endpoint Function
/generate co.generate()
/similarity co.similarity()
/choose-best co.choose_best()
/embed co.embed()
/likelihood co.likelihood()

Models

To view an up-to-date list of available models please consult the Cohere CLI. To get started try out baseline-shrimp or baseline-seal.

Responses

All of the endpoint functions will return some Cohere object (e.g. for generation, it would be Generation). The responses can be found as instance variables of the object (e.g. for generation, it would be Generation.text). The names of these instance variables and a detailed breakdown of the response body can be found in the Cohere Docs.

Exceptions

Unsuccessful API calls from the SDK will raise an exception. Please see the documentation's page on errors for more information about what the errors mean.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cohere-0.0.8.tar.gz (4.8 kB view hashes)

Uploaded Source

Built Distribution

cohere-0.0.8-py3-none-any.whl (6.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page