Shrook21/Code-Assistant
0
1---2title: Smart Code Assistant3emoji: ๐ค4colorFrom: blue5colorTo: purple6sdk: gradio7sdk_version: "4.0.0"8app_file: app.py9pinned: false10---11 12# ๐ค Smart Code Assistant13An intelligent code assistant that can generate, explain, and analyze code using advanced AI models. Built with LangChain, LangGraph, and deployed with Gradio.14 1516 17## ๐ Features18- **Code Generation**: Generate code based on natural language descriptions19- **Code Explanation**: Get detailed explanations of existing code20- **Code Analysis**: Analyze code for improvements and understanding21- **Interactive Web Interface**: User-friendly Gradio interface22- **Intelligent Task Classification**: Automatically determines the type of request23- **Vector Database Integration**: Uses ChromaDB for efficient code retrieval24 25## ๐๏ธ Architecture26 27### LangGraph Workflow28```mermaid29graph TD30 A[User Input] --> B[Classification Node]31 B --> C{Task Type}32 C -->|Generate Code| D[Code Generation Node]33 C -->|Explain Code| E[Code Explanation Node] 34 C -->|Unclear| F[Fallback Node]35 D --> G[Vector Search Tool]36 E --> H[Final Response]37 F --> H38 G --> H39 H --> I[User Interface]40```41 42The assistant uses a conditional graph that:431. Classifies the user's input (generate, explain, or unclear)442. Routes to appropriate specialized nodes453. Retrieves relevant code examples from vector database464. Generates contextual responses using AI models47 48## ๐ Project Structure49```50Code-Assistant/51โโโ app.py # Main Gradio application52โโโ requirements.txt # Python dependencies53โโโ smart_assistant.png # Project image54โโโ agents/55โ โโโ nodes.py # LangGraph nodes implementation56โ โโโ state.py # Graph state management57โโโ chroma_code_db/ # Vector database storage58โโโ config/59โ โโโ settings.py # Configuration settings60โโโ graph/61โ โโโ conditional_graph.py # LangGraph workflow definition62โโโ prompts/63โ โโโ prompts.py # AI prompts and templates64โโโ tools/65โ โโโ tools.py # Custom tools and utilities66โโโ utils/67โ โโโ code_splitter.py # Code parsing utilities68โโโ vectorstore/69 โโโ builder.py # Vector database builder70 โโโ retriever.py # Document retrieval logic71```72 73## ๐ ๏ธ Installation & Setup74 75### Prerequisites76- Python 3.8+77- Ollama (for local AI models)78 79### Local Installation80 811. **Clone the repository:**82 ```bash83 git clone https://github.com/yourusername/Code-Assistant.git84 cd Code-Assistant85 ```86 872. **Install dependencies:**88 ```bash89 pip install -r requirements.txt90 ```91 923. **Set up Ollama:**93 ```bash94 # Install Ollama (visit ollama.ai for installation instructions)95 # Pull your preferred model96 ollama pull llama2 # or your preferred model97 ```98 994. **Configure settings:**100 Edit `config/settings.py` to set your preferred model and parameters101 The vector database will be built automatically on first run102 1035. **Run the application:**104 ```bash105 python app.py106 ```107 1086. **Open your browser:**109 Navigate to `http://localhost:7860`110 Enter your name to start the assistant111 112## ๐ Online Demo113Try the live demo on Hugging Face Spaces:114 115๐ **Code Assistant - Live Demo**116 117No installation required - just open the link and start using the assistant!118 119## ๐ Usage120 121### Getting Started1221. Enter your name when prompted1232. Ask questions about code in natural language:124 - "Generate a function to sort a list in Python"125 - "Explain how bubble sort works"126 - "Create a REST API endpoint for user login"127 128### Example Interactions129 130**๐ค User:** "Create a function that finds the maximum number in a list"131 132**๐ค Assistant:** 133```134๐ Task Classification: GENERATE CODE135 136def find_maximum(numbers):137 """138 Find the maximum number in a list.139 140 Args:141 numbers (list): List of numbers142 143 Returns:144 int/float: Maximum number in the list145 """146 if not numbers:147 raise ValueError("List cannot be empty")148 149 max_num = numbers[0]150 for num in numbers[1:]:151 if num > max_num:152 max_num = num153 154 return max_num155 156# Example usage:157my_list = [3, 1, 4, 1, 5, 9, 2, 6]158result = find_maximum(my_list)159print(f"Maximum number: {result}") # Output: Maximum number: 9160```161 162## ๐งช Development163 164### Adding New Features165- **Custom Nodes**: Add new processing nodes in `agents/nodes.py`166- **Tools**: Extend functionality in `tools/tools.py`167- **Prompts**: Customize AI behavior in `prompts/prompts.py`168- **Graph Logic**: Modify workflow in `graph/conditional_graph.py`169 170### Testing Locally171```bash172# Run with debug mode173python app.py --debug174 175# Test individual components176python -m vectorstore.builder # Build vector database177python -m agents.nodes # Test individual nodes178```179 180## ๐ค Contributing1811. Fork the repository1822. Create a feature branch (`git checkout -b feature/amazing-feature`)1833. Commit your changes (`git commit -m 'Add amazing feature'`)1844. Push to the branch (`git push origin feature/amazing-feature`)1855. Open a Pull Request186 187## ๐ License188This project is licensed under the MIT License - see the LICENSE file for details.189 190## ๐ Acknowledgments191- [LangChain](https://langchain.com/) - For the AI framework192- [LangGraph](https://langchain-ai.github.io/langgraph/) - For workflow orchestration193- [Gradio](https://gradio.app/) - For the web interface194- [Ollama](https://ollama.ai/) - For local AI model serving195- [ChromaDB](https://www.trychroma.com/) - For vector database functionality196- [Hugging Face](https://huggingface.co/) - For model hosting and deployment197 198โญ **Star this repository if you find it helpful!**