generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 119
Add Cohere docs #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add Cohere docs #108
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e7b599e
Create cohere.md
billytrend-cohere 76f55a7
Update mkdocs.yml
billytrend-cohere 85f8579
Update docs/user-guide/concepts/model-providers/cohere.md
billytrend-cohere 3e8e122
Update cohere.md
billytrend-cohere 5a14947
Apply suggestion from @Unshure
billytrend-cohere ea10f94
Apply suggestion from @Unshure
billytrend-cohere c201429
Apply suggestion from @billytrend-cohere
billytrend-cohere eb0e834
Update docs/user-guide/concepts/model-providers/cohere.md
billytrend-cohere File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Cohere | ||
|
|
||
| [Cohere](https://cohere.com) provides cutting-edge language models. These are accessible accessible through OpenAI's SDK via the Compatibility API. This allows easy and portable integration with the Strands Agents SDK using the familiar OpenAI interface. | ||
|
|
||
| ## Installation | ||
|
|
||
| Cohere is configured as an optional dependency in Strands Agents via the openai sdk. To install, run: | ||
|
|
||
| ```bash | ||
| pip install 'strands-agents[openai]' | ||
| ```` | ||
billytrend-cohere marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Usage | ||
|
|
||
| After installing the `openai` package, you can import and initialize the Strands Agents' OpenAI-compatible provider for Cohere models as follows: | ||
|
|
||
| ```python | ||
| from strands import Agent | ||
| from strands.models.openai import OpenAIModel | ||
| from strands_tools import calculator | ||
|
|
||
| model = OpenAIModel( | ||
| client_args={ | ||
| "api_key": "<COHERE_API_KEY>", | ||
| "base_url": "https://api.cohere.ai/compatibility/v1", # Cohere compatibility endpoint | ||
| }, | ||
| model_id="command-a-03-2025" # or see https://docs.cohere.com/docs/models | ||
billytrend-cohere marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| agent = Agent(model=model, tools=[calculator]) | ||
| response = agent("What is 2+2?") | ||
| print(response) | ||
billytrend-cohere marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| ### Client Configuration | ||
|
|
||
| The `client_args` configure the underlying OpenAI-compatible client. When using Cohere, you must set: | ||
|
|
||
| * `api_key`: Your Cohere API key. Get one from the [Cohere Dashboard](https://dashboard.cohere.com). | ||
| * `base_url`: `https://api.cohere.ai/compatibility/v1` | ||
billytrend-cohere marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Refer to [OpenAI Python SDK GitHub](https://github.com/openai/openai-python) for full client options. | ||
|
|
||
| ### Model Configuration | ||
|
|
||
| The `model_config` specifies which Cohere model to use and any additional parameters. | ||
|
|
||
| | Parameter | Description | Example | Options | | ||
| | ---------- | ------------------------- | ------------------------------------------ | ------------------------------------------------------------------ | | ||
| | `model_id` | Model name | `command-r-plus` | See [Cohere docs](https://docs.cohere.com/docs/models) | | ||
| | `params` | Model-specific parameters | `{"max_tokens": 1000, "temperature": 0.7}` | [API reference](https://docs.cohere.com/docs/compatibility-api) | | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### `ModuleNotFoundError: No module named 'openai'` | ||
|
|
||
| You must install the `openai` dependency to use this provider: | ||
|
|
||
| ```bash | ||
| pip install 'strands-agents[openai]' | ||
| ``` | ||
|
|
||
| ### Unexpected model behavior? | ||
|
|
||
| Ensure you're using a model ID compatible with Cohere’s Compatibility API (e.g., `command-r-plus`, `command-a-03-2025`, `embed-v4.0`), and your `base_url` is set to `https://api.cohere.ai/compatibility/v1`. | ||
|
|
||
| ## References | ||
|
|
||
| * [Cohere Docs: Using the OpenAI SDK](https://docs.cohere.com/docs/compatibility-api) | ||
| * [Cohere API Reference](https://docs.cohere.com/reference) | ||
| * [OpenAI Python SDK](https://github.com/openai/openai-python) | ||
| * [Strands Agents API](../../../api-reference/models.md) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.