Skip to main content

No project description provided

Project description

Cohere Python SDK

version badge license badge fern shield

The Cohere Python SDK allows access to Cohere models across many different platforms: the cohere platform, AWS (Bedrock, Sagemaker), Azure, GCP and Oracle OCI. For a full list of support and snippets, please take a look at the SDK support docs page.

Documentation

Cohere documentation and API reference is available here.

Installation

pip install cohere

Usage

import cohere

co = cohere.ClientV2()

response = co.chat(
    model="command-r-plus-08-2024",
    messages=[{"role": "user", "content": "hello world!"}],
)

print(response)

[!TIP] You can set a system environment variable CO_API_KEY to avoid writing your api key within your code, e.g. add export CO_API_KEY=theapikeyforyouraccount in your ~/.zshrc or ~/.bashrc, open a new terminal, then code calling cohere.Client() will read this key.

Streaming

The SDK supports streaming endpoints. To take advantage of this feature for chat, use chat_stream.

import cohere

co = cohere.ClientV2()

response = co.chat_stream(
    model="command-r-plus-08-2024",
    messages=[{"role": "user", "content": "hello world!"}],
)

for event in response:
    if event.type == "content-delta":
        print(event.delta.message.content.text, end="")

Contributing

While we value open-source contributions to this SDK, the code is generated programmatically. Additions made directly would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!

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-5.16.1.tar.gz (162.3 kB view details)

Uploaded Source

Built Distribution

cohere-5.16.1-py3-none-any.whl (291.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cohere-5.16.1.tar.gz
  • Upload date:
  • Size: 162.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.9.23 Linux/6.11.0-1015-azure

File hashes

Hashes for cohere-5.16.1.tar.gz
Algorithm Hash digest
SHA256 02aa87668689ad0fbac2cda979c190310afdb99fb132552e8848fdd0aff7cd40
MD5 1f1d4229486389c1395ef42f73b4fb6b
BLAKE2b-256 edc7fd1e4c61cf3f0aac9d9d73fce63a766c9778e1270f7a26812eb289b4851d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cohere-5.16.1-py3-none-any.whl
  • Upload date:
  • Size: 291.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.9.23 Linux/6.11.0-1015-azure

File hashes

Hashes for cohere-5.16.1-py3-none-any.whl
Algorithm Hash digest
SHA256 37e2c1d69b1804071b5e5f5cb44f8b74127e318376e234572d021a1a729c6baa
MD5 8da7a1af5c48ce14c76ed4b5d2260ae4
BLAKE2b-256 82c672309ac75f3567425ca31a601ad394bfee8d0f4a1569dfbc80cbb2890d07

See more details on using hashes here.

Supported by

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