Skip to content

feat(llm): support Cerebras provider#8

Open
Iro96 wants to merge 1 commit into
mainfrom
dev/support-other-providers
Open

feat(llm): support Cerebras provider#8
Iro96 wants to merge 1 commit into
mainfrom
dev/support-other-providers

Conversation

@Iro96
Copy link
Copy Markdown
Owner

@Iro96 Iro96 commented Jun 2, 2026

No description provided.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@qodo-code-review
Copy link
Copy Markdown

Review Summary by Qodo

Add Cerebras LLM provider support with configurable selection

✨ Enhancement

Grey Divider

Walkthroughs

Description
• 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
Diagram
flowchart 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"]

Loading

Grey Divider

File Changes

1. llm/client.py ✨ Enhancement +31/-7

Multi-provider LLM client with Cerebras support

• Refactored LLM client initialization to support multiple providers via LLM_PROVIDER environment
 variable
• Added Cerebras provider support with custom base URL and API key configuration
• Implemented provider-specific error handling with try-catch blocks for both OpenAI and Cerebras
• Improved code structure with early return for missing OpenAI package and clearer provider
 selection logic

llm/client.py


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown

qodo-code-review Bot commented Jun 2, 2026

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0)

Grey Divider


Action required

1. Unknown provider defaults 🐞 Bug ☼ Reliability
Description
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.
Code

llm/client.py[R22-55]

Evidence
The implementation compares only against "cerebras" and routes all other provider values through the
OpenAI initialization branch, with no validation/diagnostic for unsupported values.

llm/client.py[22-55]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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



Remediation recommended

2. Misleading mock guidance 🐞 Bug ◔ Observability
Description
When Cerebras is selected but the client is disabled (e.g., missing CEREBRAS_API_KEY),
generate_text() still tells operators to set OPENAI_API_KEY. This conflicts with the new provider
behavior and increases time to diagnose configuration issues.
Code

llm/client.py[R30-55]

Evidence
The new Cerebras branch correctly warns about missing CEREBRAS_API_KEY, but the runtime fallback
string returned from generate_text() still references OPENAI_API_KEY unconditionally when
self.enabled is false.

llm/client.py[30-43]
llm/client.py[84-87]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
After adding a Cerebras provider, the mocked/fallback user guidance in `generate_text()` still hardcodes `OPENAI_API_KEY`, which is incorrect when `LLM_PROVIDER=cerebras`.

## Issue Context
Init-time warnings are provider-specific (e.g., `CEREBRAS_API_KEY not set`), but `generate_text()` returns a generic OpenAI-specific hint when `self.enabled` is false.

## Fix Focus Areas
- llm/client.py[22-55]
- llm/client.py[84-87]

### Suggested change
- Store the selected provider on the instance (e.g., `self.provider = provider`).
- Update `generate_text()` to return provider-specific remediation text:
 - If provider is `cerebras`: instruct to set `CEREBRAS_API_KEY` (and optionally `CEREBRAS_BASE_URL`).
 - If provider is `openai`: instruct to set `OPENAI_API_KEY`.
 - Otherwise: generic "set provider API key" message.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

Comment thread llm/client.py
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")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

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

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.

1 participant