This project provides a lightweight solution for performing keyword-based searches on your codebase and then uses GPT‑4.1 to generate detailed answers or explanations based on the relevant code snippets. The tool extracts context (two lines before and after each match) and builds a prompt including your question and the corresponding code snippets.
- Python 3.8+
- OpenAI Python library (for interacting with GPT‑4.1)
- An OpenAI API key with access to GPT‑4.1
-
Clone the repository:
git clone https://github.com/kingabzpro/Keyword-Code-Search.git cd Keyword-Code-Search
-
Install dependencies: Please ensure you have the latest version of the OpenAI client.
pip install -U openai
Set your OpenAI API key in the environment variable:
-
On macOS/Linux:
export OPENAI_API_KEY="YOUR_API_KEY_HERE"
-
On Windows (Command Prompt):
set OPENAI_API_KEY=YOUR_API_KEY_HERE
This starts an interactive chat session where you can ask multiple questions about your codebase. The tool will search for relevant code snippets and provide AI-powered explanations for each question. Type 'quit' to exit the chat.
python main.py --path /path/to/your/codebase
The tool currently supports searching through the following file types:
- Python (.py)
- JavaScript (.js)
- Text files (.txt)
- Markdown (.md)
- HTML (.html)
- CSS (.css)
- Shell scripts (.sh)
- The tool extracts keywords from your question
- It searches through your codebase for files containing those keywords
- It extracts relevant code snippets from the matching files
- It sends the question and code snippets to GPT-4.1
- GPT-4.1 generates an explanation based on the code snippets
- The explanation is displayed in the terminal (with streaming)
This project is released under the MIT License.