Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 4 additions & 27 deletions pkg/inference/models/adapter.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package models

import (
"encoding/json"
"fmt"

"github.com/docker/model-runner/pkg/distribution/types"
Expand All @@ -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)
Expand All @@ -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
}
30 changes: 1 addition & 29 deletions pkg/inference/models/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down