Shrook21/Code-Assistant
0
๐ค Smart Code Assistant
An intelligent code assistant that can generate, explain, and analyze code using advanced AI models. Built with LangChain, LangGraph, and deployed with Gradio.
๐ Features
- Code Generation: Generate code based on natural language descriptions
- Code Explanation: Get detailed explanations of existing code
- Code Analysis: Analyze code for improvements and understanding
- Interactive Web Interface: User-friendly Gradio interface
- Intelligent Task Classification: Automatically determines the type of request
- Vector Database Integration: Uses ChromaDB for efficient code retrieval
๐๏ธ Architecture
LangGraph Workflow
graph TD
A[User Input] --> B[Classification Node]
B --> C{Task Type}
C -->|Generate Code| D[Code Generation Node]
C -->|Explain Code| E[Code Explanation Node]
C -->|Unclear| F[Fallback Node]
D --> G[Vector Search Tool]
E --> H[Final Response]
F --> H
G --> H
H --> I[User Interface]The assistant uses a conditional graph that:
- Classifies the user's input (generate, explain, or unclear)
- Routes to appropriate specialized nodes
- Retrieves relevant code examples from vector database
- Generates contextual responses using AI models
๐ Project Structure
Code-Assistant/
โโโ app.py # Main Gradio application
โโโ requirements.txt # Python dependencies
โโโ smart_assistant.png # Project image
โโโ agents/
โ โโโ nodes.py # LangGraph nodes implementation
โ โโโ state.py # Graph state management
โโโ chroma_code_db/ # Vector database storage
โโโ config/
โ โโโ settings.py # Configuration settings
โโโ graph/
โ โโโ conditional_graph.py # LangGraph workflow definition
โโโ prompts/
โ โโโ prompts.py # AI prompts and templates
โโโ tools/
โ โโโ tools.py # Custom tools and utilities
โโโ utils/
โ โโโ code_splitter.py # Code parsing utilities
โโโ vectorstore/
โโโ builder.py # Vector database builder
โโโ retriever.py # Document retrieval logic๐ ๏ธ Installation & Setup
Prerequisites
- Python 3.8+
- Ollama (for local AI models)
Local Installation
- Clone the repository:
git clone https://github.com/yourusername/Code-Assistant.git
cd Code-Assistant- Install dependencies:
pip install -r requirements.txt- Set up Ollama:
# Install Ollama (visit ollama.ai for installation instructions)
# Pull your preferred model
ollama pull llama2 # or your preferred model- Configure settings: Edit
config/settings.pyto set your preferred model and parameters The vector database will be built automatically on first run
- Run the application:
python app.py- Open your browser: Navigate to
http://localhost:7860Enter your name to start the assistant
๐ Online Demo
Try the live demo on Hugging Face Spaces:
๐ Code Assistant - Live Demo
No installation required - just open the link and start using the assistant!
๐ Usage
Getting Started
- Enter your name when prompted
- Ask questions about code in natural language:
- "Generate a function to sort a list in Python"
- "Explain how bubble sort works"
- "Create a REST API endpoint for user login"
Example Interactions
๐ค User: "Create a function that finds the maximum number in a list"
๐ค Assistant:
๐ Task Classification: GENERATE CODE
def find_maximum(numbers):
"""
Find the maximum number in a list.
Args:
numbers (list): List of numbers
Returns:
int/float: Maximum number in the list
"""
if not numbers:
raise ValueError("List cannot be empty")
max_num = numbers[0]
for num in numbers[1:]:
if num > max_num:
max_num = num
return max_num
# Example usage:
my_list = [3, 1, 4, 1, 5, 9, 2, 6]
result = find_maximum(my_list)
print(f"Maximum number: {result}") # Output: Maximum number: 9๐งช Development
Adding New Features
- Custom Nodes: Add new processing nodes in
agents/nodes.py - Tools: Extend functionality in
tools/tools.py - Prompts: Customize AI behavior in
prompts/prompts.py - Graph Logic: Modify workflow in
graph/conditional_graph.py
Testing Locally
# Run with debug mode
python app.py --debug
# Test individual components
python -m vectorstore.builder # Build vector database
python -m agents.nodes # Test individual nodes๐ค Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- LangChain - For the AI framework
- LangGraph - For workflow orchestration
- Gradio - For the web interface
- Ollama - For local AI model serving
- ChromaDB - For vector database functionality
- Hugging Face - For model hosting and deployment
โญ Star this repository if you find it helpful!
