Skip to content

Commit

Permalink
Wrap OpenAIError in a ConfigError when initializing from config so we…
Browse files Browse the repository at this point in the history
… don't show a full traceback.

Closes #1.
  • Loading branch information
codeofdusk committed Jan 30, 2025
1 parent 148f7d8 commit d8dbbd3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/gptcmd/llm/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ def from_config(cls, conf: Dict):
)
model = conf.get("model")
client_opts = {k: v for k, v in conf.items() if k not in SPECIAL_OPTS}
client = openai.OpenAI(**client_opts)
try:
client = openai.OpenAI(**client_opts)
except openai.OpenAIError as e:
# Import late to avoid circular import
from ..config import ConfigError

raise ConfigError(str(e)) from e
return cls(client, model=model)

def _message_to_openai(self, msg: Message) -> Dict[str, Any]:
Expand Down

0 comments on commit d8dbbd3

Please sign in to comment.