Skip to main content

Generate prompts for long-context LLMs using the content in your directory

Project description

dir2prompt

PyPI version License: MIT

When you feel too lazy to selectively copy code from all the various files in your project, just copy it all! Inspired by repo2prompt.

Installation 💻

You can install dir2prompt using pip:

pip install dir2prompt

Usage 🚀

To generate a prompt from a directory, use the d2p command followed by the desired options:

d2p [directory path] --filters [file extensions] --outpath [output path] --outfile [output file name] --ignore-dir [directories to ignore] --ignore-file [files to ignore] --config [path to config file]

For ease of use, you can select a directory by passing it in as a positional argument

d2p [directory path]

Options ⚙️

--filter: File extensions to include in the prompt (default: all files).

--outpath: The output path for the prompt file (default: current directory).

--outfile: The name of the output file (default: <directory_name>_prompt).

--ignore-dir: Additional directories to ignore (e.g., experiments, run*).

--ignore-file: Additional file types to ignore (e.g., pt, rs).

--config: Path to a custom config file (default: config.json in the package directory).

--clean: Remove all <folder>_prompt.txt files based on discovered directories.

--tree: Only include directory tree in prompt.

--cp: Copy prompt to clipboard.

Example 🌟

Here's an example of how to use dir2prompt to generate a prompt:

d2p --filter py txt md ipynb --ignore-dir experiments __pycache__ --ignore-file old.py

This command will generate a prompt for the specified directory, including only files with the extensions py, txt, md, ipynb, ignoring the experiments and __pycache__ directories, and ignoring the old.py file.

Note that ignored directories are not included in the directory tree, but that ignored files are. However, the content of the ignored files will not be written to the final prompt under the <files> tag. This might be changed later...

In this example, the generated prompt will be saved as a txt file in the directory that d2p is called in with the name project_prompt.txt, and will have the following structure:

<dir_name>_prompt.txt

<context>
<directory_tree>
project/
├── README.md
├── requirements.txt
└── src/
    ├── __init__.py
    ├── main.py
    ├── old.py
    ├── production.ipynb
    └── testing.rs
</directory_tree>

<files>

<file>
<path>README.md</path>
<content>
# Project Title

This is an example Python project.
</content>
</file>

<file>
<path>requirements.txt</path>
<content>
numpy==1.21.0
pandas==1.3.0
</content>
</file>

<file>
<path>src/__init__.py</path>
<content>
EMPTY FILE
</content>
</file>

<file>
<path>src/main.py</path>
<content>
import numpy as np
import pandas as pd

def main():
    print("Hello, World!")

if __name__ == "__main__":
    main()
</content>
</file>

<file>
<path>src/production.ipynb</path>
<content>
---------- Cell 1 (markdown) ----------
### Biologically inspired artificial neuron 

$$
y = mx + b
$$

---------- Cell 2 (code) ----------
def neuron(x, m, b):
    return m * x + b


</content>
</file>

</files>
</context>

You can then feed this prompt into an LLM to provide it with context about your project 🦾

Config File 📋

dir2prompt uses a config file, config.json, to list common directories and files that should be ignored and excluded from the prompt. You can customize the behavior by supplying your own config file using the --config option:

example.json

{
    "IGNORE_DIRS": [
        "experiments",
        "run*",
        ...
    ],
    "IGNORE_FILES": [
        ".pt",
        ".rs",
        ...
    ]
}

License 📄

dir2prompt is released under the MIT License 🤓

Contributing 🤝

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dir2prompt-2.0.9.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dir2prompt-2.0.9-cp39-cp39-macosx_11_0_arm64.whl (545.1 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file dir2prompt-2.0.9.tar.gz.

File metadata

  • Download URL: dir2prompt-2.0.9.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.18

File hashes

Hashes for dir2prompt-2.0.9.tar.gz
Algorithm Hash digest
SHA256 b89f431ef5d54caa1268417fdd12e17bafaf4b1c6539f44be5adc6e50438b6d1
MD5 37762201dc87f7b660a08412750840b4
BLAKE2b-256 a0208b1a7c6454ed4d42b0417cbed3168fa3acd8a8a2578425ac0f121e8d9f0f

See more details on using hashes here.

File details

Details for the file dir2prompt-2.0.9-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for dir2prompt-2.0.9-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c55de26ac594a7325aed9285054069b9c2fa60b59f46e9fd397783fbec3fd02c
MD5 14159022c846363b7b68238791fbea13
BLAKE2b-256 7e4dc4b54574ee6895497882ceef65af8f4c465559832793300caccb579a1815

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page