Skip to content

Commit

Permalink
fix: use full paths to files in workspace context prompt (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare authored Dec 12, 2024
1 parent d598ff3 commit a61aa28
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 glob '{fileglob}' specified in project config does not match any files."
)
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 a61aa28

Please sign in to comment.