Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 2 days 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 days ago)
- Default Branch: main
- Last Pushed: 2024-09-17T15:02:51.000Z (7 days ago)
- Last Synced: 2024-09-17T18:36:18.798Z (7 days ago)
- Language: PowerShell
- Size: 12.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
README
# Build-PromptFromFiles
[![Follow on Twitter](https://img.shields.io/twitter/follow/dfinke.svg?style=social&label=Follow%20%40dfinke)](https://twitter.com/dfinke)
[![Subscribe on YouTube](https://img.shields.io/youtube/channel/subscribers/UCP47ZkO5EDkoI2sr-3P4ShQ
)](https://youtube.com/@dougfinke/)[![](https://img.shields.io/powershellgallery/v/BuildPromptFromFiles.svg)](https://www.powershellgallery.com/packages/BuildPromptFromFiles)
[![](https://img.shields.io/powershellgallery/dt/BuildPromptFromFiles.svg)](https://www.powershellgallery.com/packages/BuildPromptFromFiles)
[![Changelog](https://img.shields.io/github/v/release/dfinke/Build-PromptFromFiles?include_prereleases&label=changelog)](https://github.com/dfinke/Build-PromptFromFiles/releases)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](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
```### 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
```