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

Bilalkamal/add cerebras provider #109

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# OpenAI API Key
OPENAI_API_KEY=

# Cerebras API Key
CEREBRAS_API_KEY=

# Anthropic API Key
ANTHROPIC_API_KEY=

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ __pycache__/
env/
.env
.google-adc
.DS_Store
aisuite/.DS_Store

26 changes: 26 additions & 0 deletions aisuite/providers/cerebras_provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os

from cerebras.cloud.sdk import Cerebras
from aisuite.provider import Provider


class CerebrasProvider(Provider):
def __init__(self, **config):
"""
Initialize the Cerebras provider with the given configuration.
Pass the entire configuration dictionary to the Cerebras client constructor.
"""
# Ensure API key is provided either in config or via environment variable
config.setdefault("api_key", os.getenv("CEREBRAS_API_KEY"))
if not config["api_key"]:
raise ValueError(
" API key is missing. Please provide it in the config or set the CEREBRAS_API_KEY environment variable."
)
self.client = Cerebras(**config)

def chat_completions_create(self, model, messages, **kwargs):
return self.client.chat.completions.create(
model=model,
messages=messages,
**kwargs # Pass any additional arguments to the Cerebras API
)
1 change: 1 addition & 0 deletions guides/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Here're the instructions for:
- [Google](google.md)
- [Hugging Face](huggingface.md)
- [OpenAI](openai.md)
- [Cerebras](cerebras.md)

Unless otherwise stated, these guides have not been endorsed by the providers.

Expand Down
42 changes: 42 additions & 0 deletions guides/cerebras.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Cerebras

To use Cerebras with `aisuite`, you'll need a [Cerebras account](https://console.cerebras.net/). After logging in, navigate to your account settings to generate an API key. Once you have your key, add it to your environment as follows:

```shell
export CEREBRAS_API_KEY="your-cerebras-api-key"
```

## Create a Chat Completion

Install the `cerebras` Python client:

Example with pip:
```shell
pip install cerebras_cloud_sdk
```

Example with poetry:
```shell
poetry add cerebras_cloud_sdk
```

In your code:
```python
import aisuite as ai
client = ai.Client()

provider = "cerebras"
model_id = "llama3.1-8b"


messages = [
{"content": "Why is fast inference important?"},
]

response = client.chat.completions.create(provider=provider, model_id=model_id, messages=messages)

print(response.choices[0].message.content)

```

Happy coding! If you’d like to contribute, please read our [Contributing Guide](CONTRIBUTING.md).
16 changes: 14 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
[tool.poetry]
name = "aisuite"
version = "0.1.6"
version = "0.1.7"
description = "Uniform access layer for LLMs"
authors = ["Andrew Ng"]
maintainers = [
{ email = "[email protected]" },
{ name = "Kevin Solorio" },
{ name = "Rohit Prasad", email = "[email protected]" },
{ name = "Jeff Tang" },
{ name = "Andrew Ng" },
{ name = "John Santerre" },
{ name = "Zachary Bloss", email = "[email protected]" },
{ email = "rohit-rptless" },
{ name = "Bilal Kamal", email = "[email protected]" }
]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.10"
anthropic = { version = "^0.30.1", optional = true }
boto3 = { version = "^1.34.144", optional = true }
cerebras-cloud-sdk = { version = "^1.12.2", optional = true }
vertexai = { version = "^1.63.0", optional = true }
groq = { version = "^0.9.0", optional = true }
mistralai = { version = "^1.0.3", optional = true }
Expand All @@ -25,7 +37,7 @@ huggingface = []
mistral = ["mistralai"]
ollama = []
openai = ["openai"]
all = ["anthropic", "aws", "google", "groq", "mistral", "openai"] # To install all providers
all = ["anthropic", "aws", "google", "groq", "mistral", "openai", "cerebras-cloud-sdk"] # To install all providers

[tool.poetry.group.dev.dependencies]
pytest = "^8.2.2"
Expand Down