AI Code Assistant analyzes code snippets and error messages, providing clear, conceptual explanations of errors. It helps users understand what went wrong, why it happened, and how to fix it—without generating or suggesting full code solutions. The assistant is language-agnostic and designed for learning, debugging, and code review support.
- Accepts code and error input from files or manual console entry
- Uses a Language Model (Google Gemini) to analyze code and errors
- Produces conceptual, step-by-step explanations:
- What the error means
- Why the error occurred
- How to fix it conceptually (no working code provided)
- Outputs explanations in Markdown files (for file input) or directly in the console (for manual input)
- Supports any programming or scripting language
- Easily extensible—add new input readers or output writers with minimal effort
- Designed for education, debugging, and code review workflows
ai-code-assistant/
│
├── ai-code-assistant.py # Main entry point
├── LICENSE # Project license (MIT)
├── README.md # Project documentation
├── requirements.txt # Python dependencies
├── .env # Environment variables (API key, model)
│
├── data/
│ ├── faulty_code/ # Example code files with errors (index_error.py, name_error.py, runtime_error.py, syntax_error.py, type_error.py)
│ └── explanations/ # Markdown explanations generated by the bot go here
│
└── utils/
├── base_reader.py # Abstract class for input readers
├── base_writer.py # Abstract class for output writers
├── console_reader.py # Reader for manual console input
├── console_writer.py # Writer for console output
├── file_reader.py # Reader for code files
├── llm_client.py # Handles communication with the LLM (Google Gemini)
├── markdown_writer.py # Writer for Markdown explanations
└── prompt_templates.py # Prompt templates for LLM requests
- Python 3.12+
- python-dotenv
- google-genai
-
Clone the repository
git clone https://github.com/your-username/ai-code-assistant.git cd ai-code-assistant -
Create a virtual environment
- Windows:
python -m venv venv venv\Scripts\activate
- Mac/Linux:*
python3 -m venv venv source venv/bin/activate
- Windows:
-
Install dependencies
pip install -r requirements.txt
Create a .env file in the project root and add the necessary environment variable:
GOOGLE_API_KEY=<your_google_gemini_api_key>
AI_MODEL=<your_model_name>python ai-code-assistant.py <path/to/code_file.ext>The explanation will be saved in data/explanations/ as a Markdown file named after your input file.
How to specify the error in your code file:
To help the assistant identify the error, add a comment line at the top of your code file using the [ERROR] tag, followed by your error message. For example:
# [ERROR] IndexError: list index out of range
my_list = []
print(my_list[0])You can use the appropriate comment syntax for your language (e.g., # for Python, // for JavaScript, -- for SQL, etc.).
python ai-code-assistant.pyYou will be prompted to enter the error message and code snippet interactively. The explanation will be shown in the console.
Note: If you do not provide an error message (either in the code file or when prompted for manual input), the AI will automatically analyze your code and attempt to identify and explain any errors it finds.
This project is licensed under the MIT License.