Add save data functionality and enhance search result model with model type
Browse files- static/index.html +194 -8
static/index.html
CHANGED
@@ -147,16 +147,19 @@ class LoginResponse {
|
|
147 |
<pre><code class="language-dart">class SearchResult {
|
148 |
final String text;
|
149 |
final double similarity;
|
|
|
150 |
|
151 |
SearchResult({
|
152 |
required this.text,
|
153 |
required this.similarity,
|
|
|
154 |
});
|
155 |
|
156 |
factory SearchResult.fromJson(Map<String, dynamic> json) {
|
157 |
return SearchResult(
|
158 |
text: json['text'],
|
159 |
similarity: json['similarity'].toDouble(),
|
|
|
160 |
);
|
161 |
}
|
162 |
}
|
@@ -191,18 +194,97 @@ Future<List<SearchResult>> search(String query, String accessToken) async {
|
|
191 |
<pre><code class="language-json">[
|
192 |
{
|
193 |
"text": "Result 1 text",
|
194 |
-
"similarity": 0.95
|
|
|
195 |
},
|
196 |
{
|
197 |
"text": "Result 2 text",
|
198 |
-
"similarity": 0.92
|
199 |
-
|
200 |
-
{
|
201 |
-
"text": "Result 3 text",
|
202 |
-
"similarity": 0.89
|
203 |
}
|
204 |
]</code></pre>
|
205 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
</section>
|
207 |
|
208 |
<section id="workflow">
|
@@ -226,7 +308,26 @@ Future<List<SearchResult>> search(String query, String accessToken) async {
|
|
226 |
</div>
|
227 |
|
228 |
<div class="endpoint">
|
229 |
-
<h3>Step 3:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
<pre><code class="language-bash">curl -X POST https://humblebeeai-al-ghazali-rag-retrieval-api.hf.space/refresh \
|
231 |
-H "Content-Type: application/json" \
|
232 |
-d '{"refresh_token": "your-refresh-token"}'</code></pre>
|
@@ -301,6 +402,30 @@ class _ApiWorkflowExampleState extends State<ApiWorkflowExample> {
|
|
301 |
}
|
302 |
}
|
303 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
304 |
Future<void> _refreshToken() async {
|
305 |
try {
|
306 |
final loginResponse = await refreshToken(_refreshToken);
|
@@ -336,6 +461,10 @@ class _ApiWorkflowExampleState extends State<ApiWorkflowExample> {
|
|
336 |
onPressed: _search,
|
337 |
child: Text('Search'),
|
338 |
),
|
|
|
|
|
|
|
|
|
339 |
ElevatedButton(
|
340 |
onPressed: _refreshToken,
|
341 |
child: Text('Refresh Token'),
|
@@ -347,7 +476,7 @@ class _ApiWorkflowExampleState extends State<ApiWorkflowExample> {
|
|
347 |
final result = _searchResults[index];
|
348 |
return ListTile(
|
349 |
title: Text(result.text),
|
350 |
-
subtitle: Text('Similarity: ${result.similarity}'),
|
351 |
);
|
352 |
},
|
353 |
),
|
@@ -430,6 +559,29 @@ Future<List<SearchResult>> search(String query, String accessToken) async {
|
|
430 |
}
|
431 |
}
|
432 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
433 |
class LoginResponse {
|
434 |
final String accessToken;
|
435 |
final String refreshToken;
|
@@ -456,19 +608,53 @@ class LoginResponse {
|
|
456 |
class SearchResult {
|
457 |
final String text;
|
458 |
final double similarity;
|
|
|
459 |
|
460 |
SearchResult({
|
461 |
required this.text,
|
462 |
required this.similarity,
|
|
|
463 |
});
|
464 |
|
465 |
factory SearchResult.fromJson(Map<String, dynamic> json) {
|
466 |
return SearchResult(
|
467 |
text: json['text'],
|
468 |
similarity: json['similarity'].toDouble(),
|
|
|
469 |
);
|
470 |
}
|
471 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
472 |
</main>
|
473 |
</div>
|
474 |
|
|
|
147 |
<pre><code class="language-dart">class SearchResult {
|
148 |
final String text;
|
149 |
final double similarity;
|
150 |
+
final String modelType;
|
151 |
|
152 |
SearchResult({
|
153 |
required this.text,
|
154 |
required this.similarity,
|
155 |
+
required this.modelType,
|
156 |
});
|
157 |
|
158 |
factory SearchResult.fromJson(Map<String, dynamic> json) {
|
159 |
return SearchResult(
|
160 |
text: json['text'],
|
161 |
similarity: json['similarity'].toDouble(),
|
162 |
+
modelType: json['model_type'],
|
163 |
);
|
164 |
}
|
165 |
}
|
|
|
194 |
<pre><code class="language-json">[
|
195 |
{
|
196 |
"text": "Result 1 text",
|
197 |
+
"similarity": 0.95,
|
198 |
+
"model_type": "all-mpnet-base-v2"
|
199 |
},
|
200 |
{
|
201 |
"text": "Result 2 text",
|
202 |
+
"similarity": 0.92,
|
203 |
+
"model_type": "openai"
|
|
|
|
|
|
|
204 |
}
|
205 |
]</code></pre>
|
206 |
</div>
|
207 |
+
|
208 |
+
<div class="endpoint" id="save">
|
209 |
+
<h3>4. Save Data Endpoint</h3>
|
210 |
+
<p><span class="method">POST</span><span class="endpoint-url">/save</span></p>
|
211 |
+
<p>This endpoint is used to save user feedback and search results to the Hugging Face dataset. It requires a valid access token.</p>
|
212 |
+
|
213 |
+
<h4>cURL Request:</h4>
|
214 |
+
<pre><code class="language-bash">curl -X POST https://humblebeeai-al-ghazali-rag-retrieval-api.hf.space/save \
|
215 |
+
-H "Content-Type: application/json" \
|
216 |
+
-H "Authorization: Bearer your-access-token" \
|
217 |
+
-d '{
|
218 |
+
"items": [
|
219 |
+
{
|
220 |
+
"user_type": "user",
|
221 |
+
"username": "user123",
|
222 |
+
"query": "test query",
|
223 |
+
"retrieved_text": "Result 1 text",
|
224 |
+
"model_type": "all-mpnet-base-v2",
|
225 |
+
"reaction": "positive"
|
226 |
+
}
|
227 |
+
]
|
228 |
+
}'</code></pre>
|
229 |
+
|
230 |
+
<h4>Flutter Implementation:</h4>
|
231 |
+
<pre><code class="language-dart">class SaveInput {
|
232 |
+
final String userType;
|
233 |
+
final String username;
|
234 |
+
final String query;
|
235 |
+
final String retrievedText;
|
236 |
+
final String modelType;
|
237 |
+
final String reaction;
|
238 |
+
|
239 |
+
SaveInput({
|
240 |
+
required this.userType,
|
241 |
+
required this.username,
|
242 |
+
required this.query,
|
243 |
+
required this.retrievedText,
|
244 |
+
required this.modelType,
|
245 |
+
required this.reaction,
|
246 |
+
});
|
247 |
+
|
248 |
+
Map<String, dynamic> toJson() {
|
249 |
+
return {
|
250 |
+
'user_type': userType,
|
251 |
+
'username': username,
|
252 |
+
'query': query,
|
253 |
+
'retrieved_text': retrievedText,
|
254 |
+
'model_type': modelType,
|
255 |
+
'reaction': reaction,
|
256 |
+
};
|
257 |
+
}
|
258 |
+
}
|
259 |
+
|
260 |
+
Future<void> saveData(List<SaveInput> items, String accessToken) async {
|
261 |
+
final url = Uri.parse('https://humblebeeai-al-ghazali-rag-retrieval-api.hf.space/save');
|
262 |
+
|
263 |
+
try {
|
264 |
+
final response = await http.post(
|
265 |
+
url,
|
266 |
+
headers: {
|
267 |
+
'Content-Type': 'application/json',
|
268 |
+
'Authorization': 'Bearer $accessToken',
|
269 |
+
},
|
270 |
+
body: jsonEncode({
|
271 |
+
'items': items.map((item) => item.toJson()).toList(),
|
272 |
+
}),
|
273 |
+
);
|
274 |
+
|
275 |
+
if (response.statusCode != 200) {
|
276 |
+
throw Exception('Failed to save data: ${response.body}');
|
277 |
+
}
|
278 |
+
} catch (e) {
|
279 |
+
throw Exception('Network error: $e');
|
280 |
+
}
|
281 |
+
}</code></pre>
|
282 |
+
|
283 |
+
<h4>Response:</h4>
|
284 |
+
<pre><code class="language-json">{
|
285 |
+
"message": "Data saved successfully"
|
286 |
+
}</code></pre>
|
287 |
+
</div>
|
288 |
</section>
|
289 |
|
290 |
<section id="workflow">
|
|
|
308 |
</div>
|
309 |
|
310 |
<div class="endpoint">
|
311 |
+
<h3>Step 3: Save Data</h3>
|
312 |
+
<pre><code class="language-bash">curl -X POST https://humblebeeai-al-ghazali-rag-retrieval-api.hf.space/save \
|
313 |
+
-H "Content-Type: application/json" \
|
314 |
+
-H "Authorization: Bearer your-access-token" \
|
315 |
+
-d '{
|
316 |
+
"items": [
|
317 |
+
{
|
318 |
+
"user_type": "user",
|
319 |
+
"username": "user123",
|
320 |
+
"query": "test query",
|
321 |
+
"retrieved_text": "Result 1 text",
|
322 |
+
"model_type": "all-mpnet-base-v2",
|
323 |
+
"reaction": "positive"
|
324 |
+
}
|
325 |
+
]
|
326 |
+
}'</code></pre>
|
327 |
+
</div>
|
328 |
+
|
329 |
+
<div class="endpoint">
|
330 |
+
<h3>Step 4: Refresh Token</h3>
|
331 |
<pre><code class="language-bash">curl -X POST https://humblebeeai-al-ghazali-rag-retrieval-api.hf.space/refresh \
|
332 |
-H "Content-Type: application/json" \
|
333 |
-d '{"refresh_token": "your-refresh-token"}'</code></pre>
|
|
|
402 |
}
|
403 |
}
|
404 |
|
405 |
+
Future<void> _saveData() async {
|
406 |
+
final items = [
|
407 |
+
SaveInput(
|
408 |
+
userType: 'user',
|
409 |
+
username: 'user123',
|
410 |
+
query: 'test query',
|
411 |
+
retrievedText: _searchResults[0].text,
|
412 |
+
modelType: _searchResults[0].modelType,
|
413 |
+
reaction: 'positive',
|
414 |
+
),
|
415 |
+
];
|
416 |
+
|
417 |
+
try {
|
418 |
+
await saveData(items, _accessToken);
|
419 |
+
ScaffoldMessenger.of(context).showSnackBar(
|
420 |
+
SnackBar(content: Text('Data saved successfully!')),
|
421 |
+
);
|
422 |
+
} catch (e) {
|
423 |
+
ScaffoldMessenger.of(context).showSnackBar(
|
424 |
+
SnackBar(content: Text('Failed to save data: $e')),
|
425 |
+
);
|
426 |
+
}
|
427 |
+
}
|
428 |
+
|
429 |
Future<void> _refreshToken() async {
|
430 |
try {
|
431 |
final loginResponse = await refreshToken(_refreshToken);
|
|
|
461 |
onPressed: _search,
|
462 |
child: Text('Search'),
|
463 |
),
|
464 |
+
ElevatedButton(
|
465 |
+
onPressed: _saveData,
|
466 |
+
child: Text('Save Data'),
|
467 |
+
),
|
468 |
ElevatedButton(
|
469 |
onPressed: _refreshToken,
|
470 |
child: Text('Refresh Token'),
|
|
|
476 |
final result = _searchResults[index];
|
477 |
return ListTile(
|
478 |
title: Text(result.text),
|
479 |
+
subtitle: Text('Similarity: ${result.similarity}, Model: ${result.modelType}'),
|
480 |
);
|
481 |
},
|
482 |
),
|
|
|
559 |
}
|
560 |
}
|
561 |
|
562 |
+
Future<void> saveData(List<SaveInput> items, String accessToken) async {
|
563 |
+
final url = Uri.parse('https://humblebeeai-al-ghazali-rag-retrieval-api.hf.space/save');
|
564 |
+
|
565 |
+
try {
|
566 |
+
final response = await http.post(
|
567 |
+
url,
|
568 |
+
headers: {
|
569 |
+
'Content-Type': 'application/json',
|
570 |
+
'Authorization': 'Bearer $accessToken',
|
571 |
+
},
|
572 |
+
body: jsonEncode({
|
573 |
+
'items': items.map((item) => item.toJson()).toList(),
|
574 |
+
}),
|
575 |
+
);
|
576 |
+
|
577 |
+
if (response.statusCode != 200) {
|
578 |
+
throw Exception('Failed to save data: ${response.body}');
|
579 |
+
}
|
580 |
+
} catch (e) {
|
581 |
+
throw Exception('Network error: $e');
|
582 |
+
}
|
583 |
+
}
|
584 |
+
|
585 |
class LoginResponse {
|
586 |
final String accessToken;
|
587 |
final String refreshToken;
|
|
|
608 |
class SearchResult {
|
609 |
final String text;
|
610 |
final double similarity;
|
611 |
+
final String modelType;
|
612 |
|
613 |
SearchResult({
|
614 |
required this.text,
|
615 |
required this.similarity,
|
616 |
+
required this.modelType,
|
617 |
});
|
618 |
|
619 |
factory SearchResult.fromJson(Map<String, dynamic> json) {
|
620 |
return SearchResult(
|
621 |
text: json['text'],
|
622 |
similarity: json['similarity'].toDouble(),
|
623 |
+
modelType: json['model_type'],
|
624 |
);
|
625 |
}
|
626 |
}
|
627 |
+
|
628 |
+
class SaveInput {
|
629 |
+
final String userType;
|
630 |
+
final String username;
|
631 |
+
final String query;
|
632 |
+
final String retrievedText;
|
633 |
+
final String modelType;
|
634 |
+
final String reaction;
|
635 |
+
|
636 |
+
SaveInput({
|
637 |
+
required this.userType,
|
638 |
+
required this.username,
|
639 |
+
required this.query,
|
640 |
+
required this.retrievedText,
|
641 |
+
required this.modelType,
|
642 |
+
required this.reaction,
|
643 |
+
});
|
644 |
+
|
645 |
+
Map<String, dynamic> toJson() {
|
646 |
+
return {
|
647 |
+
'user_type': userType,
|
648 |
+
'username': username,
|
649 |
+
'query': query,
|
650 |
+
'retrieved_text': retrievedText,
|
651 |
+
'model_type': modelType,
|
652 |
+
'reaction': reaction,
|
653 |
+
};
|
654 |
+
}
|
655 |
+
}</code></pre>
|
656 |
+
</div>
|
657 |
+
</section>
|
658 |
</main>
|
659 |
</div>
|
660 |
|