Skip to content

Commit

Permalink
fix: use full paths to files in workspace context prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Dec 12, 2024
1 parent 2343ab6 commit 3bbbd96
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions gptme/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
When prompting, it is important to provide clear instructions and avoid any ambiguity.
"""

import glob
import logging
import platform
from collections.abc import Generator, Iterable
Expand Down Expand Up @@ -252,18 +251,25 @@ def get_workspace_prompt(workspace: Path) -> str:
# TODO: update this prompt if the files change
# TODO: include `git status -vv`, and keep it up-to-date
if project := get_project_config(workspace):
files = []
for file in project.files:
files: list[Path] = []
for fileglob in project.files:
# expand user
file = str(Path(file).expanduser())
fileglob = str(Path(fileglob).expanduser())
# expand with glob
if new_files := glob.glob(file):
if new_files := workspace.glob(fileglob):
files.extend(new_files)
else:
logger.error(f"File {file} specified in project config does not exist")
logger.error(
f"File {fileglob} specified in project config does not exist"
)
exit(1)
return "\n\nSelected project files, read more with cat:\n" + "\n\n".join(
[f"```{Path(file).name}\n{Path(file).read_text()}\n```" for file in files]
files_str = []
for file in files:
if file.exists():
files_str.append(f"```{file}\n{file.read_text()}\n```")
return (
"# Workspace Context\n\n"
"Selected project files, read more with cat:\n\n" + "\n\n".join(files_str)
)
return ""

Expand Down

0 comments on commit 3bbbd96

Please sign in to comment.