From 3bbbd964adbfb3d1aa2bf4408ec064cfad7c1a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Bj=C3=A4reholt?= Date: Thu, 12 Dec 2024 20:05:45 +0100 Subject: [PATCH] fix: use full paths to files in workspace context prompt --- gptme/prompts.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/gptme/prompts.py b/gptme/prompts.py index e2bdd907..b5bb60ec 100644 --- a/gptme/prompts.py +++ b/gptme/prompts.py @@ -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 @@ -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 ""