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

Uploaded Source

Built Distribution

cohere-5.14.0-py3-none-any.whl (253.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cohere-5.14.0.tar.gz
  • Upload date:
  • Size: 133.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.9.21 Linux/5.15.0-1079-azure

File hashes

Hashes for cohere-5.14.0.tar.gz
Algorithm Hash digest
SHA256 fdbf2d4c54049b74c8f79ff8ed6fd149c4c2055d3b5eae57b9c70716e65c78fd
MD5 66cc694b9ce46a76478c690d2c8790ea
BLAKE2b-256 03dadc4b93a44e9d34cdc27e5b90c2abe7e4180d9c0ac515ed8938257175a881

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cohere-5.14.0-py3-none-any.whl
  • Upload date:
  • Size: 253.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.9.21 Linux/5.15.0-1079-azure

File hashes

Hashes for cohere-5.14.0-py3-none-any.whl
Algorithm Hash digest
SHA256 286b4ff66f9a59c06a30b8819fb8b2aee3354dc2f7dc83f19519da771e598a5e
MD5 73e102cfc79bc079493a31cc4c22f75b
BLAKE2b-256 52a752db5d464ca0956a31e510fe9327997759dff7ae16a16a05ab748261fd69

See more details on using hashes here.

Supported by

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