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

Uploaded Source

Built Distribution

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

cohere-5.20.4-py3-none-any.whl (319.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cohere-5.20.4.tar.gz
  • Upload date:
  • Size: 180.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.9.25 Linux/6.11.0-1018-azure

File hashes

Hashes for cohere-5.20.4.tar.gz
Algorithm Hash digest
SHA256 3b3017048ff5d5b4f113180947d538ca3d0f274de5875f0345be4c8cb3d5119a
MD5 baaf4688d75dc1ea162894cedf1e8bde
BLAKE2b-256 353765af9c50b5d5772a5528c6a949799f98ae286b8ebb924e0fac0619b3ae88

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for cohere-5.20.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9cc6ebb0adac3d9f96ac0efffde6a2484534fb0aec3684a62c250d49da958f29
MD5 869eddf03b89551614d611a0e2e20ed6
BLAKE2b-256 6d145c5077c6b01aed7a18dfc5ab775a35c7a6cb118e5bc1dafcfc06abdb9d9e

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