Skip to content

Commit

Permalink
added more openai error handling (#888)
Browse files Browse the repository at this point in the history
  • Loading branch information
ieaves authored Mar 26, 2024
1 parent 233658c commit f2b2f25
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion grai-server/app/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "the_guide"
version = "0.1.59"
version = "0.1.60"
description = ""
authors = ["Grai <[email protected]>"]
license = "Elastic-2.0"
Expand Down
2 changes: 1 addition & 1 deletion grai-server/app/the_guide/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# Django starts so that shared_task will use this app.
from .celery import app as celery_app

__version__ = "0.1.59"
__version__ = "0.1.60"
__all__ = ("celery_app", "__version__")
6 changes: 6 additions & 0 deletions grai-server/app/the_guide/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,12 @@ def inner(value: str | bool) -> bool:
except openai.AuthenticationError as e:
warnings.warn("Could not authenticate with OpenAI API key and organization id.")
HAS_OPENAI = False
except openai.APIConnectionError as e:
warnings.warn("Could not connect to OpenAI API and are disabling AI functionality.")
HAS_OPENAI = False
except Exception as e:
warnings.warn(f"We encountered an unknown error while trying to connect to OpenAI {e}")
HAS_OPENAI = False
else:
if len(models) == 0:
message = f"Provided OpenAI API key does not have access to any models as a result we've disabled OpenAI."
Expand Down

0 comments on commit f2b2f25

Please sign in to comment.