From 5e4852bd32610699d449716eee51c17e1c39fe25 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Thu, 6 Feb 2025 09:49:40 -0800 Subject: [PATCH] refactor: Optimize exception lookup using a set in LiteLLMExceptions --- aider/exceptions.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/aider/exceptions.py b/aider/exceptions.py index e3401c209..bd5d2f8b4 100644 --- a/aider/exceptions.py +++ b/aider/exceptions.py @@ -51,6 +51,7 @@ EXCEPTIONS = [ class LiteLLMExceptions: exceptions = dict() + exception_names = {exi.name for exi in EXCEPTIONS} def __init__(self): self._load() @@ -63,11 +64,11 @@ class LiteLLMExceptions: continue ex_info = None - # collect these names into a set once, above ai! - for exi in EXCEPTIONS: - if var == exi.name: - ex_info = exi - break + if var in self.exception_names: + for exi in EXCEPTIONS: + if var == exi.name: + ex_info = exi + break if strict and not ex_info: raise ValueError(f"{var} is in litellm but not in aider's exceptions list")