No project description provided
Project description
Cohere Python SDK
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.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. addexport CO_API_KEY=theapikeyforyouraccount
in your ~/.zshrc or ~/.bashrc, open a new terminal, then code callingcohere.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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cohere-5.11.4.tar.gz
.
File metadata
- Download URL: cohere-5.11.4.tar.gz
- Upload date:
- Size: 129.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.8.18 Linux/5.15.0-1074-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5586335a20de3bf6816f34151f9d9f2928880cdf776c57aae793b5cca58d1826 |
|
MD5 | 076be2d32b96b98c5206e5e42b8ba434 |
|
BLAKE2b-256 | 9a457aff8f9b24fe926a8f092491e56a90560ed2227d1dfdf1b9ada665f607ed |
File details
Details for the file cohere-5.11.4-py3-none-any.whl
.
File metadata
- Download URL: cohere-5.11.4-py3-none-any.whl
- Upload date:
- Size: 249.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.8.18 Linux/5.15.0-1074-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59fb427e5426e0ee1c25b9deec83f0418a1c082240c57007f41384b34cd41552 |
|
MD5 | 40067bc721413b01ed73d92fccafafb6 |
|
BLAKE2b-256 | 535c909862a2eb2a0eaf3bc2024058207e342286e015d60ff03fe38f3efdde6d |