CoolFace
Modelpublic

Kethanvr/my_nextjs_assistant

sourceHugging Facemitupdated 8mo agoView on Hugging Face
5likes
Model Card

๐Ÿค– Next.js & React TypeScript AI Assistant

A custom AI coding assistant finetuned on Qwen2.5-Coder-3B using QLoRA, specialized in Next.js, React, TypeScript, and modern web development.

![License: MIT](https://opensource.org/licenses/MIT) ![Python 3.8+](https://www.python.org/downloads/) ![Made with Unsloth](https://github.com/unslothai/unsloth)


๐Ÿ“‹ Table of Contents


๐ŸŽฏ Overview

This project demonstrates parameter-efficient finetuning of a large language model (LLM) using QLoRA (Quantized Low-Rank Adaptation). The resulting model provides accurate, context-aware coding assistance specifically for:

  • โ€”Next.js 14+ App Router and Server Components
  • โ€”React 19 with modern Hooks
  • โ€”TypeScript type patterns and best practices
  • โ€”Tailwind CSS integration and styling

Key Achievement: Trained a production-quality model in ~40 minutes using free Google Colab resources (T4 GPU).


โœจ Features

  • โ€”๐ŸŽฏ Specialized Knowledge: Focused on modern web development stack
  • โ€”โšก Fast Training: QLoRA enables training on free GPUs
  • โ€”๐Ÿ’ฐ Cost-Effective: $0 training cost using Google Colab
  • โ€”๐Ÿ“Š Small Dataset: Only 70 high-quality examples needed
  • โ€”๐Ÿ”ง Parameter Efficient: Trains only 1-10% of model parameters
  • โ€”๐Ÿš€ Production Ready: Can be deployed to HuggingFace or used locally

๐Ÿ› ๏ธ Tech Stack

Model

  • โ€”Base Model: Qwen2.5-Coder-3B-Instruct (3 billion parameters)
  • โ€”Quantization: 4-bit using bitsandbytes
  • โ€”Finetuning Method: QLoRA (Low-Rank Adaptation)

Training Framework

  • โ€”Unsloth: 2x faster training, 60% less memory usage
  • โ€”HuggingFace Transformers: Model loading and tokenization
  • โ€”TRL (Transformer Reinforcement Learning): Training pipeline
  • โ€”PEFT: Parameter-Efficient Fine-Tuning library

Infrastructure

  • โ€”Platform: Google Colab (Free Tier)
  • โ€”GPU: NVIDIA Tesla T4 (15GB VRAM)
  • โ€”Training Time: ~40 minutes
  • โ€”Memory Usage: ~8GB peak

๐Ÿ“Š Dataset

Dataset Creation

  1. 1.Source: Generated using Gemini API (free tier)
  2. 2.Format: JSONL with ChatML structure
  3. 3.Size: 70 Q&A pairs
  4. 4.Quality Focus: Detailed, accurate, production-ready examples

Topics Covered

  • โ€”Next.js App Router & Architecture (14 examples)
  • โ€”React Hooks & Patterns (13 examples)
  • โ€”TypeScript with React (12 examples)
  • โ€”Tailwind CSS Integration (6 examples)
  • โ€”Common Errors & Debugging (25 examples)

Data Format

json
{
  "messages": [
    {
      "role": "system",
      "content": "You are a Next.js, React, and TypeScript expert assistant."
    },
    {
      "role": "user",
      "content": "How do I use useState in React with TypeScript?"
    },
    {
      "role": "assistant",
      "content": "You should define an interface for the object..."
    }
  ]
}

๐Ÿš€ Training

Hyperparameters

python
# LoRA Configuration
r = 16                    # LoRA rank
lora_alpha = 16          # LoRA scaling
lora_dropout = 0         # Dropout (0 for speed)

# Training Configuration
max_steps = 200          # Training steps
learning_rate = 2e-4     # Learning rate
batch_size = 2           # Per-device batch size
gradient_accumulation = 4 # Effective batch size = 8
warmup_steps = 5         # LR warmup
max_seq_length = 2048    # Context window

Training Process

bash
# 1. Data Preparation
python prepare_data.py

# 2. Training
python train.py

# 3. Evaluation
python test_model.py

Performance Metrics

  • โ€”Training Time: 40 minutes
  • โ€”GPU Memory: 8GB peak usage
  • โ€”Loss: Converged smoothly
  • โ€”Inference Speed: ~2-3 tokens/second on T4

๐Ÿ’ป Usage

Quick Start

python
from unsloth import FastLanguageModel
from peft import PeftModel

# Load base model
model, tokenizer = FastLanguageModel.from_pretrained(
    model_name="unsloth/Qwen2.5-Coder-3B-Instruct-bnb-4bit",
    max_seq_length=2048,
    dtype=None,
    load_in_4bit=True,
)

# Load finetuned adapters
model = PeftModel.from_pretrained(model, "path/to/model")

# Enable inference mode
FastLanguageModel.for_inference(model)

# Ask a question
messages = [
    {"role": "user", "content": "How do I use Server Components in Next.js?"}
]

inputs = tokenizer.apply_chat_template(
    messages,
    tokenize=True,
    add_generation_prompt=True,
    return_tensors="pt",
).to("cuda")

outputs = model.generate(
    input_ids=inputs,
    max_new_tokens=256,
    use_cache=True
)

print(tokenizer.decode(outputs[0]))

Using from HuggingFace

python
# If uploaded to HuggingFace
model, tokenizer = FastLanguageModel.from_pretrained(
    model_name="YOUR_USERNAME/nextjs-assistant",
    max_seq_length=2048,
    load_in_4bit=True,
)

๐Ÿ”ง Installation

Prerequisites

  • โ€”Python 3.8+
  • โ€”CUDA-compatible GPU (for training/inference)
  • โ€”Google Colab account (for free GPU access)

Local Setup

bash
# Clone the repository
git clone https://github.com/YOUR_USERNAME/nextjs-ai-assistant.git
cd nextjs-ai-assistant

# Install dependencies
pip install -r requirements.txt

# Optional: Install Unsloth for faster training
pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"

Google Colab Setup

  1. 1.Open the notebook: nextjs_assistant_training.ipynb
  2. 2.Runtime โ†’ Change runtime type โ†’ T4 GPU
  3. 3.Run all cells
  4. 4.Upload your training_data.jsonl when prompted

๐Ÿ“ˆ Results

Model Performance

โœ… Strengths:

  • โ€”Accurate Next.js App Router patterns
  • โ€”Proper TypeScript typing examples
  • โ€”Context-aware React Hook explanations
  • โ€”Tailwind CSS best practices

โš ๏ธ Limitations:

  • โ€”May need longer answers with more training steps
  • โ€”Limited to training data scope
  • โ€”Best for questions similar to training examples

Example Outputs

Question: "How do I use useState in React with TypeScript?"

Response:

typescript
interface User {
  id: number;
  name: string;
}

const [users, setUsers] = useState<User[]>([]);

๐Ÿ“ Project Structure

nextjs-ai-assistant/
โ”‚
โ”œโ”€โ”€ data/
โ”‚   โ”œโ”€โ”€ training_data.jsonl         # Training dataset
โ”‚   โ””โ”€โ”€ prepare_data.py             # Data preparation script
โ”‚
โ”œโ”€โ”€ notebooks/
โ”‚   โ””โ”€โ”€ training_notebook.ipynb     # Complete training notebook
โ”‚
โ”œโ”€โ”€ scripts/
โ”‚   โ”œโ”€โ”€ train.py                    # Training script
โ”‚   โ”œโ”€โ”€ test_model.py               # Testing script
โ”‚   โ””โ”€โ”€ convert_to_jsonl.py         # Data conversion utility
โ”‚
โ”œโ”€โ”€ model/
โ”‚   โ””โ”€โ”€ my_nextjs_assistant/        # Saved model (not in git)
โ”‚
โ”œโ”€โ”€ requirements.txt                 # Python dependencies
โ”œโ”€โ”€ README.md                        # This file
โ””โ”€โ”€ LICENSE                          # MIT License

๐Ÿค Contributing

Contributions are welcome! Here's how you can help:

  1. 1.Fork the repository
  2. 2.Create a feature branch: git checkout -b feature/amazing-feature
  3. 3.Commit your changes: git commit -m 'Add amazing feature'
  4. 4.Push to the branch: git push origin feature/amazing-feature
  5. 5.Open a Pull Request

Ideas for Contributions

  • โ€”Expand the dataset with more examples
  • โ€”Add support for other frameworks (Vue, Angular)
  • โ€”Create a web UI using Gradio/Streamlit
  • โ€”Implement RAG (Retrieval-Augmented Generation)
  • โ€”Add evaluation metrics

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ™ Acknowledgments

  • โ€”[Unsloth](https://github.com/unslothai/unsloth) - For making LLM training accessible and fast
  • โ€”[Alibaba Cloud](https://www.alibabacloud.com/) - For the Qwen2.5-Coder model
  • โ€”[HuggingFace](https://huggingface.co/) - For the transformers library and model hosting
  • โ€”[Google Colab](https://colab.research.google.com/) - For free GPU access
  • โ€”Community - For datasets, tutorials, and support

๐Ÿ“š Resources

Learn More

Related Projects


๐Ÿ“ž Contact

Your Name - @kethan_vr

Project Link: https://github.com/Kethanvr/qwen-fine-tuning

Portfolio: kethanvr.me


โญ Star History

If you find this project useful, please consider giving it a star!

![Star History Chart](https://star-history.com/#YOUR_USERNAME/nextjs-ai-assistant&Date)


<div align="center">

Made with โค๏ธ by [Kethan VR](https://github.com/Kethanvr)

If this project helped you, consider buying me a coffee โ˜•

</div>