指南概览
欢迎使用 Code2Prompt。
指南概览
欢迎使用 Code2Prompt。
从代码库生成提示:
code2prompt path/to/codebase生成提示并复制到剪贴板:
code2prompt path/to/codebase -c启动交互式 TUI:
code2prompt path/to/codebase --tui显示 token‑map:
code2prompt path/to/codebase --token-map使用自定义 Handlebars 模板:
code2prompt path/to/codebase -t path/to/template.hbs使用 glob 模式过滤文件:
code2prompt path/to/codebase --include="*.rs,*.toml"使用 glob 模式排除文件:
code2prompt path/to/codebase --exclude="*.txt,*.md"根据排除模式从源树中排除文件/文件夹:
code2prompt path/to/codebase --exclude="*.npy,*.wav" --exclude-from-tree显示生成提示的 token 数量:
code2prompt path/to/codebase --tokens指定用于 token 计数的 tokenizer:
code2prompt path/to/codebase --tokens --encoding=p50k支持的 tokenizer:cl100k、p50k、p50k_edit、r50k_bas。
将生成的提示保存到输出文件:
code2prompt path/to/codebase -O output.txt以 JSON 格式输出:
code2prompt path/to/codebase -F JSONJSON 输出示例:
{ "prompt": "<生成的提示>", "directory_name": "codebase", "token_count": 1234, "model_info": "ChatGPT 模型, text-embedding-ada-002", "files": []}为已暂存的文件生成 Git 提交信息:
code2prompt path/to/codebase --diff -t templates/write-git-commit.hbs为已暂存的文件生成分支比较的 Pull Request:
code2prompt path/to/codebase --git-diff-branch 'main, development' --git-log-branch 'main, development' -t templates/write-github-pull-request.hbs为源码块添加行号:
code2prompt path/to/codebase --line-number在 Markdown 代码块中禁用代码包装:
code2prompt path/to/codebase --no-codeblockCode2Prompt 是一个出色的工具,可高效生成 token‑优化的提示。它适用于多种场景,例如: