fix: update gguf data to be GGUFFileHeader

Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>
This commit is contained in:
Christopher Phillips 2025-10-22 13:20:23 -04:00
parent ce74ed0309
commit a08d5b78d9
No known key found for this signature in database
9 changed files with 19 additions and 4065 deletions

View File

@ -27,7 +27,7 @@ func AllTypes() []any {
pkg.ELFBinaryPackageNoteJSONPayload{}, pkg.ELFBinaryPackageNoteJSONPayload{},
pkg.ElixirMixLockEntry{}, pkg.ElixirMixLockEntry{},
pkg.ErlangRebarLockEntry{}, pkg.ErlangRebarLockEntry{},
pkg.GGUFFileMetadata{}, pkg.GGUFFileHeader{},
pkg.GitHubActionsUseStatement{}, pkg.GitHubActionsUseStatement{},
pkg.GolangBinaryBuildinfoEntry{}, pkg.GolangBinaryBuildinfoEntry{},
pkg.GolangModuleEntry{}, pkg.GolangModuleEntry{},

View File

@ -122,7 +122,7 @@ var jsonTypes = makeJSONTypes(
jsonNames(pkg.TerraformLockProviderEntry{}, "terraform-lock-provider-entry"), jsonNames(pkg.TerraformLockProviderEntry{}, "terraform-lock-provider-entry"),
jsonNames(pkg.DotnetPackagesLockEntry{}, "dotnet-packages-lock-entry"), jsonNames(pkg.DotnetPackagesLockEntry{}, "dotnet-packages-lock-entry"),
jsonNames(pkg.CondaMetaPackage{}, "conda-metadata-entry", "CondaPackageMetadata"), jsonNames(pkg.CondaMetaPackage{}, "conda-metadata-entry", "CondaPackageMetadata"),
jsonNames(pkg.GGUFFileMetadata{}, "gguf-file-metadata"), jsonNames(pkg.GGUFFileHeader{}, "gguf-file-metadata"),
) )
func expandLegacyNameVariants(names ...string) []string { func expandLegacyNameVariants(names ...string) []string {

File diff suppressed because it is too large Load Diff

View File

@ -53,7 +53,7 @@ func Test_OriginatorSupplier(t *testing.T) {
pkg.OpamPackage{}, pkg.OpamPackage{},
pkg.YarnLockEntry{}, pkg.YarnLockEntry{},
pkg.TerraformLockProviderEntry{}, pkg.TerraformLockProviderEntry{},
pkg.GGUFFileMetadata{}, pkg.GGUFFileHeader{},
) )
tests := []struct { tests := []struct {
name string name string

View File

@ -117,7 +117,7 @@ func TestGGUFCataloger_Integration(t *testing.T) {
Licenses: pkg.NewLicenseSet( Licenses: pkg.NewLicenseSet(
pkg.NewLicenseFromFields("Apache-2.0", "", nil), pkg.NewLicenseFromFields("Apache-2.0", "", nil),
), ),
Metadata: pkg.GGUFFileMetadata{ Metadata: pkg.GGUFFileHeader{
ModelFormat: "gguf", ModelFormat: "gguf",
ModelName: "llama3-8b", ModelName: "llama3-8b",
ModelVersion: "3.0", ModelVersion: "3.0",
@ -166,7 +166,7 @@ func TestGGUFCataloger_Integration(t *testing.T) {
Name: "model1", Name: "model1",
Version: "1.0", Version: "1.0",
Type: pkg.ModelPkg, Type: pkg.ModelPkg,
Metadata: pkg.GGUFFileMetadata{ Metadata: pkg.GGUFFileHeader{
ModelFormat: "gguf", ModelFormat: "gguf",
ModelName: "model1", ModelName: "model1",
ModelVersion: "1.0", ModelVersion: "1.0",
@ -182,7 +182,7 @@ func TestGGUFCataloger_Integration(t *testing.T) {
Name: "model2", Name: "model2",
Version: "2.0", Version: "2.0",
Type: pkg.ModelPkg, Type: pkg.ModelPkg,
Metadata: pkg.GGUFFileMetadata{ Metadata: pkg.GGUFFileHeader{
ModelFormat: "gguf", ModelFormat: "gguf",
ModelName: "model2", ModelName: "model2",
ModelVersion: "2.0", ModelVersion: "2.0",
@ -219,7 +219,7 @@ func TestGGUFCataloger_Integration(t *testing.T) {
Name: "qwen-nested", Name: "qwen-nested",
Version: unknownGGUFData, Version: unknownGGUFData,
Type: pkg.ModelPkg, Type: pkg.ModelPkg,
Metadata: pkg.GGUFFileMetadata{ Metadata: pkg.GGUFFileHeader{
ModelFormat: "gguf", ModelFormat: "gguf",
ModelName: "qwen-nested", ModelName: "qwen-nested",
ModelVersion: unknownGGUFData, ModelVersion: unknownGGUFData,
@ -248,7 +248,7 @@ func TestGGUFCataloger_Integration(t *testing.T) {
IgnorePackageFields("FoundBy", "Locations"). // These are set by the cataloger IgnorePackageFields("FoundBy", "Locations"). // These are set by the cataloger
WithCompareOptions( WithCompareOptions(
// Ignore Hash as it's computed dynamically // Ignore Hash as it's computed dynamically
cmpopts.IgnoreFields(pkg.GGUFFileMetadata{}, "Hash"), cmpopts.IgnoreFields(pkg.GGUFFileHeader{}, "Hash"),
) )
tester.TestCataloger(t, NewGGUFCataloger()) tester.TestCataloger(t, NewGGUFCataloger())

View File

@ -10,7 +10,7 @@ import (
"github.com/anchore/syft/syft/pkg" "github.com/anchore/syft/syft/pkg"
) )
func newGGUFPackage(metadata *pkg.GGUFFileMetadata, locations ...file.Location) pkg.Package { func newGGUFPackage(metadata *pkg.GGUFFileHeader, locations ...file.Location) pkg.Package {
// Compute hash if not already set // Compute hash if not already set
if metadata.Hash == "" { if metadata.Hash == "" {
metadata.Hash = computeMetadataHash(metadata) metadata.Hash = computeMetadataHash(metadata)
@ -38,7 +38,7 @@ func newGGUFPackage(metadata *pkg.GGUFFileMetadata, locations ...file.Location)
} }
// computeMetadataHash computes a stable hash of the metadata for use as a global identifier // computeMetadataHash computes a stable hash of the metadata for use as a global identifier
func computeMetadataHash(metadata *pkg.GGUFFileMetadata) string { func computeMetadataHash(metadata *pkg.GGUFFileHeader) string {
// Create a stable representation of the metadata // Create a stable representation of the metadata
hashData := struct { hashData := struct {
Format string Format string

View File

@ -13,13 +13,13 @@ import (
func TestNewGGUFPackage(t *testing.T) { func TestNewGGUFPackage(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
metadata *pkg.GGUFFileMetadata metadata *pkg.GGUFFileHeader
locations []file.Location locations []file.Location
checkFunc func(t *testing.T, p pkg.Package) checkFunc func(t *testing.T, p pkg.Package)
}{ }{
{ {
name: "complete GGUF package with all fields", name: "complete GGUF package with all fields",
metadata: &pkg.GGUFFileMetadata{ metadata: &pkg.GGUFFileHeader{
ModelFormat: "gguf", ModelFormat: "gguf",
ModelName: "llama3-8b-instruct", ModelName: "llama3-8b-instruct",
ModelVersion: "3.0", ModelVersion: "3.0",
@ -45,7 +45,7 @@ func TestNewGGUFPackage(t *testing.T) {
}, },
{ {
name: "minimal GGUF package", name: "minimal GGUF package",
metadata: &pkg.GGUFFileMetadata{ metadata: &pkg.GGUFFileHeader{
ModelFormat: "gguf", ModelFormat: "gguf",
ModelName: "simple-model", ModelName: "simple-model",
ModelVersion: "1.0", ModelVersion: "1.0",
@ -64,7 +64,7 @@ func TestNewGGUFPackage(t *testing.T) {
}, },
{ {
name: "GGUF package with multiple locations", name: "GGUF package with multiple locations",
metadata: &pkg.GGUFFileMetadata{ metadata: &pkg.GGUFFileHeader{
ModelFormat: "gguf", ModelFormat: "gguf",
ModelName: "multi-location-model", ModelName: "multi-location-model",
ModelVersion: "1.5", ModelVersion: "1.5",
@ -91,8 +91,8 @@ func TestNewGGUFPackage(t *testing.T) {
assert.Equal(t, pkg.ModelPkg, p.Type) assert.Equal(t, pkg.ModelPkg, p.Type)
// Verify metadata is attached // Verify metadata is attached
metadata, ok := p.Metadata.(pkg.GGUFFileMetadata) metadata, ok := p.Metadata.(pkg.GGUFFileHeader)
require.True(t, ok, "metadata should be GGUFFileMetadata") require.True(t, ok, "metadata should be GGUFFileHeader")
assert.Equal(t, *tt.metadata, metadata) assert.Equal(t, *tt.metadata, metadata)
if tt.checkFunc != nil { if tt.checkFunc != nil {

View File

@ -59,7 +59,7 @@ func parseGGUFModel(_ context.Context, _ file.Resolver, _ *generic.Environment,
metadata := ggufFile.Metadata() metadata := ggufFile.Metadata()
// Convert to syft metadata structure // Convert to syft metadata structure
syftMetadata := &pkg.GGUFFileMetadata{ syftMetadata := &pkg.GGUFFileHeader{
ModelFormat: "gguf", ModelFormat: "gguf",
ModelName: metadata.Name, ModelName: metadata.Name,
ModelVersion: extractVersion(ggufFile.Header.MetadataKV), ModelVersion: extractVersion(ggufFile.Header.MetadataKV),

View File

@ -1,9 +1,9 @@
package pkg package pkg
// GGUFFileMetadata represents metadata extracted from a GGUF (GPT-Generated Unified Format) model file. // GGUFFileHeader represents metadata extracted from a GGUF (GPT-Generated Unified Format) model file.
// GGUF is a binary file format used for storing model weights for the GGML library, designed for fast // GGUF is a binary file format used for storing model weights for the GGML library, designed for fast
// loading and saving of models, particularly quantized large language models. // loading and saving of models, particularly quantized large language models.
type GGUFFileMetadata struct { type GGUFFileHeader struct {
// ModelFormat is always "gguf" // ModelFormat is always "gguf"
ModelFormat string `json:"modelFormat" cyclonedx:"modelFormat"` ModelFormat string `json:"modelFormat" cyclonedx:"modelFormat"`