File size: 5,896 Bytes
a0b9343
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# Phase III Quick Start Guide
## AI-Powered Todo Chatbot

Get up and running in 5 minutes! ⚡

---

## 🚀 Quick Start

### Prerequisites Checklist

- [ ] Python 3.12+ installed
- [ ] Node.js 18+ installed
- [ ] Neon PostgreSQL account (free at https://neon.tech/)
- [ ] Hugging Face API key (free at https://huggingface.co/)
- [ ] Git installed

---

## Step 1: Setup Environment (2 minutes)

### Backend `.env`

```bash
# In project root, create .env file:
NEON_DATABASE_URL=postgresql://user:password@ep-xxx.aws.neon.tech/neondb?sslmode=require
HUGGINGFACE_API_KEY=hf_your_api_key_here
QWEN_MODEL=Qwen/Qwen-14B-Chat
JWT_SECRET=your-jwt-secret-here
```

### Frontend `.env.local`

```bash
# In frontend/, create .env.local:
NEXT_PUBLIC_API_URL=http://localhost:8000
```

---

## Step 2: Install Dependencies (1 minute)

```bash
# Python dependencies
pip install -r requirements.txt

# Node dependencies
cd frontend
npm install
cd ..
```

---

## Step 3: Setup Database (30 seconds)

```bash
python backend/scripts/migrate_ai_tables.py
```

Expected output:
```
[OK] Checking database connection...
[OK] Creating Conversation table...
[OK] Creating Message table...
[OK] Migration complete!
```

---

## Step 4: Start Backend (30 seconds)

```bash
# Terminal 1
python -m uvicorn backend.main:app --host 0.0.0.0 --port 8000 --reload
```

Verify it's running:
```bash
curl http://localhost:8000/health
# Should return: {"status":"healthy"...}
```

---

## Step 5: Start Frontend (30 seconds)

```bash
# Terminal 2
cd frontend
npm run dev
```

Open: http://localhost:3000/chat

---

## Step 6: Test the Chat! (1 minute)

### Login First
1. Go to http://localhost:3000/login
2. Enter your Phase II credentials
3. You'll be redirected to chat

### Try These Commands

**English:**
```
Add a task to buy milk
Show my tasks
Mark task 1 as complete
```

**Urdu:**
```
دودھ لینے کا ٹاسک شامل کرو
میرے ٹاسک دکھاؤ
پہلا ٹاسک مکمل کرو
```

---

## 🎯 What's Happening?

### Architecture

```
You (Frontend)
    ↓ "Add a task to buy milk"
    ↓ (JWT + HTTP)
Backend (/api/chat)
    ↓ Extract user_id
    ↓ Detect language (English)
    ↓ Send to Qwen AI
    ↓ AI responds: TOOL_CALL create_task
    ↓ Execute MCP tool
    ↓ Create task in database
    ↓ Format response
    ↓ Return: "Task created!"
You (Frontend)
    ↓ Display response
```

### Components

**Frontend:**
- `ChatInterfaceAdvanced.tsx` - Beautiful chat UI
- `RobotAvatar.tsx` - Animated robot
- `/chat` page - Main chat interface

**Backend:**
- `/api/chat` - Main chat endpoint
- `QwenClient` - Hugging Face integration
- `MCPTools` - Task operations
- `TodoRepository` - Database access

---

## 📝 Common Commands

### Backend

```bash
# Start server
python -m uvicorn backend.main:app --reload

# Run migration
python backend/scripts/migrate_ai_tables.py

# Test chat endpoint
curl http://localhost:8000/api/chat/health

# View API docs
open http://localhost:8000/docs
```

### Frontend

```bash
# Start dev server
npm run dev

# Build for production
npm run build

# Start production server
npm run start

# Lint code
npm run lint
```

---

## 🐛 Troubleshooting

### "Port 8000 already in use"

```bash
# Windows
netstat -ano | findstr :8000
taskkill /PID <PID> /F

# Mac/Linux
lsof -ti:8000 | xargs kill -9
```

### "Database connection failed"

Check your `.env` file has correct `NEON_DATABASE_URL`

### "JWT token invalid"

1. Logout from frontend
2. Login again with Phase II credentials
3. New token will be generated

### "Hugging Face API error"

Verify:
- API key is correct
- Model name: `Qwen/Qwen-14B-Chat`
- Account has API access enabled

---

## 📊 Test Cases

### Test 1: Create Task (English)

**Input:** `Add a task to finish the project with high priority`

**Expected:**
- AI responds in English
- Task created with title "finish the project"
- Priority set to "high"
- Confirmation message displayed

### Test 2: Create Task (Urdu)

**Input:** `گھر پر جا задача`

**Expected:**
- AI responds in Urdu
- Task created with Urdu title
- Confirmation in Urdu

### Test 3: View Tasks

**Input:** `Show my tasks`

**Expected:**
- AI lists all your tasks
- Shows status, priority, due dates
- Response in detected language

### Test 4: Complete Task

**Input:** `Mark task 1 as done`

**Expected:**
- Task status changed to "completed"
- Completion timestamp set
- Confirmation message

---

## 🎨 Features Available**Bilingual Support** - English & Urdu
✅ **Natural Language** - No special commands needed
✅ **Task CRUD** - Create, Read, Update, Delete
✅ **Priorities** - Low, Medium, High
✅ **Due Dates** - ISO format supported
✅ **Tags** - Categorize tasks
✅ **Animated Robot** - Cute AI avatar
✅ **Chat History** - Conversations saved
✅ **Dark Mode** - Beautiful dark theme

---

## 🚀 Next Steps

1. **Customize Prompts:** Edit `backend/src/ai/prompt_builder.py`
2. **Add More Tools:** Create new MCP tools in `backend/src/mcp/tools.py`
3. **Style Customization:** Modify `frontend/src/styles/globals.css`
4. **Deploy:** Follow `PHASE_III_DEPLOYMENT.md`

---

## 📚 Full Documentation

- **Deployment Guide:** `PHASE_III_DEPLOYMENT.md`
- **Specification:** `specs/001-ai-chatbot/spec.md`
- **Implementation Plan:** `specs/001-ai-chatbot/plan.md`
- **Task List:** `specs/001-ai-chatbot/tasks.md`

---

## 💡 Tips

1. **Start Simple:** Try basic commands first
2. **Be Specific:** More details = better AI understanding
3. **Mix Languages:** AI detects language automatically
4. **Use Conversations:** AI remembers context (10 messages)
5. **Check Logs:** Backend logs show tool executions

---

**🎉 You're ready to use the AI-Powered Todo Chatbot!**

**Time to complete:** ~5 minutes
**Difficulty:** Beginner-friendly
**Support:** Check `PHASE_III_DEPLOYMENT.md` for detailed troubleshooting