feat(llm): support Cerebras provider#8
Open
Iro96 wants to merge 1 commit into
Open
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Review Summary by QodoAdd Cerebras LLM provider support with configurable selection
WalkthroughsDescription• Add support for Cerebras LLM provider via LLM_PROVIDER environment variable • Implement provider selection logic with OpenAI as default fallback • Add Cerebras-specific configuration with CEREBRAS_API_KEY and CEREBRAS_BASE_URL • Improve error handling with try-catch blocks for both providers Diagramflowchart LR
A["LLM_PROVIDER env var"] -->|"cerebras"| B["Cerebras Client"]
A -->|"openai or default"| C["OpenAI Client"]
B --> D["CEREBRAS_API_KEY + CEREBRAS_BASE_URL"]
C --> E["OPENAI_API_KEY"]
D --> F["Initialize Client"]
E --> F
F --> G["Set enabled flag"]
File Changes1. llm/client.py
|
Code Review by Qodo
1. Unknown provider defaults
|
Comment on lines
+22
to
55
| # Select provider via environment variable. Supported: "openai" (default), "cerebras". | ||
| provider = os.environ.get("LLM_PROVIDER", "openai").lower() | ||
|
|
||
| if not OpenAI: | ||
| self.enabled = False | ||
| if not OpenAI: | ||
| logger.warning("openai package not installed; LLM calls are mocked") | ||
| logger.warning("openai package not installed; LLM calls are mocked") | ||
| return | ||
|
|
||
| if provider == "cerebras": | ||
| api_key = os.environ.get("CEREBRAS_API_KEY") | ||
| base_url = os.environ.get("CEREBRAS_BASE_URL", "https://api.cerebras.ai/v1") | ||
| if api_key: | ||
| try: | ||
| self.client = OpenAI(base_url=base_url, api_key=api_key) | ||
| self.enabled = True | ||
| except Exception: | ||
| logger.exception("failed to initialize Cerebras LLM client") | ||
| self.enabled = False | ||
| else: | ||
| self.enabled = False | ||
| logger.warning("CEREBRAS_API_KEY not set; LLM calls are mocked") | ||
| else: | ||
| # default: OpenAI | ||
| api_key = os.environ.get("OPENAI_API_KEY") | ||
| if api_key: | ||
| try: | ||
| self.client = OpenAI(api_key=api_key) | ||
| self.enabled = True | ||
| except Exception: | ||
| logger.exception("failed to initialize OpenAI LLM client") | ||
| self.enabled = False | ||
| else: | ||
| self.enabled = False | ||
| logger.warning("OPENAI_API_KEY not set; LLM calls are mocked") |
There was a problem hiding this comment.
1. Unknown provider defaults 🐞 Bug ☼ Reliability
LLMClient treats any LLM_PROVIDER value other than "cerebras" as the OpenAI path, so typos/unsupported providers silently fall back to OPENAI_API_KEY behavior. This can route requests to the wrong provider (including unintended API calls/billing) and makes misconfiguration hard to detect.
Agent Prompt
## Issue description
`LLM_PROVIDER` is parsed, but any value other than `"cerebras"` implicitly falls through to the OpenAI branch. This makes typos/unsupported values silently behave like OpenAI.
## Issue Context
Provider selection is meant to be explicit (`openai` default, `cerebras` optional). The current implementation uses a catch-all `else:` for OpenAI.
## Fix Focus Areas
- llm/client.py[22-55]
### Suggested change
- Replace the catch-all `else:` with explicit handling:
- `if provider == "openai": ...`
- `elif provider == "cerebras": ...`
- `else:` log a warning/error like `Unsupported LLM_PROVIDER=...; supported: openai,cerebras` and set `self.enabled=False` (or raise, depending on desired behavior).
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.