Skip to content

Commit

Permalink
Trim the saasbom to help all models including Gemini (#1454)
Browse files Browse the repository at this point in the history
Signed-off-by: Prabhu Subramanian <[email protected]>
  • Loading branch information
prabhu authored Nov 13, 2024
1 parent 7d14de2 commit 3b4b2fe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
1 change: 0 additions & 1 deletion bin/cdxgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,6 @@ const checkPermissions = (filePath) => {
printTable(bomNSData.bomJson);
// CBOM related print
if (options.includeCrypto) {
console.log("\n*** Cryptography BOM ***");
printTable(bomNSData.bomJson, ["cryptographic-asset"]);
printDependencyTree(bomNSData.bomJson, "provides");
}
Expand Down
19 changes: 17 additions & 2 deletions lib/stages/postgen/postgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,17 @@ export function annotate(bomJson, options) {
if (!cdxgenAnnotator.length) {
return bomJson;
}
const requiresContextTrimming = ["ml-tiny"].includes(options?.profile);
const { bomType } = findBomType(bomJson);
const requiresContextTuning = [
"deep-learning",
"machine-learning",
"ml",
"ml-deep",
"ml-tiny",
].includes(options?.profile);
const requiresContextTrimming =
(requiresContextTuning && ["saasbom"].includes(bomType.toLowerCase())) ||
["ml-tiny"].includes(options?.profile);
// Construct the bom-link prefix to use for context tuning
const bomLinkPrefix = `${bomJson.serialNumber}/${bomJson.version}/`;
const metadataAnnotations = textualMetadata(bomJson);
Expand Down Expand Up @@ -343,8 +346,13 @@ export function annotate(bomJson, options) {
if (bomJson?.metadata?.component?.["bom-ref"]) {
bomJson.metadata.component["bom-ref"] = undefined;
}
if (bomJson?.metadata?.component?.properties) {
bomJson.metadata.component.properties = undefined;
}
if (bomJson?.metadata?.properties) {
bomJson.metadata.properties = undefined;
}
}
const { bomType, bomTypeDescription } = findBomType(bomJson);
// Tag the components
for (const comp of bomJson.components) {
const tags = extractTags(comp, bomType);
Expand Down Expand Up @@ -372,6 +380,13 @@ export function annotate(bomJson, options) {
// For tiny models, we can remove the dependencies section
if (requiresContextTrimming) {
bomJson.dependencies = undefined;
if (bomType.toLowerCase() === "saasbom") {
bomJson.components = undefined;
let i = 0;
for (const aserv of bomJson.services) {
aserv.name = `service-${i++}`;
}
}
}
// Problem: information such as the dependency tree are specific to an sbom
// To prevent the models from incorrectly learning about the trees, we automatically convert all bom-ref
Expand Down
2 changes: 1 addition & 1 deletion types/lib/stages/postgen/postgen.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3b4b2fe

Please sign in to comment.