Skip to content

Commit

Permalink
Refactor chat prompts loading to check for OpenAI API key configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
dannon committed Jan 9, 2025
1 parent e251c07 commit 97de7f3
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions lib/galaxy/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,8 +1093,9 @@ def _process_config(self, kwargs: Dict[str, Any]) -> None:

self._process_celery_config()

# load in the chat_prompts if openai is enabled
self._load_chat_prompts()
# load in the chat_prompts if openai api key is configured
if self.openai_api_key:
self._load_chat_prompts()

self.pretty_datetime_format = expand_pretty_datetime_format(self.pretty_datetime_format)
try:
Expand Down Expand Up @@ -1257,21 +1258,20 @@ def _load_theme(path: str, theme_dict: dict):
self.file_source_temp_dir = os.path.abspath(self.file_source_temp_dir)

def _load_chat_prompts(self):
if self.openai_api_key:
current_dir = os.path.dirname(os.path.abspath(__file__))
chat_prompts_path = os.path.join(current_dir, "chat_prompts.json")
current_dir = os.path.dirname(os.path.abspath(__file__))
chat_prompts_path = os.path.join(current_dir, "chat_prompts.json")

if os.path.exists(chat_prompts_path):
try:
with open(chat_prompts_path, encoding="utf-8") as file:
data = json.load(file)
self.chat_prompts = data.get("prompts", {})
except json.JSONDecodeError as e:
log.error(f"JSON decoding error in chat prompts file: {e}")
except Exception as e:
log.error(f"An error occurred while reading chat prompts file: {e}")
else:
log.warning(f"Chat prompts file not found at {chat_prompts_path}")
if os.path.exists(chat_prompts_path):
try:
with open(chat_prompts_path, encoding="utf-8") as file:
data = json.load(file)
self.chat_prompts = data.get("prompts", {})
except json.JSONDecodeError as e:
log.error(f"JSON decoding error in chat prompts file: {e}")
except Exception as e:
log.error(f"An error occurred while reading chat prompts file: {e}")
else:
log.warning(f"Chat prompts file not found at {chat_prompts_path}")

def _process_celery_config(self):
if self.celery_conf and self.celery_conf.get("result_backend") is None:
Expand Down

0 comments on commit 97de7f3

Please sign in to comment.