package catalog import ( "fmt" "slices" "gitea.mynodes.xyz/ilker/llmgw/internal/agent/weights" ) // PickleSources are the sources of a model's weights and adapters that are // in a pickle format, which run code as they are loaded (weights.Pickled). func (m Model) PickleSources() []string { var out []string add := func(s string) { if s != "" && weights.Pickled(s) && !slices.Contains(out, s) { out = append(out, s) } } add(m.Source) for _, p := range m.Profiles { add(p.Source) } for _, a := range m.Adapters { add(a.Source) } return out } // CheckPickle refuses a model whose weights are in a pickle format, unless // it says allow_pickle. Asked when a model is added or its sources change, // not when the catalog is built: a model already running is refused by its // node, with the same words, rather than dropped from the catalog. // Sources in except were there before and are not asked about again. func (m Model) CheckPickle(except ...string) error { if m.AllowPickle { return nil } for _, s := range m.PickleSources() { if slices.Contains(except, s) { continue } return fmt.Errorf("model %q: %s is in a pickle format, which runs code when it is loaded; "+ "use the model's safetensors or GGUF, or set allow_pickle: true if it was checked and has no other form", m.Name, s) } return nil }