Thresher 发表于 2024-3-31 04:17:29

将一个目录中的文件合并成一个更完整的提示文本files-to-prompt

# files-to-prompt

将一个装满文件的目录连接到一个提示中,以便与LLM一起使用

## 安装

使用安装此工具 `pip`:
```bash
pip install files-to-prompt
```
## 用法

使用 `files-to-prompt`, 提供要处理的目录的路径:

```bash
files-to-prompt path/to/directory
```

这将输出目录及其子目录中每个文件的内容,每个文件前面都有其相对路径,并用分隔 `---`.

### 选项

- `--include-hidden`: 包括以开头的文件和文件夹 `.` (隐藏的文件和目录).
```bash
files-to-prompt path/to/directory --include-hidden
```

- `--ignore-gitignore`: Ignore `.gitignore` files and include all files.
```bash
files-to-prompt path/to/directory --ignore-gitignore
```

### 实例

假设您有这样的目录结构:

```
my_directory/
├── file1.txt
├── file2.txt
├── .hidden_file.txt
└── subdirectory/
    └── file3.txt
```

运行 `files-to-prompt my_directory` 将输出:

```
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
---
```

如果运行 `files-to-prompt my_directory --include-hidden`, 则输出还将包括 `.hidden_file.txt`:

```
my_directory/.hidden_file.txt
---
Contents of .hidden_file.txt
---
...
```
## 例子

要对此工具做出贡献,请首先签出代码。然后创建一个新的虚拟环境:
```bash
cd files-to-prompt
python -m venv venv
source venv/bin/activate
```
现在安装依赖项和测试依赖项:
```bash
pip install -e '.'
```
运行测试:
```bash
pytest
```
页: [1]
查看完整版本: 将一个目录中的文件合并成一个更完整的提示文本files-to-prompt