-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-api.ps1
More file actions
93 lines (80 loc) · 3.14 KB
/
test-api.ps1
File metadata and controls
93 lines (80 loc) · 3.14 KB
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
# Test the Smart FAQ Assistant API
Write-Host "🧪 Testing Smart FAQ Assistant" -ForegroundColor Cyan
Write-Host "==============================" -ForegroundColor Cyan
Write-Host ""
$baseUrl = "http://localhost:5050"
# Test 1: Health Check
Write-Host "1️⃣ Testing health endpoint..." -ForegroundColor Yellow
try {
$health = Invoke-RestMethod -Uri "$baseUrl/health"
Write-Host "✅ Health check passed: $($health.message)" -ForegroundColor Green
} catch {
Write-Host "❌ Health check failed" -ForegroundColor Red
exit 1
}
# Test 2: Add a single FAQ
Write-Host ""
Write-Host "2️⃣ Adding a test FAQ..." -ForegroundColor Yellow
$faq = @{
question = "What are your business hours?"
answer = "We are open Monday to Friday, 9 AM to 6 PM EST."
category = "general"
} | ConvertTo-Json
try {
$result = Invoke-RestMethod -Uri "$baseUrl/api/faq" `
-Method Post `
-Body $faq `
-ContentType "application/json"
Write-Host "✅ FAQ added successfully: $($result.data.id)" -ForegroundColor Green
$faqId = $result.data.id
} catch {
Write-Host "❌ Failed to add FAQ: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "Response: $($_.ErrorDetails.Message)" -ForegroundColor Red
}
# Test 3: Search
Write-Host ""
Write-Host "3️⃣ Testing semantic search..." -ForegroundColor Yellow
Start-Sleep -Seconds 2 # Give time for embedding generation
$searchQuery = @{
query = "When are you open?"
topK = 5
} | ConvertTo-Json
try {
$searchResults = Invoke-RestMethod -Uri "$baseUrl/api/search" `
-Method Post `
-Body $searchQuery `
-ContentType "application/json"
Write-Host "✅ Search completed. Found $($searchResults.data.Count) results" -ForegroundColor Green
if ($searchResults.data.Count -gt 0) {
Write-Host ""
Write-Host "📋 Top Result:" -ForegroundColor Cyan
$top = $searchResults.data[0]
Write-Host " Q: $($top.metadata.question)" -ForegroundColor White
Write-Host " A: $($top.metadata.answer)" -ForegroundColor White
if ($top.score) {
Write-Host " Similarity: $([math]::Round($top.score * 100, 2))%" -ForegroundColor Yellow
}
}
} catch {
Write-Host "❌ Search failed: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "Response: $($_.ErrorDetails.Message)" -ForegroundColor Red
}
# Test 4: Get all FAQs
Write-Host ""
Write-Host "4️⃣ Getting all FAQs..." -ForegroundColor Yellow
try {
$allFaqs = Invoke-RestMethod -Uri "$baseUrl/api/faq"
Write-Host "✅ Retrieved $($allFaqs.data.Count) FAQs" -ForegroundColor Green
} catch {
Write-Host "❌ Failed to get FAQs" -ForegroundColor Red
}
Write-Host ""
Write-Host "==============================" -ForegroundColor Cyan
Write-Host "✅ All tests completed!" -ForegroundColor Green
Write-Host ""
Write-Host "🌐 You can now start the frontend:" -ForegroundColor Cyan
Write-Host " cd frontend" -ForegroundColor White
Write-Host " npm run dev" -ForegroundColor White
Write-Host ""
Write-Host "Then open: http://localhost:5173" -ForegroundColor Green
Write-Host "==============================" -ForegroundColor Cyan