Combine files from a directory into a single prompt, ready for use with large language models (LLMs)
For background on this project see Building files-to-prompt entirely using Claude 3 Opus.
Install-Module BuildPromptFromFiles
Use the Build-PromptFromFiles
command to combine all files in one or more directories into a single prompt.
Build-PromptFromFiles path/to/file_or_directory [path/to/another/file_or_directory ...]
This will output the contents of every file in the specified directories, combined into an XML format.
-RAW
- Output the prompt as a single string, with each file preceded by its relative path and separated by---
-ignore <patterb>
- Specify a pattern to ignore files by. For example-ignore *.txt
will ignore all.txt
files.Build-PromptFromFiles path/to/file_or_directory -ignore *.txt, *.dll
Use the Build-PromptFromGitHubRepo
command to download a GitHub repository and build a prompt from its contents.
Build-PromptFromGitHubRepo dfinke/psai | clip
clip
is optional and will copy the prompt to the clipboard. You can then paste it into your favorite LLM. Your token limit may be exceeded if the prompt is too large.
Suppose you have a directory structure like this:
my_directory/
├── file1.txt
├── file2.txt
├── temp.log
└── subdirectory/
└── file3.txt
Running Build-PromptFromFiles my_directory -RAW
will output:
my_directory/file1.txt
---
Contents of file1.txt
---
my_directory/file2.txt
---
Contents of file2.txt
---
my_directory/temp.log
---
Contents of temp.log
---
my_directory/subdirectory/file3.txt
---
Contents of file3.txt
---
If you run Build-PromptFromFiles my_directory -RAW --ignore "*.log"
, the output will exclude temp.log
:` the output will be:
my_directory/file1.txt
---
Contents of file1.txt
---
my_directory/file2.txt
---
Contents of file2.txt
---
my_directory/subdirectory/file3.txt
---
Contents of file3.txt
---
Anthropic has provided specific guidelines for optimally structuring prompts to take advantage of Claude's extended context window.
The XML output is generated by Build-PromptFromFiles
as the default and follows these guidelines. Here is an example of the XML output:
<documents>
<document index="1">
<source>my_directory/file1.txt</source>
<document_content>
Contents of file1.txt
</document_content>
</document>
<document index="2">
<source>my_directory/file2.txt</source>
<document_content>
Contents of file2.txt
</document_content>
</document>
</documents>