Skip to content

Commit

Permalink
Add openai conditional dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
dannon committed Mar 28, 2023
1 parent c8e0645 commit f54f382
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/galaxy/dependencies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions lib/galaxy/dependencies/conditional-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ python-pam
galaxycloudrunner
pkce
total-perspective-vortex<3
openai

# For file sources plugins
fs.webdavfs>=0.4.2 # type: webdav
Expand Down
7 changes: 5 additions & 2 deletions lib/galaxy/webapps/galaxy/api/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f54f382

Please sign in to comment.