File size: 10,330 Bytes
d6ca612
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# AI SBOM Generator API Documentation

## Overview

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.

## Base URL

When deployed on Hugging Face Spaces, the base URL will be:
```
https://aetheris-ai-aibom-generator.hf.space
```

Replace this with your actual deployment URL.

## API Endpoints

### Status Endpoint

**Purpose**: Check if the API is operational and get version information.

**Endpoint**: `/status`

**Method**: GET

**cURL Example**:
```bash
curl -X GET "https://aetheris-ai-aibom-generator.hf.space/status"
```

**Expected Response**:
```json
{
  "status": "operational",
  "version": "1.0.0",
  "generator_version": "1.0.0"
}
```

### Generate AIBOM Endpoint

**Purpose**: Generate an AI SBOM for a specified Hugging Face model.

**Endpoint**: `/api/generate`

**Method**: POST

**Parameters**:
- `model_id` (required): The Hugging Face model ID (e.g., 'meta-llama/Llama-2-7b-chat-hf')
- `include_inference` (optional): Whether to use AI inference to enhance the AI SBOM (default: true)
- `use_best_practices` (optional): Whether to use industry best practices for scoring (default: true)
- `hf_token` (optional): Hugging Face API token for accessing private models

**cURL Example**:
```bash
curl -X POST "https://aetheris-ai-aibom-generator.hf.space/api/generate" \
  -H "Content-Type: application/json" \
  -d '{
    "model_id": "meta-llama/Llama-2-7b-chat-hf",
    "include_inference": true,
    "use_best_practices": true
  }'
```

**Expected Response**: JSON containing the generated AIBOM, model ID, timestamp, and download URL.
```json
{
  "aibom": {
    "bomFormat": "CycloneDX",
    "specVersion": "1.6",
    "serialNumber": "urn:uuid:...",
    "version": 1,
    "metadata": { ... },
    "components": [ ... ],
    "dependencies": [ ... ]
  },
  "model_id": "meta-llama/Llama-2-7b-chat-hf",
  "generated_at": "2025-04-24T20:30:00Z",
  "request_id": "...",
  "download_url": "/output/meta-llama_Llama-2-7b-chat-hf_....json"
}
```

### Generate AIBOM with Enhancement Report

**Purpose**: Generate an AI SBOM with a detailed enhancement report.

**Endpoint**: `/api/generate-with-report`

**Method**: POST

**Parameters**: Same as `/api/generate`

**cURL Example**:
```bash
curl -X POST "https://aetheris-ai-aibom-generator.hf.space/api/generate-with-report" \
  -H "Content-Type: application/json" \
  -d '{
    "model_id": "meta-llama/Llama-2-7b-chat-hf",
    "include_inference": true,
    "use_best_practices": true
  }'
```

**Expected Response**: JSON containing the generated AIBOM, model ID, timestamp, download URL, and enhancement report.
```json
{
  "aibom": { ... },
  "model_id": "meta-llama/Llama-2-7b-chat-hf",
  "generated_at": "2025-04-24T20:30:00Z",
  "request_id": "...",
  "download_url": "/output/meta-llama_Llama-2-7b-chat-hf_....json",
  "enhancement_report": {
    "ai_enhanced": true,
    "ai_model": "BERT-base-uncased",
    "original_score": {
      "total_score": 65.5,
      "completeness_score": 65.5
    },
    "final_score": {
      "total_score": 85.2,
      "completeness_score": 85.2
    },
    "improvement": 19.7
  }
}
```

### Get Model Score

**Purpose**: Get the completeness score for a model without generating a full AIBOM.

**Endpoint**: `/api/models/{model_id}/score`

**Method**: GET

**Parameters**:
- `model_id` (path parameter): The Hugging Face model ID
- `hf_token` (query parameter, optional): Hugging Face API token for accessing private models
- `use_best_practices` (query parameter, optional): Whether to use industry best practices for scoring (default: true)

**cURL Example**:
```bash
curl -X GET "https://aetheris-ai-aibom-generator.hf.space/api/models/meta-llama/Llama-2-7b-chat-hf/score?use_best_practices=true"
```

**Expected Response**: JSON containing the completeness score information.
```json
{
  "total_score": 85.2,
  "section_scores": {
    "required_fields": 20,
    "metadata": 18.5,
    "component_basic": 20,
    "component_model_card": 20.7,
    "external_references": 6
  },
  "max_scores": {
    "required_fields": 20,
    "metadata": 20,
    "component_basic": 20,
    "component_model_card": 30,
    "external_references": 10
  }
}
```

### Batch Generate AIBOMs

**Purpose**: Start a batch job to generate AIBOMs for multiple models.

**Endpoint**: `/api/batch`

**Method**: POST

**Parameters**:
- `model_ids` (required): List of Hugging Face model IDs to generate AIBOMs for
- `include_inference` (optional): Whether to use AI inference to enhance the AI SBOM (default: true)
- `use_best_practices` (optional): Whether to use industry best practices for scoring (default: true)
- `hf_token` (optional): Hugging Face API token for accessing private models

