Skip to content

Commit

Permalink
Add Cerebras to OpenAI Plugin (livekit#731)
Browse files Browse the repository at this point in the history
  • Loading branch information
henrytwo authored Sep 9, 2024
1 parent 2f722cf commit 0007461
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/swift-dodos-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-plugins-openai": patch
---

Add Cerebras to OpenAI Plugin
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ from livekit.plugins.openai.llm import LLM

- OpenAI: `LLM(model="gpt-4o")`
- Azure: `LLM.with_azure(azure_endpoint="", azure_deployment="")`
- Cerebras: `LLM.with_cerebras(api_key="", model="")`
- Fireworks: `LLM.with_fireworks(api_key="", model="")`
- Groq: `LLM.with_groq(api_key="", model="")`
- OctoAI: `LLM.with_octo(api_key="", model="")`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

from .log import logger
from .models import (
CerebrasChatModels,
ChatModels,
DeepSeekChatModels,
GroqChatModels,
Expand Down Expand Up @@ -121,6 +122,31 @@ def with_azure(

return LLM(model=model, client=azure_client, user=user)

@staticmethod
def with_cerebras(
*,
model: str | CerebrasChatModels = "llama3.1-8b",
api_key: str | None = None,
base_url: str | None = "https://api.cerebras.ai/v1",
client: openai.AsyncClient | None = None,
user: str | None = None,
) -> LLM:
"""
Create a new instance of Cerebras LLM.
``api_key`` must be set to your Cerebras API key, either using the argument or by setting
the ``CEREBRAS_API_KEY`` environmental variable.
"""

# shim for not using OPENAI_API_KEY
api_key = api_key or os.environ.get("CEREBRAS_API_KEY")
if api_key is None:
raise ValueError("Cerebras API key is required")

return LLM(
model=model, api_key=api_key, base_url=base_url, client=client, user=user
)

@staticmethod
def with_fireworks(
*,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@

# adapters for OpenAI-compatible LLMs

CerebrasChatModels = Literal[
"llama3.1-8b",
"llama3.1-70b",
]

PerplexityChatModels = Literal[
"llama-3.1-sonar-small-128k-online",
"llama-3.1-sonar-small-128k-chat",
Expand Down

0 comments on commit 0007461

Please sign in to comment.