-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Update cerebras provider #1101
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
base: main
Are you sure you want to change the base?
Update cerebras provider #1101
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Summary
This PR modernizes and fixes the Cerebras LLM provider integration by refactoring the implementation to use OpenAI-compatible format. The key changes include completely rewriting the `CerebrasClient` to use composition with the existing `OpenAIClient` rather than maintaining a custom implementation, adding 7 new Cerebras model mappings, exposing the client via exports, and completing the documentation.The architecture change eliminates ~300 lines of duplicate code by leveraging the existing OpenAI client infrastructure while transforming Cerebras API configuration (baseURL, API keys) and model names to be compatible. The implementation strips the 'cerebras-' prefix from model names when communicating with the actual Cerebras API and properly handles logging categorization. This approach reduces maintenance burden and improves reliability by reusing battle-tested code paths from the OpenAI implementation.
Important Files Changed
Changed Files
Filename | Score | Overview |
---|---|---|
lib/llm/CerebrasClient.ts | 4/5 | Complete refactoring from custom implementation to OpenAI client wrapper, dramatically simplifying the codebase |
lib/llm/LLMProvider.ts | 2/5 | Added 7 new Cerebras model mappings but model names not defined in type schema, risking validation failures |
lib/index.ts | 5/5 | Added missing export for CerebrasClient to make it publicly available |
docs/configuration/models.mdx | 5/5 | Added missing CEREBRAS_API_KEY documentation to complete provider setup instructions |
Confidence score: 3/5
- This PR improves code maintainability by eliminating duplicate implementation but has a type safety issue that could cause runtime failures
- Score reflects the architectural improvement balanced against the missing type definitions for new model names in the schema validation
- Pay close attention to lib/llm/LLMProvider.ts where new model names need to be added to the AvailableModelSchema type definition
Sequence Diagram
sequenceDiagram
participant User
participant Stagehand
participant LLMProvider
participant CerebrasClient
participant OpenAIClient
participant CerebrasAPI as "Cerebras API"
User->>Stagehand: "new Stagehand({modelName: 'cerebras-llama-3.3-70b'})"
Stagehand->>LLMProvider: "getClient(modelName, clientOptions)"
LLMProvider->>LLMProvider: "Check modelToProviderMap['cerebras-llama-3.3-70b']"
LLMProvider->>CerebrasClient: "new CerebrasClient(options)"
CerebrasClient->>CerebrasClient: "Transform model name: remove 'cerebras-' prefix"
CerebrasClient->>OpenAIClient: "new OpenAIClient({baseURL: 'https://api.cerebras.ai/v1'})"
OpenAIClient-->>CerebrasClient: "OpenAI client instance"
CerebrasClient-->>LLMProvider: "CerebrasClient instance"
LLMProvider-->>Stagehand: "LLM client"
Stagehand-->>User: "Stagehand instance"
User->>Stagehand: "page.act('click button')"
Stagehand->>CerebrasClient: "createChatCompletion(options)"
CerebrasClient->>OpenAIClient: "createChatCompletion(options)"
OpenAIClient->>CerebrasAPI: "POST /v1/chat/completions"
CerebrasAPI-->>OpenAIClient: "Chat completion response"
OpenAIClient-->>CerebrasClient: "LLM response"
CerebrasClient-->>Stagehand: "LLM response"
Stagehand-->>User: "Action result"
4 files reviewed, 1 comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Summary
This review covers only the changes made since the last review, not the entire PR. The developer has addressed the previous review feedback by adding the missing Cerebras model identifiers to the `AvailableModelSchema` enum in `types/model.ts`.The change adds seven new Cerebras model identifiers: cerebras-gpt-oss-120b
, cerebras-llama-4-maverick-17b-128e-instruct
, cerebras-llama-4-scout-17b-16e-instruct
, cerebras-qwen-3-235b-a22b-instruct-2507
, cerebras-qwen-3-235b-a22b-thinking-2507
, cerebras-qwen-3-32b
, and cerebras-qwen-3-coder-480b
. This change ensures type validation will work correctly when users specify these newer Cerebras models in their configurations.
The models are appropriately placed in the enum structure, maintaining alphabetical ordering within the Cerebras section and preserving the overall organization of the schema. This addresses the core issue identified in the previous review where the LLM provider code supported these models but the type system would reject them during validation.
Important Files Changed
Changed Files
Filename | Score | Overview |
---|---|---|
types/model.ts | 5/5 | Added seven new Cerebras model identifiers to AvailableModelSchema enum to enable type validation |
Confidence score: 5/5
- This change is safe to merge with minimal risk as it only adds new enum values without modifying existing functionality
- Score reflects the straightforward nature of adding enum values and the fact that this directly addresses the previous review feedback
- No files require special attention as this is a simple type schema update
1 file reviewed, no comments
why
The Cerebras integration was out of date when it came to models and also nonfunctional during testing.
what changed
Updated the Cerebras provider file to work with OpenAI format + added most recently released Cerebras models.
test plan
I used the form_filling_sensible file and the 2048 tests to run through all the Cerebras models in the PR