Skip to content

Commit

Permalink
Rename select_recent to select_prompts of Store
Browse files Browse the repository at this point in the history
- Rename select_recent method to select_prompts in store.py
- Update tests in test_store.py to use select_prompts
- Add shorthand flag '-n' for --max-count option in _cli.py
  • Loading branch information
basicthinker committed Jun 5, 2023
1 parent 0dec1fb commit 16a7244
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions devchat/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def prompt(content: Optional[str], parent: Optional[str], reference: Optional[Li

@main.command()
@click.option('--skip', default=0, help='Skip number prompts before showing the prompt history.')
@click.option('--max-count', default=100, help='Limit the number of commits to output.')
@click.option('-n', '--max-count', default=100, help='Limit the number of commits to output.')
def log(skip, max_count):
"""
Show the prompt history.
Expand All @@ -186,7 +186,7 @@ def log(skip, max_count):
openai_config = OpenAIChatConfig(model=config['model'], **config['OpenAI'])
chat = OpenAIChat(openai_config)
store = Store(chat_dir, chat)
recent_prompts = store.select_recent(skip, skip + max_count)
recent_prompts = store.select_prompts(skip, skip + max_count)
else:
click.echo(f"Error: Invalid LLM in configuration '{provider}'", err=True)
sys.exit(os.EX_DATAERR)
Expand Down
4 changes: 2 additions & 2 deletions devchat/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ def get_prompt(self, prompt_hash: str) -> Prompt:
assert len(prompt_data) == 1
return self._chat.load_prompt(prompt_data[0])

def select_recent(self, start: int, end: int, topic: Optional[str] = None) -> List[Prompt]:
def select_prompts(self, start: int, end: int, topic: Optional[str] = None) -> List[Prompt]:
"""
Select recent prompts.
Select recent prompts in reverse chronological order.
Args:
start (int): The start index.
Expand Down
6 changes: 3 additions & 3 deletions tests/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_select_recent(tmp_path):
hashes.append(prompt.hash)

# Test selecting recent prompts
recent_prompts = store.select_recent(0, 3)
recent_prompts = store.select_prompts(0, 3)
assert len(recent_prompts) == 3
for index, prompt in enumerate(recent_prompts):
assert prompt.hash == hashes[4 - index]
Expand Down Expand Up @@ -125,7 +125,7 @@ def test_select_recent_with_topic(tmp_path):
child_hashes.append(child_prompt.hash)

# Test selecting recent prompts within the topic
recent_prompts = store.select_recent(0, 2, topic=root_prompt.hash)
recent_prompts = store.select_prompts(0, 2, topic=root_prompt.hash)
assert len(recent_prompts) == 2
for index, prompt in enumerate(recent_prompts):
assert prompt.hash == child_hashes[2 - index]
Expand Down Expand Up @@ -208,7 +208,7 @@ def test_select_recent_with_nested_topic(tmp_path):
grandchild_hashes.append(grandchild_prompt.hash)

# Test selecting recent prompts within the nested topic
recent_prompts = store.select_recent(1, 3, topic=root_prompt.hash)
recent_prompts = store.select_prompts(1, 3, topic=root_prompt.hash)
assert len(recent_prompts) == 2
assert recent_prompts[0].hash == grandchild_hashes[0]
assert recent_prompts[1].hash == child_prompt.hash

0 comments on commit 16a7244

Please sign in to comment.