Spaces:
Running
Running
Bahodir Nematjonov
commited on
Commit
·
667244c
1
Parent(s):
a708c46
index files updated
Browse files- static/index.html +390 -621
- static/script.js +1 -1
- utils.py +4 -5
static/index.html
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
<title>LLM Host API Documentation</title>
|
7 |
<link href="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/themes/prism-tomorrow.min.css" rel="stylesheet" />
|
8 |
-
<link href="
|
9 |
</head>
|
10 |
<body>
|
11 |
<div class="container">
|
@@ -18,649 +18,418 @@
|
|
18 |
</div>
|
19 |
</nav>
|
20 |
<main class="content">
|
21 |
-
|
22 |
|
23 |
-
|
24 |
-
|
25 |
|
26 |
-
|
27 |
-
<h3>1.
|
28 |
-
<p><span class="method">POST</span><span class="endpoint-url">/
|
29 |
-
<p>This endpoint is used to
|
30 |
|
31 |
<h4>cURL Request:</h4>
|
32 |
-
<pre><code class="language-bash">curl -X POST https://humblebeeai-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
44 |
-
body: {
|
45 |
-
'username': username,
|
46 |
-
'password': password,
|
47 |
-
},
|
48 |
-
);
|
49 |
-
|
50 |
-
if (response.statusCode == 200) {
|
51 |
-
return LoginResponse.fromJson(jsonDecode(response.body));
|
52 |
-
} else {
|
53 |
-
throw Exception('Failed to login: ${response.body}');
|
54 |
-
}
|
55 |
-
} catch (e) {
|
56 |
-
throw Exception('Network error: $e');
|
57 |
-
}
|
58 |
-
}
|
59 |
-
|
60 |
-
// Model class
|
61 |
-
class LoginResponse {
|
62 |
-
final String accessToken;
|
63 |
-
final String refreshToken;
|
64 |
-
final String tokenType;
|
65 |
-
final int expiresIn;
|
66 |
-
|
67 |
-
LoginResponse({
|
68 |
-
required this.accessToken,
|
69 |
-
required this.refreshToken,
|
70 |
-
required this.tokenType,
|
71 |
-
required this.expiresIn,
|
72 |
-
});
|
73 |
-
|
74 |
-
factory LoginResponse.fromJson(Map<String, dynamic> json) {
|
75 |
-
return LoginResponse(
|
76 |
-
accessToken: json['access_token'],
|
77 |
-
refreshToken: json['refresh_token'],
|
78 |
-
tokenType: json['token_type'],
|
79 |
-
expiresIn: json['expires_in'],
|
80 |
-
);
|
81 |
-
}
|
82 |
-
}</code></pre>
|
83 |
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
"expires_in": 1800
|
90 |
-
}</code></pre>
|
91 |
-
</div>
|
92 |
-
|
93 |
-
<div class="endpoint" id="refresh">
|
94 |
-
<h3>2. Refresh Token Endpoint</h3>
|
95 |
-
<p><span class="method">POST</span><span class="endpoint-url">/refresh</span></p>
|
96 |
-
<p>This endpoint is used to refresh the access token using a valid refresh token.</p>
|
97 |
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
<pre><code class="language-dart">Future<LoginResponse> refreshToken(String refreshToken) async {
|
105 |
-
final url = Uri.parse('https://humblebeeai-al-ghazali-rag-retrieval-api.hf.space/refresh');
|
106 |
-
|
107 |
-
try {
|
108 |
-
final response = await http.post(
|
109 |
-
url,
|
110 |
-
headers: {'Content-Type': 'application/json'},
|
111 |
-
body: jsonEncode({
|
112 |
-
'refresh_token': refreshToken,
|
113 |
-
}),
|
114 |
-
);
|
115 |
-
|
116 |
-
if (response.statusCode == 200) {
|
117 |
-
return LoginResponse.fromJson(jsonDecode(response.body));
|
118 |
-
} else {
|
119 |
-
throw Exception('Failed to refresh token: ${response.body}');
|
120 |
-
}
|
121 |
-
} catch (e) {
|
122 |
-
throw Exception('Network error: $e');
|
123 |
-
}
|
124 |
-
}</code></pre>
|
125 |
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
"expires_in": 1800
|
132 |
-
}</code></pre>
|
133 |
-
</div>
|
134 |
-
|
135 |
-
<div class="endpoint" id="search">
|
136 |
-
<h3>3. Search Endpoint</h3>
|
137 |
-
<p><span class="method">POST</span><span class="endpoint-url">/search</span></p>
|
138 |
-
<p>This endpoint is used to send a search query and retrieve results. It requires a valid access token.</p>
|
139 |
|
140 |
-
|
141 |
-
|
142 |
-
-H "Content-Type: application/json" \
|
143 |
-
-H "Authorization: Bearer your-access-token" \
|
144 |
-
-d '{"query": "test query"}'</code></pre>
|
145 |
-
|
146 |
-
<h4>Flutter Implementation:</h4>
|
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 |
-
}
|
166 |
-
|
167 |
-
Future<List<SearchResult>> search(String query, String accessToken) async {
|
168 |
-
final url = Uri.parse('https://humblebeeai-al-ghazali-rag-retrieval-api.hf.space/search');
|
169 |
-
|
170 |
-
try {
|
171 |
-
final response = await http.post(
|
172 |
-
url,
|
173 |
-
headers: {
|
174 |
-
'Content-Type': 'application/json',
|
175 |
-
'Authorization': 'Bearer $accessToken',
|
176 |
-
},
|
177 |
-
body: jsonEncode({
|
178 |
-
'query': query,
|
179 |
-
}),
|
180 |
-
);
|
181 |
-
|
182 |
-
if (response.statusCode == 200) {
|
183 |
-
List<dynamic> jsonList = jsonDecode(response.body);
|
184 |
-
return jsonList.map((json) => SearchResult.fromJson(json)).toList();
|
185 |
-
} else {
|
186 |
-
throw Exception('Search failed: ${response.body}');
|
187 |
-
}
|
188 |
-
} catch (e) {
|
189 |
-
throw Exception('Network error: $e');
|
190 |
-
}
|
191 |
-
}</code></pre>
|
192 |
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
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 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
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 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
|
302 |
-
|
303 |
-
|
304 |
-
<pre><code class="language-bash">curl -X POST https://humblebeeai-al-ghazali-rag-retrieval-api.hf.space/search \
|
305 |
-H "Content-Type: application/json" \
|
306 |
-H "Authorization: Bearer your-access-token" \
|
307 |
-d '{"query": "test query"}'</code></pre>
|
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>
|
334 |
-
</div>
|
335 |
-
|
336 |
-
<h3>Flutter Implementation</h3>
|
337 |
-
<div class="endpoint">
|
338 |
-
<h4>Complete Flutter Example</h4>
|
339 |
-
<pre><code class="language-dart">import 'dart:convert';
|
340 |
-
import 'package:flutter/material.dart';
|
341 |
-
import 'package:http/http.dart' as http;
|
342 |
-
|
343 |
-
void main() {
|
344 |
-
runApp(MyApp());
|
345 |
-
}
|
346 |
-
|
347 |
-
class MyApp extends StatelessWidget {
|
348 |
-
@override
|
349 |
-
Widget build(BuildContext context) {
|
350 |
-
return MaterialApp(
|
351 |
-
title: 'Al Ghazali RAG API Example',
|
352 |
-
home: ApiWorkflowExample(),
|
353 |
-
);
|
354 |
-
}
|
355 |
-
}
|
356 |
-
|
357 |
-
class ApiWorkflowExample extends StatefulWidget {
|
358 |
-
@override
|
359 |
-
_ApiWorkflowExampleState createState() => _ApiWorkflowExampleState();
|
360 |
-
}
|
361 |
-
|
362 |
-
class _ApiWorkflowExampleState extends State<ApiWorkflowExample> {
|
363 |
-
String _accessToken = '';
|
364 |
-
String _refreshToken = '';
|
365 |
-
List<SearchResult> _searchResults = [];
|
366 |
-
|
367 |
-
Future<void> _login() async {
|
368 |
-
final username = 'user123';
|
369 |
-
final password = 'password123';
|
370 |
-
|
371 |
-
try {
|
372 |
-
final loginResponse = await login(username, password);
|
373 |
-
setState(() {
|
374 |
-
_accessToken = loginResponse.accessToken;
|
375 |
-
_refreshToken = loginResponse.refreshToken;
|
376 |
-
});
|
377 |
-
ScaffoldMessenger.of(context).showSnackBar(
|
378 |
-
SnackBar(content: Text('Login successful!')),
|
379 |
-
);
|
380 |
-
} catch (e) {
|
381 |
-
ScaffoldMessenger.of(context).showSnackBar(
|
382 |
-
SnackBar(content: Text('Login failed: $e')),
|
383 |
-
);
|
384 |
-
}
|
385 |
-
}
|
386 |
-
|
387 |
-
Future<void> _search() async {
|
388 |
-
final query = 'test query';
|
389 |
-
|
390 |
-
try {
|
391 |
-
final results = await search(query, _accessToken);
|
392 |
-
setState(() {
|
393 |
-
_searchResults = results;
|
394 |
-
});
|
395 |
-
ScaffoldMessenger.of(context).showSnackBar(
|
396 |
-
SnackBar(content: Text('Search successful!')),
|
397 |
-
);
|
398 |
-
} catch (e) {
|
399 |
-
ScaffoldMessenger.of(context).showSnackBar(
|
400 |
-
SnackBar(content: Text('Search failed: $e')),
|
401 |
-
);
|
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);
|
432 |
-
setState(() {
|
433 |
-
_accessToken = loginResponse.accessToken;
|
434 |
-
});
|
435 |
-
ScaffoldMessenger.of(context).showSnackBar(
|
436 |
-
SnackBar(content: Text('Token refreshed successfully!')),
|
437 |
-
);
|
438 |
-
} catch (e) {
|
439 |
-
ScaffoldMessenger.of(context).showSnackBar(
|
440 |
-
SnackBar(content: Text('Token refresh failed: $e')),
|
441 |
-
);
|
442 |
-
}
|
443 |
-
}
|
444 |
-
|
445 |
-
@override
|
446 |
-
Widget build(BuildContext context) {
|
447 |
-
return Scaffold(
|
448 |
-
appBar: AppBar(
|
449 |
-
title: Text('Al Ghazali RAG API Workflow'),
|
450 |
-
),
|
451 |
-
body: Padding(
|
452 |
-
padding: const EdgeInsets.all(16.0),
|
453 |
-
child: Column(
|
454 |
-
crossAxisAlignment: CrossAxisAlignment.stretch,
|
455 |
-
children: [
|
456 |
-
ElevatedButton(
|
457 |
-
onPressed: _login,
|
458 |
-
child: Text('Login'),
|
459 |
-
),
|
460 |
-
ElevatedButton(
|
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'),
|
471 |
-
),
|
472 |
-
Expanded(
|
473 |
-
child: ListView.builder(
|
474 |
-
itemCount: _searchResults.length,
|
475 |
-
itemBuilder: (context, index) {
|
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 |
-
),
|
483 |
-
),
|
484 |
-
],
|
485 |
-
),
|
486 |
-
),
|
487 |
-
);
|
488 |
-
}
|
489 |
-
}
|
490 |
-
|
491 |
-
Future<LoginResponse> login(String username, String password) async {
|
492 |
-
final url = Uri.parse('https://humblebeeai-al-ghazali-rag-retrieval-api.hf.space/login');
|
493 |
-
|
494 |
-
try {
|
495 |
-
final response = await http.post(
|
496 |
-
url,
|
497 |
-
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
498 |
-
body: {
|
499 |
-
'username': username,
|
500 |
-
'password': password,
|
501 |
-
},
|
502 |
-
);
|
503 |
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
508 |
}
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
658 |
</main>
|
659 |
</div>
|
660 |
|
661 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/prism.min.js"></script>
|
662 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/components/prism-bash.min.js"></script>
|
663 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/components/prism-json.min.js"></script>
|
664 |
-
<script src="
|
665 |
</body>
|
666 |
</html>
|
|
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
<title>LLM Host API Documentation</title>
|
7 |
<link href="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/themes/prism-tomorrow.min.css" rel="stylesheet" />
|
8 |
+
<link href="style.css" rel="stylesheet" />
|
9 |
</head>
|
10 |
<body>
|
11 |
<div class="container">
|
|
|
18 |
</div>
|
19 |
</nav>
|
20 |
<main class="content">
|
21 |
+
<h1>LLM Host API</h1>
|
22 |
|
23 |
+
<section id="endpoints">
|
24 |
+
<h2>Endpoints</h2>
|
25 |
|
26 |
+
<div class="endpoint" id="register">
|
27 |
+
<h3>1. Register Endpoint</h3>
|
28 |
+
<p><span class="method">POST</span><span class="endpoint-url">/register</span></p>
|
29 |
+
<p>This endpoint is used to register the username and password.</p>
|
30 |
|
31 |
<h4>cURL Request:</h4>
|
32 |
+
<pre><code class="language-bash">curl -X POST 'https://humblebeeai-llm-host.hf.space/register' \
|
33 |
+
-H "Content-Type: application/json" \
|
34 |
+
-d '{
|
35 |
+
"username": "testuser",
|
36 |
+
"password": "testpassword"
|
37 |
+
}'</code></pre>
|
38 |
+
|
39 |
+
<h4>Python Implementation:</h4>
|
40 |
+
<pre><code class="language-python">
|
41 |
+
import requests
|
42 |
+
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
+
class RegisterResponse:
|
45 |
+
"""Class to handle API response"""
|
46 |
+
def __init__(self, message, user):
|
47 |
+
self.message = message
|
48 |
+
self.user = user
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
+
@classmethod
|
51 |
+
def from_json(cls, json_data):
|
52 |
+
return cls(
|
53 |
+
message=json_data.get("message"),
|
54 |
+
user=json_data.get("user")
|
55 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
+
def register(username: str, password: str):
|
58 |
+
"""Sends a POST request to register a new user."""
|
59 |
+
url = "https://humblebeeai-llm-host.hf.space/register"
|
60 |
+
headers = {"Content-Type": "application/json"}
|
61 |
+
payload = {"username": username, "password": password}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
+
try:
|
64 |
+
response = requests.post(url, json=payload, headers=headers)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
+
if response.status_code == 200:
|
67 |
+
return RegisterResponse.from_json(response.json())
|
68 |
+
else:
|
69 |
+
raise Exception(f"Failed to register: {response.text}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
+
except requests.exceptions.RequestException as e:
|
72 |
+
raise Exception(f"Network error: {e}")
|
73 |
+
|
74 |
+
# Example usage
|
75 |
+
try:
|
76 |
+
result = register("testuser", "testpassword")
|
77 |
+
print(f"✅ Registration successful! User: {result.user}, Message: {result.message}")
|
78 |
+
except Exception as e:
|
79 |
+
print(f"⚠️ Error: {e}")
|
80 |
+
</code></pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
<h4>Response:</h4>
|
83 |
+
<pre><code class="language-json">{"message":"User registered successfully","user":"bahodir"}</code></pre>
|
84 |
+
|
85 |
+
</div>
|
86 |
+
<div class="endpoint" id="login">
|
87 |
+
<h3>2. Login Endpoint</h3>
|
88 |
+
<p><span class="method">POST</span><span class="endpoint-url">/login</span></p>
|
89 |
+
<p>This endpoint is used to authenticate a user and retrieve an access token.</p>
|
90 |
+
|
91 |
+
<h4>cURL Request:</h4>
|
92 |
+
<pre><code class="language-bash">curl -X POST 'https://humblebeeai-llm-host.hf.space/login' \
|
93 |
+
-H "Content-Type: application/x-www-form-urlencoded" \
|
94 |
+
-d 'username=testuser&password=testpassword'</code></pre>
|
95 |
+
|
96 |
+
<h4>Python Implementation:</h4>
|
97 |
+
<pre><code class="language-python">
|
98 |
+
import requests
|
99 |
+
|
100 |
+
class LoginResponse:
|
101 |
+
"""Class to handle API login response"""
|
102 |
+
def __init__(self, access_token, refresh_token, token_type):
|
103 |
+
self.access_token = access_token
|
104 |
+
self.refresh_token = refresh_token
|
105 |
+
self.token_type = token_type
|
106 |
+
|
107 |
+
@classmethod
|
108 |
+
def from_json(cls, json_data):
|
109 |
+
return cls(
|
110 |
+
access_token=json_data.get("access_token"),
|
111 |
+
refresh_token=json_data.get("refresh_token"),
|
112 |
+
token_type=json_data.get("token_type"),
|
113 |
+
)
|
114 |
+
|
115 |
+
def login(username: str, password: str):
|
116 |
+
"""Sends a POST request to authenticate a user."""
|
117 |
+
url = "https://humblebeeai-llm-host.hf.space/login"
|
118 |
+
headers = {"Content-Type": "application/x-www-form-urlencoded"}
|
119 |
+
payload = {"username": username, "password": password}
|
120 |
+
|
121 |
+
try:
|
122 |
+
response = requests.post(url, data=payload, headers=headers)
|
123 |
+
|
124 |
+
if response.status_code == 200:
|
125 |
+
return LoginResponse.from_json(response.json())
|
126 |
+
else:
|
127 |
+
raise Exception(f"Failed to login: {response.text}")
|
128 |
+
|
129 |
+
except requests.exceptions.RequestException as e:
|
130 |
+
raise Exception(f"Network error: {e}")
|
131 |
+
|
132 |
+
# Example usage
|
133 |
+
try:
|
134 |
+
result = login("testuser", "testpassword")
|
135 |
+
print(f"✅ Login successful! Access Token: {result.access_token}")
|
136 |
+
except Exception as e:
|
137 |
+
print(f"⚠️ Error: {e}")
|
138 |
+
</code></pre>
|
139 |
+
|
140 |
+
<h4>Response:</h4>
|
141 |
+
<pre><code class="language-json">{ "access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0dXNlciIsImV4cCI6MTczOTE3Nzg5N30.jUfB7vHA4HGrpDiI08cpKGR7s3DOVrchhpf5yBz0hCc",
|
142 |
+
"token_type":"bearer",
|
143 |
+
"refresh_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0dXNlciIsImV4cCI6MTczOTc4MDg5N30.L9_5hGR_lUskUINccE51fOA1-8NOgmQ2bjBK3iMS-K8"}</code></pre>
|
144 |
+
|
145 |
+
</div>
|
146 |
+
|
147 |
+
|
148 |
+
<div class="endpoint" id="refresh">
|
149 |
+
<h3>3. Refresh Token Endpoint</h3>
|
150 |
+
<p><span class="method">POST</span><span class="endpoint-url">/refresh</span></p>
|
151 |
+
<p>This endpoint is used to refresh the access token using a valid refresh token.</p>
|
152 |
+
|
153 |
+
<h4>cURL Request:</h4>
|
154 |
+
<pre><code class="language-bash">curl -X POST 'https://humblebeeai-llm-host.hf.space/refresh' \
|
155 |
+
-H "Content-Type: application/json" \
|
156 |
+
-d '{"refresh_token": "your-refresh-token"}'</code></pre>
|
157 |
+
|
158 |
+
<h4>Python Implementation:</h4>
|
159 |
+
<pre><code class="language-python">
|
160 |
+
import requests
|
161 |
+
import json
|
162 |
+
|
163 |
+
class RefreshResponse:
|
164 |
+
"""Class to handle API refresh response"""
|
165 |
+
def __init__(self, access_token, refresh_token, token_type):
|
166 |
+
self.access_token = access_token
|
167 |
+
self.refresh_token = refresh_token
|
168 |
+
self.token_type = token_type
|
169 |
+
|
170 |
+
@classmethod
|
171 |
+
def from_json(cls, json_data):
|
172 |
+
return cls(
|
173 |
+
access_token=json_data.get("access_token"),
|
174 |
+
refresh_token=json_data.get("refresh_token"),
|
175 |
+
token_type=json_data.get("token_type"),
|
176 |
+
)
|
177 |
+
|
178 |
+
def refresh_token(refresh_token: str):
|
179 |
+
"""Sends a POST request to refresh the access token."""
|
180 |
+
url = "https://humblebeeai-llm-host.hf.space/refresh"
|
181 |
+
headers = {"Content-Type": "application/json"}
|
182 |
+
payload = {"refresh_token": refresh_token}
|
183 |
+
|
184 |
+
try:
|
185 |
+
response = requests.post(url, json=payload, headers=headers)
|
186 |
+
|
187 |
+
if response.status_code == 200:
|
188 |
+
return RefreshResponse.from_json(response.json())
|
189 |
+
else:
|
190 |
+
raise Exception(f"Failed to refresh token: {response.text}")
|
191 |
+
|
192 |
+
except requests.exceptions.RequestException as e:
|
193 |
+
raise Exception(f"Network error: {e}")
|
194 |
+
|
195 |
+
# Example usage
|
196 |
+
try:
|
197 |
+
result = refresh_token("your-refresh-token")
|
198 |
+
print(f"✅ Token refreshed! New Access Token: {result.access_token}")
|
199 |
+
except Exception as e:
|
200 |
+
print(f"⚠️ Error: {e}")
|
201 |
+
</code></pre>
|
202 |
+
|
203 |
+
<h4>Response:</h4>
|
204 |
+
<pre><code class="language-json">{
|
205 |
+
"access_token": "new-access-token",
|
206 |
+
"refresh_token": "your-refresh-token",
|
207 |
+
"token_type": "bearer"
|
208 |
+
}</code></pre>
|
209 |
+
</div>
|
210 |
+
|
211 |
+
<div class="endpoint" id="search">
|
212 |
+
<h3>4. Search Endpoint</h3>
|
213 |
+
<p><span class="method">POST</span><span class="endpoint-url">/search</span></p>
|
214 |
+
<p>This endpoint is used to send a search query and retrieve results. It requires a valid access token.</p>
|
215 |
|
216 |
+
<h4>cURL Request:</h4>
|
217 |
+
<pre><code class="language-bash">curl -X POST 'https://humblebeeai-llm-host.hf.space/search' \
|
|
|
218 |
-H "Content-Type: application/json" \
|
219 |
-H "Authorization: Bearer your-access-token" \
|
220 |
-d '{"query": "test query"}'</code></pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
|
222 |
+
<h4>Python Implementation:</h4>
|
223 |
+
<pre><code class="language-python">
|
224 |
+
import requests
|
225 |
+
import json
|
226 |
+
|
227 |
+
class SearchResult:
|
228 |
+
"""Class to handle search results"""
|
229 |
+
def __init__(self, text, similarity, model_type):
|
230 |
+
self.text = text
|
231 |
+
self.similarity = similarity
|
232 |
+
self.model_type = model_type
|
233 |
+
|
234 |
+
@classmethod
|
235 |
+
def from_json(cls, json_data):
|
236 |
+
return cls(
|
237 |
+
text=json_data.get("text"),
|
238 |
+
similarity=json_data.get("similarity"),
|
239 |
+
model_type=json_data.get("model_type"),
|
240 |
+
)
|
241 |
+
|
242 |
+
def search(query: str, access_token: str):
|
243 |
+
"""Sends a search query and retrieves results."""
|
244 |
+
url = "https://humblebeeai-llm-host.hf.space/search"
|
245 |
+
headers = {
|
246 |
+
"Content-Type": "application/json",
|
247 |
+
"Authorization": f"Bearer {access_token}"
|
248 |
}
|
249 |
+
payload = {"query": query}
|
250 |
+
|
251 |
+
try:
|
252 |
+
response = requests.post(url, json=payload, headers=headers)
|
253 |
+
|
254 |
+
if response.status_code == 200:
|
255 |
+
json_list = response.json()
|
256 |
+
return [SearchResult.from_json(item) for item in json_list]
|
257 |
+
else:
|
258 |
+
raise Exception(f"Search failed: {response.text}")
|
259 |
+
|
260 |
+
except requests.exceptions.RequestException as e:
|
261 |
+
raise Exception(f"Network error: {e}")
|
262 |
+
|
263 |
+
# Example usage
|
264 |
+
try:
|
265 |
+
results = search("test query", "your-access-token")
|
266 |
+
for result in results:
|
267 |
+
print(f"✅ Found: {result.text} (Similarity: {result.similarity}, Model: {result.model_type})")
|
268 |
+
except Exception as e:
|
269 |
+
print(f"⚠️ Error: {e}")
|
270 |
+
</code></pre>
|
271 |
+
|
272 |
+
<h4>Response:</h4>
|
273 |
+
<pre><code class="language-json">
|
274 |
+
response based on query
|
275 |
+
</code></pre>
|
276 |
+
</div>
|
277 |
+
|
278 |
+
|
279 |
+
</section>
|
280 |
+
|
281 |
+
<section id="workflow">
|
282 |
+
<h2>Workflow Example</h2>
|
283 |
+
<p>Here's a complete workflow demonstrating how to use the API:</p>
|
284 |
+
|
285 |
+
<h3>cURL Implementation</h3>
|
286 |
+
|
287 |
+
<div class="endpoint">
|
288 |
+
<h3>Step 1: Login</h3>
|
289 |
+
<pre><code class="language-bash">curl -X POST https://humblebeeai-llm-host.hf.space/login \
|
290 |
+
-H "Content-Type: application/x-www-form-urlencoded" \
|
291 |
+
-d 'username=user123&password=password123'</code></pre>
|
292 |
+
</div>
|
293 |
+
|
294 |
+
<div class="endpoint">
|
295 |
+
<h3>Step 2: Search</h3>
|
296 |
+
<pre><code class="language-bash">curl -X POST https://humblebeeai-llm-host.hf.space/search \
|
297 |
+
-H "Content-Type: application/json" \
|
298 |
+
-H "Authorization: Bearer your-access-token" \
|
299 |
+
-d '{"query": "test query"}'</code></pre>
|
300 |
+
</div>
|
301 |
+
|
302 |
+
<div class="endpoint">
|
303 |
+
<h3>Step 3: Refresh Token</h3>
|
304 |
+
<pre><code class="language-bash">curl -X POST https://humblebeeai-llm-host.hf.space/refresh \
|
305 |
+
-H "Content-Type: application/json" \
|
306 |
+
-d '{"refresh_token": "your-refresh-token"}'</code></pre>
|
307 |
+
</div>
|
308 |
+
|
309 |
+
<h3>Python Implementation</h3>
|
310 |
+
|
311 |
+
<div class="endpoint">
|
312 |
+
<h4>Complete Python Example</h4>
|
313 |
+
<pre><code class="language-python">
|
314 |
+
import requests
|
315 |
+
import json
|
316 |
+
|
317 |
+
API_BASE_URL = "https://humblebeeai-llm-host.hf.space"
|
318 |
+
|
319 |
+
class APIClient:
|
320 |
+
"""Handles the full API workflow"""
|
321 |
+
|
322 |
+
def __init__(self):
|
323 |
+
self.access_token = None
|
324 |
+
self.refresh_token = None
|
325 |
+
|
326 |
+
def login(self, username: str, password: str):
|
327 |
+
"""Authenticates the user and retrieves tokens"""
|
328 |
+
url = f"{API_BASE_URL}/login"
|
329 |
+
payload = {"username": username, "password": password}
|
330 |
+
headers = {"Content-Type": "application/x-www-form-urlencoded"}
|
331 |
+
|
332 |
+
response = requests.post(url, data=payload, headers=headers)
|
333 |
+
if response.status_code == 200:
|
334 |
+
tokens = response.json()
|
335 |
+
self.access_token = tokens.get("access_token")
|
336 |
+
self.refresh_token = tokens.get("refresh_token")
|
337 |
+
print(f"✅ Login successful! Token: {self.access_token}")
|
338 |
+
else:
|
339 |
+
raise Exception(f"⚠️ Login failed: {response.text}")
|
340 |
+
|
341 |
+
def search(self, query: str):
|
342 |
+
"""Performs a search query"""
|
343 |
+
url = f"{API_BASE_URL}/search"
|
344 |
+
payload = {"query": query}
|
345 |
+
headers = {
|
346 |
+
"Content-Type": "application/json",
|
347 |
+
"Authorization": f"Bearer {self.access_token}",
|
348 |
+
}
|
349 |
+
|
350 |
+
response = requests.post(url, json=payload, headers=headers)
|
351 |
+
if response.status_code == 200:
|
352 |
+
results = response.json()
|
353 |
+
print("✅ Search results:", results)
|
354 |
+
return results
|
355 |
+
else:
|
356 |
+
raise Exception(f"⚠️ Search failed: {response.text}")
|
357 |
+
|
358 |
+
def save_data(self, items: list):
|
359 |
+
"""Saves retrieved data"""
|
360 |
+
url = f"{API_BASE_URL}/save"
|
361 |
+
payload = {"items": items}
|
362 |
+
headers = {
|
363 |
+
"Content-Type": "application/json",
|
364 |
+
"Authorization": f"Bearer {self.access_token}",
|
365 |
+
}
|
366 |
+
|
367 |
+
response = requests.post(url, json=payload, headers=headers)
|
368 |
+
if response.status_code == 200:
|
369 |
+
print("✅ Data saved successfully!")
|
370 |
+
else:
|
371 |
+
raise Exception(f"⚠️ Failed to save data: {response.text}")
|
372 |
+
|
373 |
+
def refresh_token(self):
|
374 |
+
"""Refreshes access token"""
|
375 |
+
url = f"{API_BASE_URL}/refresh"
|
376 |
+
payload = {"refresh_token": self.refresh_token}
|
377 |
+
headers = {"Content-Type": "application/json"}
|
378 |
+
|
379 |
+
response = requests.post(url, json=payload, headers=headers)
|
380 |
+
if response.status_code == 200:
|
381 |
+
tokens = response.json()
|
382 |
+
self.access_token = tokens.get("access_token")
|
383 |
+
print(f"✅ Token refreshed! New Token: {self.access_token}")
|
384 |
+
else:
|
385 |
+
raise Exception(f"⚠️ Token refresh failed: {response.text}")
|
386 |
+
|
387 |
+
# Example Usage
|
388 |
+
client = APIClient()
|
389 |
+
|
390 |
+
try:
|
391 |
+
# Step 1: Login
|
392 |
+
client.login("user123", "password123")
|
393 |
+
|
394 |
+
# Step 2: Perform Search
|
395 |
+
search_results = client.search("test query")
|
396 |
+
|
397 |
+
# Step 3: Save Data (assuming we got some results)
|
398 |
+
if search_results:
|
399 |
+
save_items = [
|
400 |
+
{
|
401 |
+
"user_type": "user",
|
402 |
+
"username": "user123",
|
403 |
+
"query": "test query",
|
404 |
+
"retrieved_text": search_results[0]["text"],
|
405 |
+
"model_type": search_results[0]["model_type"],
|
406 |
+
"reaction": "positive",
|
407 |
+
}
|
408 |
+
]
|
409 |
+
client.save_data(save_items)
|
410 |
+
|
411 |
+
# Step 4: Refresh Token
|
412 |
+
client.refresh_token()
|
413 |
+
|
414 |
+
except Exception as e:
|
415 |
+
print(f"⚠️ Error: {e}")
|
416 |
+
</code></pre>
|
417 |
+
</div>
|
418 |
+
|
419 |
+
<h4>Response:</h4>
|
420 |
+
<pre><code class="language-json">{
|
421 |
+
"access_token": "your-access-token",
|
422 |
+
"refresh_token": "your-refresh-token",
|
423 |
+
"token_type": "bearer",
|
424 |
+
}</code></pre>
|
425 |
+
</section>
|
426 |
+
|
427 |
</main>
|
428 |
</div>
|
429 |
|
430 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/prism.min.js"></script>
|
431 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/components/prism-bash.min.js"></script>
|
432 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/prismjs/1.29.0/components/prism-json.min.js"></script>
|
433 |
+
<script src="script.js"></script>
|
434 |
</body>
|
435 |
</html>
|
static/script.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
// Generate navigation items
|
2 |
const sections = [
|
3 |
{ id: 'endpoints', title: 'Endpoints' },
|
|
|
4 |
{ id: 'login', title: 'Login' },
|
5 |
{ id: 'refresh', title: 'Refresh Token' },
|
6 |
{ id: 'search', title: 'Search' },
|
7 |
-
{ id: 'save', title: 'Save'},
|
8 |
{ id: 'workflow', title: 'Workflow Example' }
|
9 |
];
|
10 |
|
|
|
1 |
// Generate navigation items
|
2 |
const sections = [
|
3 |
{ id: 'endpoints', title: 'Endpoints' },
|
4 |
+
{ id: 'register', title: 'Register' },
|
5 |
{ id: 'login', title: 'Login' },
|
6 |
{ id: 'refresh', title: 'Refresh Token' },
|
7 |
{ id: 'search', title: 'Search' },
|
|
|
8 |
{ id: 'workflow', title: 'Workflow Example' }
|
9 |
];
|
10 |
|
utils.py
CHANGED
@@ -2,19 +2,18 @@ import asyncio
|
|
2 |
import ollama
|
3 |
|
4 |
async def generate_stream(query: str):
|
5 |
-
"""Generates streamed responses from Ollama using LLaMA 3
|
6 |
try:
|
7 |
stream = ollama.chat(
|
8 |
-
model="llama3.2",
|
9 |
messages=[{"role": "user", "content": query}],
|
10 |
stream=True
|
11 |
)
|
12 |
|
13 |
-
# Stream
|
14 |
for chunk in stream:
|
15 |
if "message" in chunk and "content" in chunk["message"]:
|
16 |
-
yield chunk["message"]["content"]
|
17 |
-
await asyncio.sleep(0)
|
18 |
|
19 |
except Exception as e:
|
20 |
yield f"⚠️ Error: {str(e)}"
|
|
|
2 |
import ollama
|
3 |
|
4 |
async def generate_stream(query: str):
|
5 |
+
"""Generates streamed responses from Ollama using LLaMA 3."""
|
6 |
try:
|
7 |
stream = ollama.chat(
|
8 |
+
model="llama3.2",
|
9 |
messages=[{"role": "user", "content": query}],
|
10 |
stream=True
|
11 |
)
|
12 |
|
13 |
+
# Stream output without unnecessary delay
|
14 |
for chunk in stream:
|
15 |
if "message" in chunk and "content" in chunk["message"]:
|
16 |
+
yield chunk["message"]["content"] # ✅ No sleep needed
|
|
|
17 |
|
18 |
except Exception as e:
|
19 |
yield f"⚠️ Error: {str(e)}"
|