本文档介绍了 gpt-engineer 项目中的文件组织方式以及文件选择功能的使用。文件选择是一项关键功能,它允许用户在改进现有代码库时指定应考虑哪些文件。有关整体命令行界面的信息,请参阅 CLI 和 Agent 系统。
gpt-engineer 以特定的目录结构组织项目,其中包含用户创建的文件和存储在隐藏目录中的元数据。理解此结构对于有效使用该系统至关重要。
来源:gpt_engineer/core/default/paths.py43-52 gpt_engineer/applications/cli/file_selector.py54
项目目录包含:
文件选择系统允许用户指定 AI 在改进现有代码时应考虑哪些文件。这很重要,因为:
来源:gpt_engineer/applications/cli/file_selector.py79-121 gpt_engineer/applications/cli/file_selector.py123-211
当您在改进模式下运行 gpt-engineer 时(gpte <project_dir> -i),文件选择过程会自动激活。工作流程如下:
.gpteng 元数据目录中创建一个 file_selection.toml 文件,或者使用现有的文件。# 开头)。#)您想要包含的文件。TOML 文件结构如下所示:
# Remove '#' to select a file or turn off linting.
# Linting with BLACK (Python) enhances code suggestions from LLMs.
# To disable linting, uncomment the relevant option in the linting settings.
# gpt-engineer can only read selected files.
# Including irrelevant files will degrade performance,
# cost additional tokens and potentially overflow token limit.
[linting]
# "linting" = "off"
[files]
# "main.py" = "selected"
# "utils.py" = "selected"
# "README.md" = "selected"
来源:gpt_engineer/applications/cli/file_selector.py54-64 gpt_engineer/applications/cli/file_selector.py271-307
FileSelector 使用几种机制来过滤文件:
默认情况下,以下目录会被忽略:
site-packagesnode_modulesvenv__pycache__. 开头)如果项目是 Git 仓库,则文件选择器会遵守 .gitignore 规则,过滤掉不应被跟踪的文件。这是通过以下方式实现的:
.gitignore 规则来过滤文件列表。来源:gpt_engineer/applications/cli/file_selector.py53 gpt_engineer/applications/cli/file_selector.py379-416 gpt_engineer/core/git.py58-68
在文件选择之后,gpt-engineer 使用 DisplayablePath 类显示所选文件的树形表示。这提供了关于哪些文件将包含在改进过程中的可视化确认。
示例输出
You have selected the following files:
/path/to/project
├── main.py
├── utils/
│ ├── helpers.py
│ └── config.py
└── README.md
DisplayablePath 类通过以下方式创建此树状结构:
来源:gpt_engineer/applications/cli/file_selector.py419-540
文件选择系统与 gpt-engineer 的其他几个组件集成。
来源:gpt_engineer/applications/cli/file_selector.py35-121 gpt_engineer/core/git.py10-85 gpt_engineer/core/linting.py1-64
文件选择过程还允许用户切换代码 Linting。默认情况下,Python 文件会使用 Black 格式化程序进行 Linting,以确保样式一致性,这通常有助于 AI 提供更好的建议。用户可以在 TOML 配置文件中禁用 Linting。
文件选择中的 Linting 状态会影响 AI 生成后文件的处理方式。
来源:gpt_engineer/core/linting.py6-64 gpt_engineer/applications/cli/file_selector.py64 gpt_engineer/applications/cli/file_selector.py177-180
在使用 gpt-engineer 改进现有代码时,为获得最佳结果:
当使用 gpt-engineer 改进现有代码时,文件选择过程在更大的工作流程中按如下方式进行:
gpte <project_dir> -i 以启动改进模式。此过程确保 AI 获得进行有针对性改进所需的精确上下文,而不会因无关代码而感到不知所措。
来源:gpt_engineer/applications/cli/file_selector.py79-121
gpt-engineer 中的文件选择和项目结构系统为用户提供了对 AI 处理文件的精细控制。通过了解这些系统的运作方式,用户可以有效地组织他们的项目并选择正确的文件,以在生成或改进代码时取得最佳结果。