a1c00l commited on
Commit
d6ca612
Β·
verified Β·
1 Parent(s): 17e9c2f

Create docs/AI_SBOM_API_doc.md

Browse files
Files changed (1) hide show
  1. docs/AI_SBOM_API_doc.md +359 -0
docs/AI_SBOM_API_doc.md ADDED
@@ -0,0 +1,359 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AI SBOM Generator API Documentation
2
+
3
+ ## Overview
4
+
5
+ The AI SBOM Generator API provides a comprehensive solution for generating CycloneDX-compliant AI Bill of Materials (AIBOM) for Hugging Face models. This document outlines the available API endpoints, their functionality, and how to interact with them using cURL commands.
6
+
7
+ ## Base URL
8
+
9
+ When deployed on Hugging Face Spaces, the base URL will be:
10
+ ```
11
+ https://aetheris-ai-aibom-generator.hf.space
12
+ ```
13
+
14
+ Replace this with your actual deployment URL.
15
+
16
+ ## API Endpoints
17
+
18
+ ### Status Endpoint
19
+
20
+ **Purpose**: Check if the API is operational and get version information.
21
+
22
+ **Endpoint**: `/status`
23
+
24
+ **Method**: GET
25
+
26
+ **cURL Example**:
27
+ ```bash
28
+ curl -X GET "https://aetheris-ai-aibom-generator.hf.space/status"
29
+ ```
30
+
31
+ **Expected Response**:
32
+ ```json
33
+ {
34
+ "status": "operational",
35
+ "version": "1.0.0",
36
+ "generator_version": "1.0.0"
37
+ }
38
+ ```
39
+
40
+ ### Generate AIBOM Endpoint
41
+
42
+ **Purpose**: Generate an AI SBOM for a specified Hugging Face model.
43
+
44
+ **Endpoint**: `/api/generate`
45
+
46
+ **Method**: POST
47
+
48
+ **Parameters**:
49
+ - `model_id` (required): The Hugging Face model ID (e.g., 'meta-llama/Llama-2-7b-chat-hf')
50
+ - `include_inference` (optional): Whether to use AI inference to enhance the AI SBOM (default: true)
51
+ - `use_best_practices` (optional): Whether to use industry best practices for scoring (default: true)
52
+ - `hf_token` (optional): Hugging Face API token for accessing private models
53
+
54
+ **cURL Example**:
55
+ ```bash
56
+ curl -X POST "https://aetheris-ai-aibom-generator.hf.space/api/generate" \
57
+ -H "Content-Type: application/json" \
58
+ -d '{
59
+ "model_id": "meta-llama/Llama-2-7b-chat-hf",
60
+ "include_inference": true,
61
+ "use_best_practices": true
62
+ }'
63
+ ```
64
+
65
+ **Expected Response**: JSON containing the generated AIBOM, model ID, timestamp, and download URL.
66
+ ```json
67
+ {
68
+ "aibom": {
69
+ "bomFormat": "CycloneDX",
70
+ "specVersion": "1.6",
71
+ "serialNumber": "urn:uuid:...",
72
+ "version": 1,
73
+ "metadata": { ... },
74
+ "components": [ ... ],
75
+ "dependencies": [ ... ]
76
+ },
77
+ "model_id": "meta-llama/Llama-2-7b-chat-hf",
78
+ "generated_at": "2025-04-24T20:30:00Z",
79
+ "request_id": "...",
80
+ "download_url": "/output/meta-llama_Llama-2-7b-chat-hf_....json"
81
+ }
82
+ ```
83
+
84
+ ### Generate AIBOM with Enhancement Report
85
+
86
+ **Purpose**: Generate an AI SBOM with a detailed enhancement report.
87
+
88
+ **Endpoint**: `/api/generate-with-report`
89
+
90
+ **Method**: POST
91
+
92
+ **Parameters**: Same as `/api/generate`
93
+
94
+ **cURL Example**:
95
+ ```bash
96
+ curl -X POST "https://aetheris-ai-aibom-generator.hf.space/api/generate-with-report" \
97
+ -H "Content-Type: application/json" \
98
+ -d '{
99
+ "model_id": "meta-llama/Llama-2-7b-chat-hf",
100
+ "include_inference": true,
101
+ "use_best_practices": true
102
+ }'
103
+ ```
104
+
105
+ **Expected Response**: JSON containing the generated AIBOM, model ID, timestamp, download URL, and enhancement report.
106
+ ```json
107
+ {
108
+ "aibom": { ... },
109
+ "model_id": "meta-llama/Llama-2-7b-chat-hf",
110
+ "generated_at": "2025-04-24T20:30:00Z",
111
+ "request_id": "...",
112
+ "download_url": "/output/meta-llama_Llama-2-7b-chat-hf_....json",
113
+ "enhancement_report": {
114
+ "ai_enhanced": true,
115
+ "ai_model": "BERT-base-uncased",
116
+ "original_score": {
117
+ "total_score": 65.5,
118
+ "completeness_score": 65.5
119
+ },
120
+ "final_score": {
121
+ "total_score": 85.2,
122
+ "completeness_score": 85.2
123
+ },
124
+ "improvement": 19.7
125
+ }
126
+ }
127
+ ```
128
+
129
+ ### Get Model Score
130
+
131
+ **Purpose**: Get the completeness score for a model without generating a full AIBOM.
132
+
133
+ **Endpoint**: `/api/models/{model_id}/score`
134
+
135
+ **Method**: GET
136
+
137
+ **Parameters**:
138
+ - `model_id` (path parameter): The Hugging Face model ID
139
+ - `hf_token` (query parameter, optional): Hugging Face API token for accessing private models
140
+ - `use_best_practices` (query parameter, optional): Whether to use industry best practices for scoring (default: true)
141
+
142
+ **cURL Example**:
143
+ ```bash
144
+ curl -X GET "https://aetheris-ai-aibom-generator.hf.space/api/models/meta-llama/Llama-2-7b-chat-hf/score?use_best_practices=true"
145
+ ```
146
+
147
+ **Expected Response**: JSON containing the completeness score information.
148
+ ```json
149
+ {
150
+ "total_score": 85.2,
151
+ "section_scores": {
152
+ "required_fields": 20,
153
+ "metadata": 18.5,
154
+ "component_basic": 20,
155
+ "component_model_card": 20.7,
156
+ "external_references": 6
157
+ },
158
+ "max_scores": {
159
+ "required_fields": 20,
160
+ "metadata": 20,
161
+ "component_basic": 20,
162
+ "component_model_card": 30,
163
+ "external_references": 10
164
+ }
165
+ }
166
+ ```
167
+
168
+ ### Batch Generate AIBOMs
169
+
170
+ **Purpose**: Start a batch job to generate AIBOMs for multiple models.
171
+
172
+ **Endpoint**: `/api/batch`
173
+
174
+ **Method**: POST
175
+
176
+ **Parameters**:
177
+ - `model_ids` (required): List of Hugging Face model IDs to generate AIBOMs for
178
+ - `include_inference` (optional): Whether to use AI inference to enhance the AI SBOM (default: true)
179
+ - `use_best_practices` (optional): Whether to use industry best practices for scoring (default: true)
180
+ - `hf_token` (optional): Hugging Face API token for accessing private models
181
+
182
+ **cURL Example**:
183
+ ```bash
184
+ curl -X POST "https://aetheris-ai-aibom-generator.hf.space/api/batch" \
185
+ -H "Content-Type: application/json" \
186
+ -d '{
187
+ "model_ids": [
188
+ "meta-llama/Llama-2-7b-chat-hf",
189
+ "google/flan-t5-base"
190
+ ],
191
+ "include_inference": true,
192
+ "use_best_practices": true
193
+ }'
194
+ ```
195
+
196
+ **Expected Response**: JSON containing the batch job ID and status information.
197
+ ```json
198
+ {
199
+ "job_id": "...",
200
+ "status": "queued",
201
+ "model_ids": [
202
+ "meta-llama/Llama-2-7b-chat-hf",
203
+ "google/flan-t5-base"
204
+ ],
205
+ "created_at": "2025-04-24T20:30:00Z"
206
+ }
207
+ ```
208
+
209
+ ### Check Batch Job Status
210
+
211
+ **Purpose**: Check the status of a batch job.
212
+
213
+ **Endpoint**: `/api/batch/{job_id}`
214
+
215
+ **Method**: GET
216
+
217
+ **Parameters**:
218
+ - `job_id` (path parameter): The ID of the batch job to check
219
+
220
+ **cURL Example**:
221
+ ```bash
222
+ curl -X GET "https://aetheris-ai-aibom-generator.hf.space/api/batch/{job_id}"
223
+ ```
224
+
225
+ **Expected Response**: JSON containing the current status of the batch job and results for completed models.
226
+ ```json
227
+ {
228
+ "job_id": "...",
229
+ "status": "processing",
230
+ "model_ids": [
231
+ "meta-llama/Llama-2-7b-chat-hf",
232
+ "google/flan-t5-base"
233
+ ],
234
+ "created_at": "2025-04-24T20:30:00Z",
235
+ "completed": 1,
236
+ "total": 2,
237
+ "results": {
238
+ "meta-llama/Llama-2-7b-chat-hf": {
239
+ "status": "completed",
240
+ "download_url": "/output/meta-llama_Llama-2-7b-chat-hf_....json",
241
+ "enhancement_report": { ... }
242
+ }
243
+ }
244
+ }
245
+ ```
246
+
247
+ ### Download Generated AIBOM
248
+
249
+ **Purpose**: Download a previously generated AIBOM file.
250
+
251
+ **Endpoint**: `/download/{filename}`
252
+
253
+ **Method**: GET
254
+
255
+ **Parameters**:
256
+ - `filename` (path parameter): The filename of the AIBOM to download
257
+
258
+ **cURL Example**:
259
+ ```bash
260
+ curl -X GET "https://aetheris-ai-aibom-generator.hf.space/download/{filename}" \
261
+ -o "downloaded_aibom.json"
262
+ ```
263
+
264
+ **Expected Response**: The AIBOM JSON file will be downloaded to your local machine.
265
+
266
+ ### Form-Based Generation (Web UI)
267
+
268
+ **Purpose**: Generate an AIBOM using form data (typically used by the web UI).
269
+
270
+ **Endpoint**: `/generate`
271
+
272
+ **Method**: POST
273
+
274
+ **Parameters**:
275
+ - `model_id` (form field, required): The Hugging Face model ID
276
+ - `include_inference` (form field, optional): Whether to use AI inference to enhance the AI SBOM
277
+ - `use_best_practices` (form field, optional): Whether to use industry best practices for scoring
278
+
279
+ **cURL Example**:
280
+ ```bash
281
+ curl -X POST "https://aetheris-ai-aibom-generator.hf.space/generate" \
282
+ -F "model_id=meta-llama/Llama-2-7b-chat-hf" \
283
+ -F "include_inference=true" \
284
+ -F "use_best_practices=true"
285
+ ```
286
+
287
+ **Expected Response**: HTML page with the generated AIBOM results.
288
+
289
+ ## Web UI
290
+
291
+ The API also provides a web user interface for generating AIBOMs without writing code:
292
+
293
+ **URL**: `https://aetheris-ai-aibom-generator.hf.space/`
294
+
295
+ The web UI allows you to:
296
+ 1. Enter a Hugging Face model ID
297
+ 2. Configure generation options
298
+ 3. Generate an AIBOM
299
+ 4. View the results in a human-friendly format
300
+ 5. Download the generated AIBOM as a JSON file
301
+
302
+ ## Understanding the Field Checklist
303
+
304
+ In the Field Checklist tab of the results page, you'll see a list of fields with check marks (βœ”/✘) and stars (β˜…). Here's what they mean:
305
+
306
+ - **Check marks**:
307
+ - βœ”: Field is present in the AIBOM
308
+ - ✘: Field is missing from the AIBOM
309
+
310
+ - **Stars** (importance level):
311
+ - β˜…β˜…β˜… (three stars): Critical fields - Essential for a valid and complete AIBOM
312
+ - β˜…β˜… (two stars): Important fields - Valuable information that enhances completeness
313
+ - β˜… (one star): Supplementary fields - Additional context and details (optional)
314
+
315
+ ## Notes on Using the API
316
+
317
+ 1. When deployed on Hugging Face Spaces, use the correct URL format as shown in the examples.
318
+ 2. Some endpoints may have rate limiting or require authentication.
319
+ 3. For large responses, consider adding appropriate timeout settings in your requests.
320
+ 4. If you encounter CORS issues, you may need to add appropriate headers.
321
+ 5. For downloading files, specify the output file name in your client code.
322
+
323
+ ## Error Handling
324
+
325
+ The API returns standard HTTP status codes:
326
+ - 200: Success
327
+ - 400: Bad Request (invalid parameters)
328
+ - 404: Not Found (resource not found)
329
+ - 500: Internal Server Error (server-side error)
330
+
331
+ Error responses include a detail message explaining the error:
332
+ ```json
333
+ {
334
+ "detail": "Error generating AI SBOM: Model not found"
335
+ }
336
+ ```
337
+
338
+ ## Completeness Score
339
+
340
+ The completeness score is calculated based on the presence and quality of various fields in the AIBOM. The score is broken down into sections:
341
+
342
+ 1. **Required Fields** (20 points): Basic required fields for a valid AIBOM
343
+ 2. **Metadata** (20 points): Information about the AIBOM itself
344
+ 3. **Component Basic Info** (20 points): Basic information about the AI model component
345
+ 4. **Model Card** (30 points): Detailed model card information
346
+ 5. **External References** (10 points): Links to external resources
347
+
348
+ The total score is a weighted sum of these section scores, with a maximum of 100 points.
349
+
350
+ ## Enhancement Report
351
+
352
+ When AI enhancement is enabled, the API uses an inference model to extract additional information from the model card and other sources. The enhancement report shows:
353
+
354
+ 1. **Original Score**: The completeness score before enhancement
355
+ 2. **Enhanced Score**: The completeness score after enhancement
356
+ 3. **Improvement**: The point increase from enhancement
357
+ 4. **AI Model Used**: The model used for enhancement
358
+
359
+ This helps you understand how much the AI enhancement improved the AIBOM's completeness.