Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion devchat/engine/recursive_prompter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re
import os
from .namespace import Namespace


Expand All @@ -13,6 +15,23 @@ def run(self, name: str) -> str:
file_path = self.namespace.get_file(ancestor_name, 'prompt.txt')
if file_path:
with open(file_path, 'r', encoding='utf-8') as file:
merged_content += file.read()
prompt_content = file.read()
# replace @file@ with the content of the file
prompt_content = self._replace_file_references(file_path, prompt_content)
merged_content += prompt_content
merged_content += '\n'

return merged_content

def _replace_file_references(self, prompt_file_path: str, content: str) -> str:
# prompt_file_path is the path to the file that contains the content
# @relative file path@: file is relative to the prompt_file_path
pattern = re.compile(r'@(.+?)@')
matches = pattern.findall(content)
for match in matches:
file_path = os.path.join(os.path.dirname(prompt_file_path), match)
if os.path.exists(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
file_content = file.read()
content = content.replace(f'@{match}@', file_content)
return content
4 changes: 2 additions & 2 deletions devchat/engine/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def load_workflow_instruction(user_input: str):
if user_input[:1] != '/':
return None

workflows_dir = os.path.join(os.path.abspath('~/.chat'), 'workflows')
workflows_dir = os.path.join(os.path.expanduser('~/.chat'), 'workflows')
if not os.path.exists(workflows_dir):
return None
if not os.path.isdir(workflows_dir):
Expand All @@ -24,7 +24,7 @@ def load_workflow_instruction(user_input: str):
command_name = user_input.split()[0][1:]
command_prompts = prompter.run(command_name)

return command_prompts
return [command_prompts]


def run_command(
Expand Down