eli02 commited on
Commit
2abc9f5
·
1 Parent(s): c895708

Refactor API documentation for search and logout endpoints; enhance styling for code blocks and navigation items

Browse files
Files changed (3) hide show
  1. static/index.html +77 -103
  2. static/script.js +6 -6
  3. static/style.css +3 -0
static/index.html CHANGED
@@ -133,77 +133,24 @@ class LoginResponse {
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
- <h4>cURL Request:</h4>
141
- <pre><code class="language-bash">curl -X POST https://humblebeeai-al-ghazali-rag-retrieval-api.hf.space/search \
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
- <h4>Response:</h4>
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>
@@ -286,38 +233,39 @@ Future<void> saveData(List<SaveInput> items, String accessToken) async {
286
  }</code></pre>
287
  </div>
288
  <div class="endpoint" id="logout">
289
- <h3>5. Log-out Endpoint</h3>
290
- <p><span class="method">POST</span><span class="endpoint-url">/logout</span></p>
291
- <p>This endpoint is used to revoke the access token after the event of logout click.</p>
292
-
293
- <h4>cURL Reqeust:</h4>
294
- <pre><code class="language-bash">curl -X POST https://humblebeeai-al-ghazali-rag-retrieval-api.hf.space/logout \
295
- -H "Authorization: Bearer YOUR_ACCESS_TOKEN"</code></pre>
296
- <h4>Flutter Implementation:</h4>
297
- <pre><code class="language-dart">Future<void> logout(String accessToken) async {
298
- final url = Uri.parse('https://humblebeeai-al-ghazali-rag-retrieval-api.hf.space/logout');
299
-
300
- try {
301
- final response = await http.post(
302
- url,
303
- headers: {
304
- 'Authorization
305
- ': 'Bearer $accessToken',
306
- },
307
- );
308
-
309
- if (response.statusCode != 200) {
310
- throw Exception('Failed to logout: ${response.body}');
311
- }
312
- } catch (e) {
313
- throw Exception('Network error: $e');
314
- }
315
- }</code></pre>
316
- <h4>Response:</h4>
317
- <pre><code class="language-json">{
318
- "message": "Successfully logged out"
319
- }</code></pre>
320
- </div>
 
321
  </section>
322
 
323
  <section id="workflow">
@@ -475,6 +423,23 @@ class _ApiWorkflowExampleState extends State<ApiWorkflowExample> {
475
  }
476
  }
477
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
478
  @override
479
  Widget build(BuildContext context) {
480
  return Scaffold(
@@ -502,6 +467,10 @@ class _ApiWorkflowExampleState extends State<ApiWorkflowExample> {
502
  onPressed: _refreshToken,
503
  child: Text('Refresh Token'),
504
  ),
 
 
 
 
505
  Expanded(
506
  child: ListView.builder(
507
  itemCount: _searchResults.length,
@@ -687,6 +656,11 @@ class SaveInput {
687
  }
688
  }</code></pre>
689
  </div>
 
 
 
 
 
690
  </section>
691
  </main>
692
  </div>
 
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
+ <h4>Response:</h4>
141
+ <pre><code class="language-json">[
142
+ {
143
+ "text": "Result 1 text",
144
+ "similarity": 0.95,
145
+ "model_type": "all-mpnet-base-v2"
146
+ },
147
+ {
148
+ "text": "Result 2 text",
149
+ "similarity": 0.92,
150
+ "model_type": "text-embedding-3-small"
151
+ }
152
+ ]</code></pre>
153
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
 
155
  <div class="endpoint" id="save">
156
  <h3>4. Save Data Endpoint</h3>
 
233
  }</code></pre>
234
  </div>
235
  <div class="endpoint" id="logout">
236
+ <h3>5. Logout Endpoint</h3>
237
+ <p><span class="method">POST</span><span class="endpoint-url">/logout</span></p>
238
+ <p>This endpoint is used to revoke the current access token.</p>
239
+
240
+ <h4>cURL Request:</h4>
241
+ <pre><code class="language-bash">curl -X POST https://humblebeeai-al-ghazali-rag-retrieval-api.hf.space/logout \
242
+ -H "Authorization: Bearer your-access-token"</code></pre>
243
+
244
+ <h4>Flutter Implementation:</h4>
245
+ <pre><code class="language-dart">Future<void> logout(String accessToken) async {
246
+ final url = Uri.parse('https://humblebeeai-al-ghazali-rag-retrieval-api.hf.space/logout');
247
+
248
+ try {
249
+ final response = await http.post(
250
+ url,
251
+ headers: {
252
+ 'Authorization': 'Bearer $accessToken',
253
+ },
254
+ );
255
+
256
+ if (response.statusCode != 200) {
257
+ throw Exception('Failed to logout: ${response.body}');
258
+ }
259
+ } catch (e) {
260
+ throw Exception('Network error: $e');
261
+ }
262
+ }</code></pre>
263
+
264
+ <h4>Response:</h4>
265
+ <pre><code class="language-json">{
266
+ "message": "Successfully logged out"
267
+ }</code></pre>
268
+ </div>
269
  </section>
270
 
271
  <section id="workflow">
 
423
  }
424
  }
