Skip to content
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

Add Cohere provider #111

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Bilalkamal
Copy link

Add Cohere Provider Support

Description

Added support for Cohere, to expand aisuite's provider options.

Changes Made

  • Added Cohere provider implementation in providers/cohere_provider.py
  • Added necessary environment variables for Cohere API authentication
  • Implemented provider class following the convention CohereProvider
  • Added type hints and documentation following project standards

Testing

  • Tested provider initialization
  • Verified API connection and authentication
  • Tested chat completion functionality
  • All existing tests pass

Environment Variables Added

CO_API_KEY=

Related Documentation

  • Added Cohere to the list of supported providers in README.md

Checklist

  • Code follows project style guidelines
  • Updated documentation
  • Pre-commit hooks pass

@@ -0,0 +1,42 @@
# Cohere

To use Cohere with `aisuite`, you’ll need an [Cohere account](https://cohere.com/). After logging in, go to the [API Keys](https://dashboard.cohere.com/api-keyss) section in your account settings, agree to the terms of service, connect your card, and generate a new key. Once you have your key, add it to your environment as follows:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To use Cohere with `aisuite`, you’ll need an [Cohere account](https://cohere.com/). After logging in, go to the [API Keys](https://dashboard.cohere.com/api-keyss) section in your account settings, agree to the terms of service, connect your card, and generate a new key. Once you have your key, add it to your environment as follows:
To use Cohere with `aisuite`, you’ll need an [Cohere account](https://cohere.com/). After logging in, go to the [API Keys](https://dashboard.cohere.com/api-keys) section in your account settings, agree to the terms of service, connect your card, and generate a new key. Once you have your key, add it to your environment as follows:


## Create a Chat Completion

Install the `openai` Python client:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Install the `openai` Python client:
Install the `cohere` Python client:

Comment on lines +25 to +39
import aisuite as ai
client = ai.Client()

model_id = "command-r-plus-08-2024"

messages=[
{"role": "user", "content": "Hi, how are you?"}
]

response = client.chat(
model=f"{model_id}",
messages=messages,
)

print(response)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import aisuite as ai
client = ai.Client()
model_id = "command-r-plus-08-2024"
messages=[
{"role": "user", "content": "Hi, how are you?"}
]
response = client.chat(
model=f"{model_id}",
messages=messages,
)
print(response)
import aisuite as ai
client = ai.Client()
provider = "cohere"
model_id = "command-r-plus-08-2024"
messages = [
{"role": "user", "content": "Hi, how are you?"}
]
response = client.chat.completions.create(
model=f"{provider}:{model_id}",
messages=messages,
)
print(response.choices[0].message.content)

Comment on lines +21 to +25
return self.client.chat(
model=model,
messages=messages,
**kwargs # Pass any additional arguments to the Cohere API
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this return an compliant response, as in response.choices[0].message.content would work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants