Views
No views yet
1{
2 "messages": [
3 {
4 "role": "system",
5 "content": "You are a Next.js, React, and TypeScript expert assistant."
6 },
7 {
8 "role": "user",
9 "content": "How do I use useState in React with TypeScript?"
10 },
11 {
12 "role": "assistant",
13 "content": "You should define an interface for the object..."
14 }
15 ]
16}1# LoRA Configuration
2r = 16 # LoRA rank
3lora_alpha = 16 # LoRA scaling
4lora_dropout = 0 # Dropout (0 for speed)
5
6# Training Configuration
7max_steps = 200 # Training steps
8learning_rate = 2e-4 # Learning rate
9batch_size = 2 # Per-device batch size
10gradient_accumulation = 4 # Effective batch size = 8
11warmup_steps = 5 # LR warmup
12max_seq_length = 2048 # Context window1# 1. Data Preparation
2python prepare_data.py
3
4# 2. Training
5python train.py
6
7# 3. Evaluation
8python test_model.py1from unsloth import FastLanguageModel
2from peft import PeftModel
3
4# Load base model
5model, tokenizer = FastLanguageModel.from_pretrained(
6 model_name="unsloth/Qwen2.5-Coder-3B-Instruct-bnb-4bit",
7 max_seq_length=2048,
8 dtype=None,
9 load_in_4bit=True,
10)
11
12# Load finetuned adapters
13model = PeftModel.from_pretrained(model, "path/to/model")
14
15# Enable inference mode
16FastLanguageModel.for_inference(model)
17
18# Ask a question
19messages = [
20 {"role": "user", "content": "How do I use Server Components in Next.js?"}
21]
22
23inputs = tokenizer.apply_chat_template(
24 messages,
25 tokenize=True,
26 add_generation_prompt=True,
27 return_tensors="pt",
28).to("cuda")
29
30outputs = model.generate(
31 input_ids=inputs,
32 max_new_tokens=256,
33 use_cache=True
34)
35
36print(tokenizer.decode(outputs[0]))1# If uploaded to HuggingFace
2model, tokenizer = FastLanguageModel.from_pretrained(
3 model_name="YOUR_USERNAME/nextjs-assistant",
4 max_seq_length=2048,
5 load_in_4bit=True,
6)1# Clone the repository
2git clone https://github.com/YOUR_USERNAME/nextjs-ai-assistant.git
3cd nextjs-ai-assistant
4
5# Install dependencies
6pip install -r requirements.txt
7
8# Optional: Install Unsloth for faster training
9pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"nextjs_assistant_training.ipynbtraining_data.jsonl when prompted1interface User {
2 id: number;
3 name: string;
4}
5
6const [users, setUsers] = useState<User[]>([]);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 Licensegit checkout -b feature/amazing-featuregit commit -m 'Add amazing feature'git push origin feature/amazing-feature