Skip to content

Commit

Permalink
Change _db_path to use 'prompts.json'
Browse files Browse the repository at this point in the history
Also add a check for empty prompt_data and return None if not found.
  • Loading branch information
basicthinker committed May 22, 2023
1 parent fe29e5c commit 2660cb4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions devchat/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, store_dir: str, chat: Chat):
os.makedirs(store_dir)

self._graph_path = os.path.join(store_dir, 'prompts.graphml')
self._db_path = os.path.join(store_dir, 'prompts')
self._db_path = os.path.join(store_dir, 'prompts.json')
self._chat = chat

if os.path.isfile(self._graph_path):
Expand Down Expand Up @@ -82,13 +82,15 @@ def get_prompt(self, prompt_hash: str) -> Prompt:
Args:
prompt_hash (str): The hash of the prompt to retrieve.
Returns:
Prompt: The retrieved prompt.
Prompt: The retrieved prompt. None if the prompt is not found.
"""
if prompt_hash not in self._graph:
raise ValueError(f'Prompt {prompt_hash} not found in the store.')

# Retrieve the prompt object from TinyDB
prompt_data = self._db.search(where('_hash') == prompt_hash)
if not prompt_data:
return None
assert len(prompt_data) == 1
return self._chat.load_prompt(prompt_data[0])

Expand Down

0 comments on commit 2660cb4

Please sign in to comment.