namanbagoria/CodingAssistant
๐ MultiLang Code Assistant (CodeLlama)
    
An AI-powered, multilingual coding assistant built using Code Llama running locally through Ollama. It helps developers generate, explain, debug, optimize, and translate code across multiple programming languages without relying on cloud-based APIs or sharing sensitive code with external servers.
๐ Table of Contents
- Overview
- What is a Code Assistant?
- About Code Llama \& Ollama
- Advantages of Running LLMs Locally
- Key Features
- Repository Structure
- File Descriptions
- Application Workflow
- Technologies Used
- Installation \& Setup
- Example Usage
- Future Improvements
- Contributing
- License
๐ Overview
This project demonstrates how to deploy and utilize locally hosted Large Language Models (LLMs) for software development tasks. By integrating Code Llama with a local Ollama API server and a python-based Gradio user interface, it provides a seamless playground for testing local code intelligence.
๐ค What is a Code Assistant?
A Code Assistant is an AI-driven tool designed to aid developers in writing, debugging, explaining, optimizing, and translating code across various languages. By leveraging models trained on large corpuses of source code, it acts as an intelligent pair programmer to increase developer productivity, reduce debugging cycles, and facilitate learning new programming paradigms.
๐ง About Code Llama & Ollama
- Code Llama: A family of state-of-the-art code generation models developed by Meta Platforms, built on top of Llama 2 architecture. It is trained on code-specific datasets, making it highly proficient in generating code and understanding programming syntax across Python, C++, Java, JavaScript, SQL, and more.
- Ollama: A lightweight framework designed to bundle, run, and manage open-source LLMs locally on your own machine. It provides a simple CLI and runs a local server that exposes REST API endpoints for text generation.
๐ Advantages of Running LLMs Locally
- Data Privacy & Security: Your code stays entirely on your machine. No external servers or third-party APIs process your prompts, making it safe for proprietary or sensitive codebases.
- Zero Latency/Network Costs: Completely free to use with no token counts or subscription limits, and functions independently of internet bandwidth.
- Offline Availability: Work anywhere, even with no internet connection.
- Full Customizability: Fine-tune parameters (like temperature) or specify custom system instructions and persona profiles via a
modelfile.
โจ Key Features
- ๐ฅ๏ธ Interactive Web UI: A simple and clean Gradio interface for chatting with the assistant.
- ๐ฌ Contextual History: Keeps track of prior messages during the session to maintain conversational flow.
- โก Local LLM Execution: Uses the customized
CodeManmodel based on Code Llama. - ๐ Multilingual Support: Supports code translation, generation, optimization, and debugging across Python, C++, Java, JavaScript, SQL, etc.
๐ Repository Structure
MultiLangCodeAssCodellama/
โโโ .gitignore # Excludes temporary, build, and environment files
โโโ LICENSE # MIT License
โโโ README.md # Documentation
โโโ app.py # Application entry point and Gradio UI
โโโ modelfile # Ollama custom model configuration
โโโ requirements.txt # Python package dependencies
โโโ theory.txt # Theoretical details of Code Llama๐ File Descriptions
- `app.py`: The core application logic. It initiates a Gradio web interface, processes the conversation prompt history, sends a POST request to Ollama's local generation endpoint (
http://localhost:11434/api/generate), parses the response, and displays it in the browser. - `modelfile`: Defines a custom Ollama model configuration named CodeMan. It uses
codellamaas the base model, sets thetemperatureparameter to1, and configures a system prompt defining the persona of a code teaching assistant created by Naman. - `requirements.txt`: Declares dependencies needed to run the application (specifically
gradioandlangchain). - `theory.txt`: Contains reference documentation summarizing the architecture, sizes, and capabilities of the Code Llama model family.
โ๏ธ Application Workflow
The diagram below outlines how user prompts travel through the application stack:
sequenceDiagram
actor User
participant App as app.py (Gradio UI)
participant Ollama as Ollama API (Local Port 11434)
participant CodeMan as Custom CodeMan Model (Code Llama)
User->>App: Enters prompt in text area
Note over App: App appends prompt to session history<br/>and joins them using newlines
App->>Ollama: POST HTTP request to /api/generate<br/>(Body: model=CodeMan, prompt=history)
Ollama->>CodeMan: Feeds input prompt to model
CodeMan-->>Ollama: Generates response output
Ollama-->>App: Returns JSON payload (HTTP 200)
Note over App: App parses 'response' from JSON
App-->>User: Displays response in Gradio UI output box- Input: The user enters a programming-related prompt into the Gradio UI.
- Context Compilation: The script compiles the input prompt, joining it with the current session's history using newline characters.
- API Dispatch: The compiled prompt is sent as a JSON payload in an HTTP POST request to Ollama's local REST API server.
- Local Execution: The customized Code Llama model (
CodeMan) processes the prompt and returns a completed response. - Output: The application receives the JSON response, extracts the generated code or explanation text, and displays it directly to the user.
๐ ๏ธ Technologies Used
- Python: Core programming language.
- Gradio: Framework used to create the interactive web interface.
- Requests: HTTP library to interact with Ollama's API.
- JSON: To structure API payloads and parse model outputs.
- Ollama: Framework running the local LLM server.
- Code Llama: Base LLM for coding intelligence.
- LangChain: Included in the requirements list.
๐ Installation & Setup
1. Prerequisites
- Python 3.8 or higher.
- Ollama installed on your system.
2. Install and Run Ollama
- Download Ollama from the official website and install it on your OS.
- Ensure Ollama service is active. On Windows/macOS, it typically runs in the system tray.
- Download the base Code Llama model using the terminal command:
ollama pull codellama3. Create the Custom Model
Build the custom model CodeMan defined in the modelfile:
ollama create CodeMan -f ./modelfile4. Clone and Setup Environment
- Clone this repository to your local machine:
git clone <repository-url>
cd MultiLangCodeAssCodellama- Create a virtual environment:
python -m venv venv- Activate the virtual environment:
- Windows (Command Prompt / PowerShell):
venv\Scripts\activate- macOS / Linux:
source venv/bin/activate- Install the required dependencies:
pip install -r requirements.txt5. Run the Application
Start the local Python application:
python app.pyAfter executing, Gradio will spin up a local server. Open the URL printed in the terminal (usually http://127.0.0.1:7860) in your web browser.
๐ก Example Usage
Use the following example prompts to test the coding assistant's capabilities:
๐ฎ Future Improvements
- Streaming Responses: Enable token-by-token streaming in the UI to remove the waiting time for the full output block.
- Dynamic Parameter Tuning: Add sliders in Gradio to adjust parameters like
temperature,top_k, andtop_pat runtime. - LangChain Integration: Leverage LangChain to implement retrieval-augmented generation (RAG) over local documents.
- Session Management: Add options to save, export, or clear session history from the UI.
๐ค Contributing
Contributions are welcome! If you would like to submit improvements or report issues:
- Fork this repository.
- Create a branch for your feature (
git checkout -b feature/AmazingFeature). - Commit your changes (
git commit -m 'Add some AmazingFeature'). - Push to the branch (
git push origin feature/AmazingFeature). - Open a Pull Request.
๐ License
This project is licensed under the terms of the MIT License. See LICENSE for details.
