Skip to main content

No project description provided

Project description

Cohere Python SDK

version badge license badge fern shield

The Cohere Python SDK provides access to the Cohere API from Python.

✨🪩✨ Announcing Cohere's new Python SDK ✨🪩✨

We are very excited to publish this brand-new Python SDK. We will continuously update this library with all the latest features in our API. Please create issues where you have feedback so that we can continue to improve the developer experience!

cohere==5.0.0 Migration Guide

We have created a migration guide to help you through the process. If you have any questions, please feel free to open an issue and we will respond to you asap.

Documentation

Cohere documentation and API reference is available here.

Installation

pip install cohere

Usage

import cohere

co = cohere.Client(
    api_key="YOUR_API_KEY",
)

chat = co.chat(
    message="hello world!",
    model="command"
)

print(chat)

[!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.Client(
    api_key="YOUR_API_KEY",
)

stream = co.chat_stream(
    message="Tell me a short story"
)

for event in stream:
    if event.event_type == "text-generation":
        print(event.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

This version

5.1.8

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.1.8.tar.gz (70.4 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.1.8-py3-none-any.whl (145.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cohere-5.1.8.tar.gz
  • Upload date:
  • Size: 70.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.8.18 Linux/5.15.0-1059-azure

File hashes

Hashes for cohere-5.1.8.tar.gz
Algorithm Hash digest
SHA256 2ce7e8541c834d5c01991ededf1d1535f76fef48515fb06dc00f284b62245b9c
MD5 7d08e26febf095bce28189ad0f4b42f0
BLAKE2b-256 bcc886948065798e0ef0d3b0f52f25c920e9efeb33fd2d30fc0a9c88cead6b9c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for cohere-5.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 420ebd0fe8fb34c69adfd6081d75cd3954f498f27dff44e0afa539958e9179ed
MD5 7ca68adf4c44b32bd52a91e89da169e3
BLAKE2b-256 6b33cbd4515be32f5ed31fcfe75e2b3a28f98d1e9376d24ef359fc487348bbed

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