|
1 | | -<!-- Begin Title, generated by Fern --> |
2 | | -# Cohere Python Library |
| 1 | +# Cohere Python SDK |
3 | 2 |
|
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
4 | 7 | [](https://github.com/fern-api/fern) |
5 | 8 |
|
6 | | -The Cohere Python Library provides convenient access to the Cohere API from applications written in Python. |
7 | | -<!-- End Title --> |
| 9 | +The Cohere Python SDK provides access to the Cohere API from Python. |
| 10 | + |
| 11 | +## ✨🪩✨ Announcing Cohere's new Python SDK ✨🪩✨ |
| 12 | + |
| 13 | +We are very excited to publish this brand new Python SDK. We will continuously update this library with all of the latest features in our API. Please create issues where you have feedback so that we can continue to improve the developer experience! |
| 14 | + |
| 15 | +## Documentation |
8 | 16 |
|
9 | | -<!-- Begin Installation, generated by Fern --> |
10 | | -# Installation |
| 17 | +Cohere documentation and API reference is available [here](https://docs.cohere.com/). |
11 | 18 |
|
12 | | -```sh |
13 | | -pip install --upgrade cohere |
| 19 | +## Installation |
| 20 | + |
| 21 | +``` |
| 22 | +pip install --pre --upgrade cohere |
14 | 23 | ``` |
15 | | -<!-- End Installation --> |
16 | 24 |
|
17 | | -<!-- Begin Usage, generated by Fern --> |
18 | | -# Usage |
| 25 | +## Usage |
| 26 | + |
| 27 | +```Python |
| 28 | +import cohere |
| 29 | +from cohere.client import ClassifyExample, ParseInfo |
19 | 30 |
|
20 | | -```python |
21 | | -from cohere.client import Client |
| 31 | +co = cohere.Client( |
| 32 | + api_key="YOUR_API_KEY", |
| 33 | +) |
22 | 34 |
|
23 | | -client = Client( |
24 | | - client_name="YOUR_CLIENT_NAME", |
25 | | - token="YOUR_TOKEN", |
| 35 | +chat = co.chat( |
| 36 | + message="hello world!", |
| 37 | + model="command" |
26 | 38 | ) |
| 39 | + |
| 40 | +print(chat) |
27 | 41 | ``` |
28 | | -<!-- End Usage --> |
29 | 42 |
|
30 | | -<!-- Begin Async Usage, generated by Fern --> |
31 | | -# Async Client |
| 43 | +## Streaming |
32 | 44 |
|
33 | | -```python |
34 | | -from cohere.client import AsyncClient |
| 45 | +The SDK supports streaming endpoints. To take advantage of this feature for chat, |
| 46 | +use `chat_stream`. |
35 | 47 |
|
36 | | -client = AsyncClient( |
37 | | - client_name="YOUR_CLIENT_NAME", |
38 | | - token="YOUR_TOKEN", |
| 48 | +```Python |
| 49 | +import cohere |
| 50 | +from cohere.client import ClassifyExample, ParseInfo |
| 51 | + |
| 52 | +co = cohere.Client( |
| 53 | + api_key="YOUR_API_KEY", |
39 | 54 | ) |
| 55 | + |
| 56 | +stream = co.chat_stream( |
| 57 | + message="Tell me a short story" |
| 58 | +) |
| 59 | + |
| 60 | +for event in stream: |
| 61 | + if event.event_type == "text-generation": |
| 62 | + print(event.text, end='') |
40 | 63 | ``` |
41 | | -<!-- End Async Usage --> |
42 | 64 |
|
43 | | -<!-- Begin Status, generated by Fern --> |
44 | | -# Beta Status |
| 65 | +## Alpha status |
45 | 66 |
|
46 | | -This SDK is in beta, and there may be breaking changes between versions without a major |
47 | | -version update. Therefore, we recommend pinning the package version to a specific version. |
48 | | -This way, you can install the same version each time without breaking changes. |
49 | | -<!-- End Status --> |
| 67 | +This SDK is in alpha, and while we will try to avoid it, there may be breaking changes between versions without a major version update. Therefore, we recommend pinning the package version to a specific version in your package.json file. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version. |
50 | 68 |
|
51 | | -<!-- Begin Contributing, generated by Fern --> |
52 | | -# Contributing |
| 69 | +## Contributing |
53 | 70 |
|
54 | | -While we value open-source contributions to this SDK, this library is generated programmatically. |
55 | | -Additions made directly to this library would have to be moved over to our generation code, |
56 | | -otherwise they would be overwritten upon the next generated release. Feel free to open a PR as |
57 | | - a proof of concept, but know that we will not be able to merge it as-is. We suggest opening |
58 | | -an issue first to discuss with us! |
| 71 | +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! |
59 | 72 |
|
60 | 73 | On the other hand, contributions to the README are always very welcome! |
61 | | -<!-- End Contributing --> |
62 | | - |
|
0 commit comments