https://github.com/dfinke/Build-PromptFromFiles
Combine files from a directory into a single prompt, ready for use with large language models (LLMs)
https://github.com/dfinke/Build-PromptFromFiles
Last synced: 3 months ago
JSON representation
Combine files from a directory into a single prompt, ready for use with large language models (LLMs)
- Host: GitHub
- URL: https://github.com/dfinke/Build-PromptFromFiles
- Owner: dfinke
- License: apache-2.0
- Created: 2024-09-17T10:07:31.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-09-25T12:57:46.000Z (7 months ago)
- Last Synced: 2025-01-14T00:34:37.413Z (3 months ago)
- Language: PowerShell
- Size: 34.2 KB
- Stars: 5
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - dfinke/Build-PromptFromFiles - Combine files from a directory into a single prompt, ready for use with large language models (LLMs) (PowerShell)
README
# Build-PromptFromFiles
[](https://twitter.com/dfinke)
[](https://youtube.com/@dougfinke/)[](https://www.powershellgallery.com/packages/BuildPromptFromFiles)
[](https://www.powershellgallery.com/packages/BuildPromptFromFiles)
[](https://github.com/dfinke/Build-PromptFromFiles/releases)
[](https://github.com/dfinke/Build-PromptFromFiles/blob/master/LICENSE)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](https://simonwillison.net/2024/Apr/8/files-to-prompt/).
## Installation
```powershell
Install-Module BuildPromptFromFiles
```## Usage
Use the `Build-PromptFromFiles` command to combine all files in one or more directories into a single prompt.
```powershell
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.
### Options
- `-RAW` - Output the prompt as a single string, with each file preceded by its relative path and separated by `---`
- `-ignore ` - Specify a pattern to ignore files by. For example `-ignore *.txt` will ignore all `.txt` files.
```powershell
Build-PromptFromFiles path/to/file_or_directory -ignore *.txt, *.dll
```### Usage - Build Prompt From GitHub Repo
Use the `Build-PromptFromGitHubRepo` command to download a GitHub repository and build a prompt from its contents.
```powershell
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.
### Example
Suppose you have a directory structure like this:
```plaintext
my_directory/
├── file1.txt
├── file2.txt
├── temp.log
└── subdirectory/
└── file3.txt
```Running `Build-PromptFromFiles my_directory -RAW` will output:
```plaintext
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:
```plaintext
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
---
```### XML Output
Anthropic has provided [specific guidelines](https://docs.anthropic.com/claude/docs/long-context-window-tips) 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:
```xml
my_directory/file1.txt
Contents of file1.txt
my_directory/file2.txt
Contents of file2.txt
```