425
 
426
+ Future<void> _logout() async {
427
+ try {
428
+ await logout(_accessToken);
429
+ setState(() {
430
+ _accessToken = '';
431
+ _refreshToken = '';
432
+ });
433
+ ScaffoldMessenger.of(context).showSnackBar(
434
+ SnackBar(content: Text('Logged out successfully!')),
435
+ );
436
+ } catch (e) {
437
+ ScaffoldMessenger.of(context).showSnackBar(
438
+ SnackBar(content: Text('Logout failed: $e')),
439
+ );
440
+ }
441
+ }
442
+
443
  @override
444
  Widget build(BuildContext context) {
445
  return Scaffold(
 
467
  onPressed: _refreshToken,
468
  child: Text('Refresh Token'),
469
  ),
470
+ ElevatedButton(
471
+ onPressed: _logout,
472
+ child: Text('Logout'),
473
+ ),
474
  Expanded(
475
  child: ListView.builder(
476
  itemCount: _searchResults.length,
 
656
  }
657
  }</code></pre>
658
  </div>
659
+ <div class="endpoint">
660
+ <h3>Step 5: Logout</h3>
661
+ <pre><code class="language-bash">curl -X POST https://humblebeeai-al-ghazali-rag-retrieval-api.hf.space/logout \
662
+ -H "Authorization: Bearer your-access-token"</code></pre>
663
+ </div>
664
  </section>
665
  </main>
666
  </div>
static/script.js CHANGED
@@ -1,11 +1,11 @@
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: 'logout', title: 'Logout' },
9
  { id: 'workflow', title: 'Workflow Example' }
10
  ];
11
 
 
1
  // Generate navigation items
2
  const sections = [
3
+ { id: 'endpoints', title: 'API Endpoints' },
4
+ { id: 'login', title: '1. Login' },
5
+ { id: 'refresh', title: '2. Refresh Token' },
6
+ { id: 'search', title: '3. Search' },
7
+ { id: 'save', title: '4. Save Data' },
8
+ { id: 'logout', title: '5. Logout' },
9
  { id: 'workflow', title: 'Workflow Example' }
10
  ];
11
 
static/style.css CHANGED
@@ -145,6 +145,7 @@ pre code {
145
  border-radius: 0.5rem;
146
  padding: 1.5rem;
147
  margin: 1.5rem 0;
 
148
  }
149
 
150
  .method {
@@ -155,11 +156,13 @@ pre code {
155
  color: white;
156
  font-weight: 500;
157
  margin-right: 0.5rem;
 
158
  }
159
 
160
  .endpoint-url {
161
  font-family: 'Fira Code', monospace;
162
  color: var(--secondary-color);
 
163
  }
164
 
165
  @media (max-width: 768px) {
 
145
  border-radius: 0.5rem;
146
  padding: 1.5rem;
147
  margin: 1.5rem 0;
148
+ box-shadow: 0 1px 3px rgba(0,0,0,0.1);
149
  }
150
 
151
  .method {
 
156
  color: white;
157
  font-weight: 500;
158
  margin-right: 0.5rem;
159
+ font-size: 0.9rem;
160
  }
161
 
162
  .endpoint-url {
163
  font-family: 'Fira Code', monospace;
164
  color: var(--secondary-color);
165
+ font-size: 0.95rem;
166
  }
167
 
168
  @media (max-width: 768px) {