Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cohere-ai/cohere-python
Python Library for Accessing the Cohere API
https://github.com/cohere-ai/cohere-python
python sdk
Last synced: about 1 month ago
JSON representation
Python Library for Accessing the Cohere API
- Host: GitHub
- URL: https://github.com/cohere-ai/cohere-python
- Owner: cohere-ai
- License: mit
- Created: 2021-01-20T22:43:24.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-06-14T17:53:24.000Z (5 months ago)
- Last Synced: 2024-06-15T10:29:16.576Z (5 months ago)
- Topics: python, sdk
- Language: Python
- Homepage: https://docs.cohere.ai
- Size: 10.7 MB
- Stars: 256
- Watchers: 25
- Forks: 51
- Open Issues: 29
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - cohere-ai/cohere-python - Python Library for Accessing the Cohere API (Python)
README
# Cohere Python SDK
![](banner.png)
[![version badge](https://img.shields.io/pypi/v/cohere)](https://pypi.org/project/cohere/)
![license badge](https://img.shields.io/github/license/cohere-ai/cohere-python)
[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-SDK%20generated%20by%20Fern-brightgreen)](https://github.com/fern-api/fern)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](https://docs.cohere.com/docs/cohere-works-everywhere).
## Documentation
Cohere documentation and API reference is available [here](https://docs.cohere.com/).
## Installation
```
pip install cohere
```## Usage
```Python
import cohereco = 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`.```Python
import cohereco = 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!