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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file cohere-0.0.8.tar.gz.

File metadata

  • Download URL: cohere-0.0.8.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for cohere-0.0.8.tar.gz
Algorithm Hash digest
SHA256 c155a250e673f11fe24ce010915d555408fa6baf526b261d492893313ebfc434
MD5 aa86de9559995038d59b755153085328
BLAKE2b-256 4f32a22fea429ea73e524b663c6e01067e6e1d8118ad9704043cde151a83e7e2

See more details on using hashes here.

File details

Details for the file cohere-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: cohere-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for cohere-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 b8896d104b3aa9626851498c979adfb10ea4084e65d793ade1a4fb05a88acd64
MD5 785f72bb5fbe19c12d0959a22ef9edeb
BLAKE2b-256 a3295a011e36d21f3bd0ce1f8240515fc3f0067b8f9ab07287191ba2813606ae

See more details on using hashes here.

Supported by

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