GPT Context Maker is a Python-based tool that intelligently generates a context from a provided project. It's designed for compatibility with Open AI's ChatGPT model, suitable for large software projects across various programming languages, including Python, PHP, and more.
The tool generates a context by analyzing your project files, prioritizing recent changes, removing comments, and taking additional steps as necessary to ensure the context fits within a predefined token limit.
-
Clone the repository:
git clone https://github.com/azazar/gpt-context-maker.git
-
Navigate into the cloned directory:
cd gpt-context-maker
-
Install the package using pip:
pip install .
The GPT Context Maker can be used either through command-line arguments or by creating a .gptsettings.yml
configuration file in your project directory.
Here are the available command-line arguments:
--path
(Optional): Path to your project directory. Defaults to the current directory if not specified.--copy
(Optional): If included, the tool will copy the generated context to the clipboard.--max-tokens
(Optional): The maximum number of tokens allowed in the context. Defaults to 3072 if not specified.--exclude-dirs
(Optional): A comma-separated list of directories to exclude from the context.--include-keywords
(Optional): A comma-separated list of keywords to filter included files.--prompt
(Optional): Text to prepend to the generated context.--requirements
(Optional): Text to append to the generated context.
Example of a command-line usage:
gpt-context-maker \
--path /path/to/your/project \
--copy --max-tokens 4096 \
--exclude-dirs test,logs \
--include-keywords key1,key2 \
--prompt "Find issues in project"
The above command instructs the tool to generate a context from the project located at /path/to/your/project
, excluding files from test
and logs
directories. It will filter files to include only those that contain 'key1' or 'key2' in their names, prepend the context with "Fix this function" and copy the resulting context to the clipboard.
You can integrate GPT Context Maker with Visual Studio Code using tasks and keybindings for a more seamless experience. Here's how to set it up:
-
Open your user
tasks.json
file in Visual Studio Code. If it does not exist, you will need to create it. You can access it by opening the command paletteCtrl+Shift+P
, and typeTasks: Open User Tasks
. -
Add the following task configurations to the
tasks.json
file:
{
"version": "2.0.0",
"tasks": [
{
"label": "Generate GPT Context from current workspace with filtering",
"type": "shell",
"command": "gpt-context-maker",
"args": [
"--path",
"${workspaceFolder}",
"--prompt",
"${input:inputPrompt}",
"--include-keywords",
"${input:includeKeywords}",
"--copy"
],
"problemMatcher": [],
"group": {
"kind": "none",
},
"presentation": {
"revealProblems": "onProblem"
}
},
{
"label": "Generate GPT Context from current workspace",
"type": "shell",
"command": "gpt-context-maker",
"args": [
"--path",
"${workspaceFolder}",
"--copy"
],
"problemMatcher": [],
"group": {
"kind": "none",
},
"presentation": {
"revealProblems": "onProblem"
}
}
],
"inputs": [
{
"id": "inputPrompt",
"type": "promptString",
"description": "Provide a prompt."
},
{
"id": "includeKeywords",
"type": "promptString",
"description": "Comma-separated list of keywords to include.",
"default": ""
}
]
}
- Update your user keybindings file (
keybindings.json
). You can access it by opening the command paletteCtrl+Shift+P
, and typePreferences: Open Keyboard Shortcuts (JSON)
.
[
{
"key": "ctrl+shift+g",
"command": "workbench.action.tasks.runTask",
"args": "Generate GPT Context from current workspace with filtering"
},
{
"key": "alt+shift+g",
"command": "workbench.action.tasks.runTask",
"args": "Generate GPT Context from current workspace"
}
]
With these settings, you can generate a context for your current workspace with filtering by pressing Ctrl+Shift+G
and without filtering by pressing Alt+Shift+G
. You will be prompted to input a prompt and keywords when using the Ctrl+Shift+G
shortcut.
If you encounter any problems while running the tasks, check the 'Problems' tab in VSCode for any error messages. If the issue persists, ensure that the gpt-context-maker
command is correctly installed and accessible in your PATH.
If you prefer not to use command-line arguments, you can create a .gptsettings.yml
file in your project directory with the same configuration options:
copy: false
max-tokens: 4096
exclude-dirs: "test,logs"
include-keywords: "main,py"
prompt: |
Here are project files for the context. Wait for instructions.
requirements: |
# Output Requirements
1. Before generating code, specify the filename.
2. Replace in-code triple backticks with "~~~" to avoid Markdown conflict.
3. For file modifications, provide diff-style patch code in a format that can be used with the patch utility (include a patch command example) unless you generate a whole file. For file renaming, provide a bash script.
4. Keep replies brief and avoid explanations due to size limits. Use code to provide clear explanations.
5. Keep explanation outside of generated code. It's supposed to be added into the project without modifications.
6. All requirements and guidelines must be followed.
# Critical Guidelines
1. **Maintainability**: Code should be clear, modular, and well-documented. Follow industry-standard style guides. Use meaningful names for variables and methods.
2. **Testability**: Write the code in easily testable units with robust error handling. Specify the test framework and required coverage level.
3. **Performance**: Code should be efficient, optimized, and minimize unnecessary calculations. Include specific performance benchmarks if necessary.
4. **Security**: Anticipate and address common security issues, validate and sanitize user input. Provide examples of potential security risks if needed.
5. **Quality**: Ensure adherence to SOLID, KISS, and YAGNI principles in the generated code.
Please note that any command-line arguments will override the respective settings from the .gptsettings.yml
file.
Your contributions are most welcome! Here are the steps to contribute:
- Fork this repository.
- Create a new branch in your forked repository.
- Make changes in your new branch.
- Create a pull request.
Ensure that your code adheres to the existing style for consistency.
The output of the GPT Context Maker is a summarized context of your code, suitable for input into the OpenAI GPT-3 model. The context is generated by intelligently summarizing and filtering your codebase while prioritizing recent changes. If the --copy
argument is used or copy: true
is set in the .gptsettings.yml
file, this context is also copied to your clipboard.
If you have any issues or suggestions, please open an issue in this repository. Happy coding!