**cURL Example**:
```bash
curl -X POST "https://aetheris-ai-aibom-generator.hf.space/api/batch" \
  -H "Content-Type: application/json" \
  -d '{
    "model_ids": [
      "meta-llama/Llama-2-7b-chat-hf",
      "google/flan-t5-base"
    ],
    "include_inference": true,
    "use_best_practices": true
  }'
```

**Expected Response**: JSON containing the batch job ID and status information.
```json
{
  "job_id": "...",
  "status": "queued",
  "model_ids": [
    "meta-llama/Llama-2-7b-chat-hf",
    "google/flan-t5-base"
  ],
  "created_at": "2025-04-24T20:30:00Z"
}
```

### Check Batch Job Status

**Purpose**: Check the status of a batch job.

**Endpoint**: `/api/batch/{job_id}`

**Method**: GET

**Parameters**:
- `job_id` (path parameter): The ID of the batch job to check

**cURL Example**:
```bash
curl -X GET "https://aetheris-ai-aibom-generator.hf.space/api/batch/{job_id}"
```

**Expected Response**: JSON containing the current status of the batch job and results for completed models.
```json
{
  "job_id": "...",
  "status": "processing",
  "model_ids": [
    "meta-llama/Llama-2-7b-chat-hf",
    "google/flan-t5-base"
  ],
  "created_at": "2025-04-24T20:30:00Z",
  "completed": 1,
  "total": 2,
  "results": {
    "meta-llama/Llama-2-7b-chat-hf": {
      "status": "completed",
      "download_url": "/output/meta-llama_Llama-2-7b-chat-hf_....json",
      "enhancement_report": { ... }
    }
  }
}
```

### Download Generated AIBOM

**Purpose**: Download a previously generated AIBOM file.

**Endpoint**: `/download/{filename}`

**Method**: GET

**Parameters**:
- `filename` (path parameter): The filename of the AIBOM to download

**cURL Example**:
```bash
curl -X GET "https://aetheris-ai-aibom-generator.hf.space/download/{filename}" \
  -o "downloaded_aibom.json"
```

**Expected Response**: The AIBOM JSON file will be downloaded to your local machine.

### Form-Based Generation (Web UI)

**Purpose**: Generate an AIBOM using form data (typically used by the web UI).

**Endpoint**: `/generate`

**Method**: POST

**Parameters**:
- `model_id` (form field, required): The Hugging Face model ID
- `include_inference` (form field, optional): Whether to use AI inference to enhance the AI SBOM
- `use_best_practices` (form field, optional): Whether to use industry best practices for scoring

**cURL Example**:
```bash
curl -X POST "https://aetheris-ai-aibom-generator.hf.space/generate" \
  -F "model_id=meta-llama/Llama-2-7b-chat-hf" \
  -F "include_inference=true" \
  -F "use_best_practices=true"
```

**Expected Response**: HTML page with the generated AIBOM results.

## Web UI

The API also provides a web user interface for generating AIBOMs without writing code:

**URL**: `https://aetheris-ai-aibom-generator.hf.space/`

The web UI allows you to:
1. Enter a Hugging Face model ID
2. Configure generation options
3. Generate an AIBOM
4. View the results in a human-friendly format
5. Download the generated AIBOM as a JSON file

## Understanding the Field Checklist

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:

- **Check marks**:
  - βœ”: Field is present in the AIBOM
  - ✘: Field is missing from the AIBOM

- **Stars** (importance level):
  - β˜…β˜…β˜… (three stars): Critical fields - Essential for a valid and complete AIBOM
  - β˜…β˜… (two stars): Important fields - Valuable information that enhances completeness
  - β˜… (one star): Supplementary fields - Additional context and details (optional)

## Notes on Using the API

1. When deployed on Hugging Face Spaces, use the correct URL format as shown in the examples.
2. Some endpoints may have rate limiting or require authentication.
3. For large responses, consider adding appropriate timeout settings in your requests.
4. If you encounter CORS issues, you may need to add appropriate headers.
5. For downloading files, specify the output file name in your client code.

## Error Handling

The API returns standard HTTP status codes:
- 200: Success
- 400: Bad Request (invalid parameters)
- 404: Not Found (resource not found)
- 500: Internal Server Error (server-side error)

Error responses include a detail message explaining the error:
```json
{
  "detail": "Error generating AI SBOM: Model not found"
}
```

## Completeness Score

The completeness score is calculated based on the presence and quality of various fields in the AIBOM. The score is broken down into sections:

1. **Required Fields** (20 points): Basic required fields for a valid AIBOM
2. **Metadata** (20 points): Information about the AIBOM itself
3. **Component Basic Info** (20 points): Basic information about the AI model component
4. **Model Card** (30 points): Detailed model card information
5. **External References** (10 points): Links to external resources

The total score is a weighted sum of these section scores, with a maximum of 100 points.

## Enhancement Report

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:

1. **Original Score**: The completeness score before enhancement
2. **Enhanced Score**: The completeness score after enhancement
3. **Improvement**: The point increase from enhancement
4. **AI Model Used**: The model used for enhancement

This helps you understand how much the AI enhancement improved the AIBOM's completeness.