diff --git a/pkg/inference/models/adapter.go b/pkg/inference/models/adapter.go index 2ca6d7fe..a686199f 100644 --- a/pkg/inference/models/adapter.go +++ b/pkg/inference/models/adapter.go @@ -1,7 +1,6 @@ package models import ( - "encoding/json" "fmt" "github.com/docker/model-runner/pkg/distribution/types" @@ -28,23 +27,12 @@ func ToModel(m types.Model) (*Model, error) { created = desc.Created.Unix() } - model := &Model{ + return &Model{ ID: id, Tags: m.Tags(), Created: created, Config: cfg, - } - - // Marshal the config to populate RawConfig - if cfg != nil { - configData, err := json.Marshal(cfg) - if err != nil { - return nil, fmt.Errorf("marshal config: %w", err) - } - model.RawConfig = configData - } - - return model, nil + }, nil } // ToModelFromArtifact converts a types.ModelArtifact (typically from remote registry) @@ -70,21 +58,10 @@ func ToModelFromArtifact(artifact types.ModelArtifact) (*Model, error) { created = desc.Created.Unix() } - model := &Model{ + return &Model{ ID: id, Tags: nil, // Remote models don't have local tags Created: created, Config: cfg, - } - - // Marshal the config to populate RawConfig - if cfg != nil { - configData, err := json.Marshal(cfg) - if err != nil { - return nil, fmt.Errorf("marshal config: %w", err) - } - model.RawConfig = configData - } - - return model, nil + }, nil } diff --git a/pkg/inference/models/api.go b/pkg/inference/models/api.go index e963603c..ffb724c1 100644 --- a/pkg/inference/models/api.go +++ b/pkg/inference/models/api.go @@ -112,35 +112,7 @@ type Model struct { Created int64 `json:"created"` // Config describes the model. Can be either Docker format (*types.Config) // or ModelPack format (*modelpack.Model). - Config types.ModelConfig `json:"-"` - // RawConfig is used for JSON marshaling/unmarshaling - RawConfig json.RawMessage `json:"config"` -} - -// MarshalJSON implements custom marshaling for Model -func (m Model) MarshalJSON() ([]byte, error) { - // Define a temporary struct to avoid recursion - type Alias Model - aux := struct { - *Alias - RawConfig json.RawMessage `json:"config"` - }{ - Alias: (*Alias)(&m), - } - - // Marshal the config separately - if m.Config != nil { - configData, err := json.Marshal(m.Config) - if err != nil { - return nil, err - } - aux.RawConfig = configData - } else { - // If Config is nil, use the RawConfig if available - aux.RawConfig = m.RawConfig - } - - return json.Marshal(aux) + Config types.ModelConfig `json:"config"` } // UnmarshalJSON implements custom JSON unmarshaling for Model.