fh / test-backend.html
Varun10000's picture
Upload 72 files
35c4df7 verified
Raw
History Blame Contribute Delete
9.02 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Backend Test - SEDNA RFP</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
max-width: 900px;
margin: 50px auto;
padding: 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.container {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 15px;
padding: 30px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
h1 {
text-align: center;
margin-bottom: 30px;
font-size: 2.5em;
}
.test-section {
background: rgba(255, 255, 255, 0.15);
border-radius: 10px;
padding: 20px;
margin: 20px 0;
}
button {
background: #4CAF50;
color: white;
border: none;
padding: 12px 24px;
font-size: 16px;
border-radius: 8px;
cursor: pointer;
margin: 10px 5px;
transition: all 0.3s;
}
button:hover {
background: #45a049;
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
button:disabled {
background: #ccc;
cursor: not-allowed;
}
.result {
background: rgba(0, 0, 0, 0.3);
border-radius: 8px;
padding: 15px;
margin-top: 15px;
font-family: 'Courier New', monospace;
white-space: pre-wrap;
word-wrap: break-word;
max-height: 400px;
overflow-y: auto;
}
.success {
color: #4CAF50;
font-weight: bold;
}
.error {
color: #f44336;
font-weight: bold;
}
.info {
color: #2196F3;
}
.loading {
text-align: center;
padding: 20px;
}
.spinner {
border: 4px solid rgba(255, 255, 255, 0.3);
border-top: 4px solid white;
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
margin: 20px auto;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
</head>
<body>
<div class="container">
<h1>πŸ”§ SEDNA RFP Backend Test</h1>
<div class="test-section">
<h2>1. Backend Health Check</h2>
<button onclick="testHealth()">Test /api/health</button>
<div id="healthResult" class="result"></div>
</div>
<div class="test-section">
<h2>2. Generate AI Answer</h2>
<button onclick="testAIGeneration()">Test AI Generation</button>
<div id="aiResult" class="result"></div>
</div>
<div class="test-section">
<h2>3. Test Question Upload</h2>
<button onclick="testQuestionUpload()">Test Add Questions</button>
<div id="questionResult" class="result"></div>
</div>
<div class="test-section">
<h2>4. Get Questions</h2>
<button onclick="testGetQuestions()">Test Get Questions</button>
<div id="getQuestionsResult" class="result"></div>
</div>
</div>
<script>
const API_BASE = window.location.hostname === 'localhost'
? 'http://localhost:5001/api'
: '/api';
async function testHealth() {
const resultDiv = document.getElementById('healthResult');
resultDiv.innerHTML = '<div class="loading"><div class="spinner"></div>Testing...</div>';
try {
console.log('Testing health endpoint:', `${API_BASE}/health`);
const response = await fetch(`${API_BASE}/health`);
const data = await response.json();
resultDiv.innerHTML = `
<span class="success">βœ… SUCCESS</span>
Status: ${response.status}
Response:
${JSON.stringify(data, null, 2)}
<span class="info">Backend is responding!</span>
AI Service: ${data.ai_service}
Model: ${data.model}
`;
} catch (error) {
resultDiv.innerHTML = `
<span class="error">❌ ERROR</span>
${error.message}
<span class="info">Possible issues:</span>
1. Backend server not running
2. CORS blocking requests
3. Port 5001 not accessible
4. Proxy not configured correctly
`;
}
}
async function testAIGeneration() {
const resultDiv = document.getElementById('aiResult');
resultDiv.innerHTML = '<div class="loading"><div class="spinner"></div>Generating AI answer...</div>';
try {
const response = await fetch(`${API_BASE}/generate-answer`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
questionId: 'test-123',
question: 'What is your experience with cloud infrastructure?',
referenceText: 'We have 10 years of experience with AWS, Azure, and Google Cloud.',
previousAnswers: []
})
});
const data = await response.json();
resultDiv.innerHTML = `
<span class="success">βœ… SUCCESS</span>
Status: ${response.status}
AI Service: ${data.aiService}
Confidence: ${data.confidence}
Answer Preview:
${data.answer.substring(0, 500)}...
<span class="info">AI Generation is working!</span>
`;
} catch (error) {
resultDiv.innerHTML = `
<span class="error">❌ ERROR</span>
${error.message}
<span class="info">Check if:</span>
1. HF_TOKEN is set correctly
2. Model access is granted
3. Backend can reach HuggingFace API
`;
}
}
async function testQuestionUpload() {
const resultDiv = document.getElementById('questionResult');
resultDiv.innerHTML = '<div class="loading"><div class="spinner"></div>Adding questions...</div>';
try {
const response = await fetch(`${API_BASE}/add-questions`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
questions: [
'What is your company size?',
'How many years of experience do you have?'
]
})
});
const data = await response.json();
resultDiv.innerHTML = `
<span class="success">βœ… SUCCESS</span>
Status: ${response.status}
Response:
${JSON.stringify(data, null, 2)}
<span class="info">Questions added successfully!</span>
`;
} catch (error) {
resultDiv.innerHTML = `
<span class="error">❌ ERROR</span>
${error.message}
`;
}
}
async function testGetQuestions() {
const resultDiv = document.getElementById('getQuestionsResult');
resultDiv.innerHTML = '<div class="loading"><div class="spinner"></div>Fetching questions...</div>';
try {
const response = await fetch(`${API_BASE}/questions`);
const data = await response.json();
resultDiv.innerHTML = `
<span class="success">βœ… SUCCESS</span>
Status: ${response.status}
Total Questions: ${data.total}
Response:
${JSON.stringify(data, null, 2)}
<span class="info">Questions retrieved successfully!</span>
`;
} catch (error) {
resultDiv.innerHTML = `
<span class="error">❌ ERROR</span>
${error.message}
`;
}
}
// Auto-run health check on page load
window.addEventListener('load', () => {
console.log('API Base URL:', API_BASE);
setTimeout(testHealth, 500);
});
</script>
</body>
</html>