File size: 9,019 Bytes
35c4df7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!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>