This project is an AI-powered code assistant that uses the LangChain framework and the Ollama language model to generate code and answer questions about provided code. The assistant can read code files from the project
directory using the code_reader
tool and generate code based on user prompts.
- Analyzes code and answers questions about provided code
- Generates code based on user prompts
- Uses the
code_reader
tool to read contents of code files in theproject
directory - Uses the
file_lister
tool to list files in a specified directory (defaults toproject
) - Utilizes the LangChain framework and Ollama language model for code generation and analysis
- Provides a Python REPL tool for looking up Python documentation and examples
- Parses the generated code into a JSON object with code, description, and filename
- Saves the generated code to a file in the
output
directory - Classifies the agent's response as either "code" or "conversation" using a response classifier
- Clone the repository:
git clone https://github.com/yourusername/langchain-ai-code-assistant.git
- Install the required dependencies:
pip install -r requirements.txt
- Set up the necessary environment variables (e.g., API keys) in a
.env
file.
-
Place the code files you want the assistant to analyze in the
project
directory. -
Run the
main.py
script:
python main.py
-
Enter a prompt for the AI code assistant. The assistant will generate code, provide a description, and save the code to a file in the
output
directory, or provide a conversational response. -
To quit the program, enter 'q' when prompted for input.
main.py
: The main script that initializes the LangChain agent, tools, and prompts, and handles user input and output.agent_tools.py
: Defines theCodeReader
andFileLister
tools that read code files and list files in a directory.prompts.py
: Contains the prompts used by the LangChain agent, code parser, and response classifier.project/
: Directory containing code files for the assistant to analyze.output/
: Directory where the generated code files are saved.
- LangChain
- langchain-community
- dotenv
- ast
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
This project is licensed under the MIT License.