CoolFace
Apppublic

Shrook21/Code-Assistant

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
README.md198 linesDownload Raw Back to root
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 15![Smart Assistant](smart_assistant.png)16 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!**