- Fix KeyError 'root' in FileGrouper when merging groups with no root-level files - Fix changelog commit parsing breaking on multiline bodies (use %x00 separator) - Add empty choices/content checks in OpenAI, Anthropic, OpenRouter providers - Fix config edit crash when config is empty - Fix validate command using wrong color for 'no staged files' - Add type check for corrupted YAML config (non-dict returns empty dict)
28 lines
965 B
Python
28 lines
965 B
Python
from openai import OpenAI
|
|
|
|
from devgen.providers.base import BaseProvider
|
|
|
|
|
|
class OpenrouterProvider(BaseProvider):
|
|
"""Generates content using OpenRouter (OpenAI-compatible API)."""
|
|
|
|
DISPLAY_NAME = "OpenRouter"
|
|
BASE_URL = "https://openrouter.ai/api/v1"
|
|
DEFAULT_MODEL = "openai/gpt-3.5-turbo"
|
|
|
|
def _generate(self, prompt, api_key, model, **kwargs):
|
|
kwargs.pop("debug", None)
|
|
client = OpenAI(base_url=self.BASE_URL, api_key=api_key)
|
|
response = client.chat.completions.create(
|
|
model=model,
|
|
messages=[{"role": "user", "content": prompt}],
|
|
extra_headers={
|
|
"HTTP-Referer": "https://github.com/S4NKALP/devgen",
|
|
"X-Title": "devgen CLI",
|
|
},
|
|
**kwargs,
|
|
)
|
|
if not response.choices:
|
|
raise RuntimeError(f"OpenRouter returned no choices for model {model!r}.")
|
|
return response.choices[0].message.content or ""
|