Skip to main content

No project description provided

Project description

ci badge version badge license badge

Cohere Python SDK

This package provides functionality developed to simplify interfacing with the Cohere API in Python 3.

Documentation

  • SDK Documentation is hosted on Read the docs.
    • You can build SDK documentation locally using cd docs; make clean html.
  • For more details on advanced parameters, you can also consult the API documentation.
  • See the examples directory for examples, including some additional functionality for visualizations in Jupyter notebooks.

Installation

The package can be installed with pip:

pip install --upgrade cohere

Install from source:

pip install .

Requirements

  • Python 3.7+

Quick Start

To use this library, you must have an API key and specify it as a string when creating the cohere.Client object. API keys can be created through the platform. This is a basic example of the creating the client and using the generate endpoint.

import cohere

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

# generate a prediction for a prompt
prediction = co.generate(
            model='large',
            prompt='co:here',
            max_tokens=10)

# print the predicted text
print('prediction: {}'.format(prediction.generations[0].text))

There is also an asyncio compatible client called cohere.AsyncClient with an equivalent interface. Consult the SDK Docs for more details.

Versioning

Each SDK release is only compatible with the latest version of the Cohere API at the time of release. To use the SDK with an older API version, you need to download a version of the SDK tied to the API version you want. Look at the Changelog to see which SDK version to download.

Endpoints

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

Cohere Endpoint Function
/generate co.generate()
/embed co.embed()
/classify co.classify()
/tokenize co.tokenize()
/detokenize co.detokenize()
/detect-language co.detect_language()

Models

When you call Cohere's APIs we decide on a good default model for your use-case behind the scenes. The default model is great to get you started, but in production environments we recommend that you specify the model size yourself via the model parameter. Learn more about the available models here(https://os.cohere.ai)

Responses

All of the endpoint functions will return a Cohere object corresponding to the endpoint (e.g. for generation, it would be Generation). The responses can be found as instance variables of the object (e.g. generation would be Generation.text). The names of these instance variables and a detailed breakdown of the response body can be found in the SDK Docs and Cohere Docs. Printing the Cohere response object itself will display an organized view of the instance variables.

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.

Contributing

To set up a development environment, run:

poetry shell    # any time you want to run code or tests
poetry install  # install and update dependencies in your environment, the first time

In addition, to ensure your code is formatted correctly, install pre-commit hooks using:

pre-commit install

You can run tests locally using:

python -m pytest

You can configure a different base url with:

CO_API_URL="https://localhost:8050" python3 foo.py

or

cohere.COHERE_API_URL = "https://localhost:8050" # Place before client initilization

Project details


Release history Release notifications | RSS feed

This version

4.7.0

Download files

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

Source Distribution

cohere-4.7.0.tar.gz (26.2 kB view details)

Uploaded Source

Built Distribution

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

cohere-4.7.0-py3-none-any.whl (33.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cohere-4.7.0.tar.gz
  • Upload date:
  • Size: 26.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for cohere-4.7.0.tar.gz
Algorithm Hash digest
SHA256 46c674545ad36133a555c6db7f25bdc299e05ec4f77dee707b661a57eb06aea6
MD5 212585d79e966be4a8f59df05fb69210
BLAKE2b-256 b23daa3bbcbe80d81bb11ae479953ebed5864e229ff7dc7290f6493e0ec6460a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cohere-4.7.0-py3-none-any.whl
  • Upload date:
  • Size: 33.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for cohere-4.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed15621bd271b941110a572cbf6187a4db78cc8d7d9d35a881bffcaeeea21d7c
MD5 7a6b36c9d15a8e2a219f657904f3fb1c
BLAKE2b-256 560c456b374940232df19310759009ce4c96e9b492c21df3e38ae5c540670dac

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