diff --git a/lib/galaxy/dependencies/__init__.py b/lib/galaxy/dependencies/__init__.py index 79526e490304..42d2ea49a339 100644 --- a/lib/galaxy/dependencies/__init__.py +++ b/lib/galaxy/dependencies/__init__.py @@ -280,6 +280,9 @@ def check_influxdb(self): def check_tensorflow(self): return asbool(self.config["enable_tool_recommendations"]) + def check_openai(self): + return self.config.get("openai_api_key", None) is not None + def check_weasyprint(self): # See notes in ./conditional-requirements.txt for more information. return os.environ.get("GALAXY_DEPENDENCIES_INSTALL_WEASYPRINT") == "1" diff --git a/lib/galaxy/dependencies/conditional-requirements.txt b/lib/galaxy/dependencies/conditional-requirements.txt index 8d8a5d9bd55c..28335c054a96 100644 --- a/lib/galaxy/dependencies/conditional-requirements.txt +++ b/lib/galaxy/dependencies/conditional-requirements.txt @@ -14,6 +14,7 @@ python-pam galaxycloudrunner pkce total-perspective-vortex<3 +openai # For file sources plugins fs.webdavfs>=0.4.2 # type: webdav diff --git a/lib/galaxy/webapps/galaxy/api/chat.py b/lib/galaxy/webapps/galaxy/api/chat.py index a2fbc1a8d387..1bbbe1dab3e9 100644 --- a/lib/galaxy/webapps/galaxy/api/chat.py +++ b/lib/galaxy/webapps/galaxy/api/chat.py @@ -3,7 +3,10 @@ """ import logging -import openai +try: + import openai +except ImportError: + openai = None from galaxy.config import GalaxyAppConfiguration from galaxy.exceptions import ConfigurationError @@ -31,7 +34,7 @@ class ChatAPI: def query(self, query: ChatPayload) -> str: """We're off to ask the wizard""" - if self.config.openai_api_key is None: + if openai is None or self.config.openai_api_key is None: raise ConfigurationError("OpenAI is not configured for this instance.") else: openai.api_key = self.config.openai_api_key