Skip to content

Commit 5b0583f

Browse files
committed
fix(schema): use v1.Model instead of v1.ModelConfig in validateConfig
Fixes pre validation always succeeding due to wrong unmarshal target. Also adds positive test cases to TestConfig. Signed-off-by: pradhyum6144 <pradhyum314@gmail.com>
1 parent f02be87 commit 5b0583f

2 files changed

Lines changed: 91 additions & 2 deletions

File tree

schema/config_test.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,95 @@ func TestConfig(t *testing.T) {
580580
`,
581581
fail: true,
582582
},
583+
// valid: minimal config with required fields only
584+
{
585+
config: `
586+
{
587+
"descriptor": {
588+
"name": "xyz-3-8B-Instruct"
589+
},
590+
"config": {
591+
"paramSize": "8b"
592+
},
593+
"modelfs": {
594+
"type": "layers",
595+
"diffIds": [
596+
"sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
597+
]
598+
}
599+
}
600+
`,
601+
fail: false,
602+
},
603+
// valid: full config with all optional fields populated
604+
{
605+
config: `
606+
{
607+
"descriptor": {
608+
"createdAt": "2025-01-01T00:00:00Z",
609+
"authors": ["xyz@xyz.com"],
610+
"vendor": "XYZ Corp.",
611+
"family": "xyz3",
612+
"name": "xyz-3-8B-Instruct",
613+
"version": "3.1",
614+
"title": "XYZ 3 8B Instruct",
615+
"description": "xyz is a large language model.",
616+
"docURL": "https://www.xyz.com/get-started/",
617+
"sourceURL": "https://github.com/xyz/xyz3",
618+
"datasetsURL": ["https://www.xyz.com/datasets/"],
619+
"revision": "1234567890",
620+
"licenses": ["Apache-2.0"]
621+
},
622+
"config": {
623+
"architecture": "transformer",
624+
"format": "safetensors",
625+
"paramSize": "8b",
626+
"precision": "float16",
627+
"quantization": "gptq",
628+
"capabilities": {
629+
"inputTypes": ["text"],
630+
"outputTypes": ["text"],
631+
"knowledgeCutoff": "2024-05-21T00:00:00Z",
632+
"reasoning": true,
633+
"toolUsage": false
634+
}
635+
},
636+
"modelfs": {
637+
"type": "layers",
638+
"diffIds": [
639+
"sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
640+
"sha256:abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890"
641+
]
642+
}
643+
}
644+
`,
645+
fail: false,
646+
},
647+
// valid: multimodal model with image input and output
648+
{
649+
config: `
650+
{
651+
"descriptor": {
652+
"name": "xyz-vl-7B"
653+
},
654+
"config": {
655+
"architecture": "transformer",
656+
"paramSize": "7b",
657+
"capabilities": {
658+
"inputTypes": ["text", "image"],
659+
"outputTypes": ["text", "image", "embedding"]
660+
}
661+
},
662+
"modelfs": {
663+
"type": "layers",
664+
"diffIds": [
665+
"sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
666+
]
667+
}
668+
}
669+
`,
670+
fail: false,
671+
},
583672
} {
584673
r := strings.NewReader(tt.config)
585674
err := schema.ValidatorMediaTypeModelConfig.Validate(r)

schema/validator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ var validateByMediaType = map[Validator]validateFunc{
114114
}
115115

116116
func validateConfig(buf []byte) error {
117-
mc := v1.ModelConfig{}
117+
model := v1.Model{}
118118

119-
err := json.Unmarshal(buf, &mc)
119+
err := json.Unmarshal(buf, &model)
120120
if err != nil {
121121
return fmt.Errorf("config format mismatch: %w", err)
122122
}

0 commit comments

Comments
 (0)