Skip to content
Open
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
38 changes: 31 additions & 7 deletions llm/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,39 @@ def __init__(self, model: str = "gpt-4.1", temperature: float = 0.2):
self.temperature = temperature
self.client = None

api_key = os.environ.get("OPENAI_API_KEY")
if OpenAI and api_key:
self.client = OpenAI(api_key=api_key)
self.enabled = True
else:
# 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")
Comment on lines +22 to 55

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


def _mock_response(self, prompt: str) -> str:
Expand Down
Loading