MCPcopy
hub / github.com/mudler/LocalAI / InstallModelFromGallery

Function InstallModelFromGallery

core/gallery/models.go:75–159  ·  view source on GitHub ↗

Installs a model from the gallery

(
	ctx context.Context,
	modelGalleries, backendGalleries []lconfig.Gallery,
	systemState *system.SystemState,
	modelLoader *model.ModelLoader,
	name string, req GalleryModel, downloadStatus func(string, string, string, float64), enforceScan, automaticallyInstallBackend, requireBackendIntegrity bool)

Source from the content-addressed store, hash-verified

73
74// Installs a model from the gallery
75func InstallModelFromGallery(
76 ctx context.Context,
77 modelGalleries, backendGalleries []lconfig.Gallery,
78 systemState *system.SystemState,
79 modelLoader *model.ModelLoader,
80 name string, req GalleryModel, downloadStatus func(string, string, string, float64), enforceScan, automaticallyInstallBackend, requireBackendIntegrity bool) error {
81
82 applyModel := func(model *GalleryModel) error {
83 name = strings.ReplaceAll(name, string(os.PathSeparator), "__")
84
85 var config ModelConfig
86
87 if len(model.URL) > 0 {
88 var err error
89 config, err = GetGalleryConfigFromURLWithContext[ModelConfig](ctx, model.URL, systemState.Model.ModelsPath)
90 if err != nil {
91 return err
92 }
93 config.Description = model.Description
94 config.License = model.License
95 } else if len(model.ConfigFile) > 0 {
96 // TODO: is this worse than using the override method with a blank cfg yaml?
97 reYamlConfig, err := yaml.Marshal(model.ConfigFile)
98 if err != nil {
99 return err
100 }
101 config = ModelConfig{
102 ConfigFile: string(reYamlConfig),
103 Description: model.Description,
104 License: model.License,
105 URLs: model.URLs,
106 Name: model.Name,
107 Files: make([]File, 0), // Real values get added below, must be blank
108 // Prompt Template Skipped for now - I expect in this mode that they will be delivered as files.
109 }
110 } else {
111 return fmt.Errorf("invalid gallery model %+v", model)
112 }
113
114 installName := model.Name
115 if req.Name != "" {
116 installName = req.Name
117 }
118
119 // Copy the model configuration from the request schema
120 config.URLs = append(config.URLs, model.URLs...)
121 config.Icon = model.Icon
122 config.Files = append(config.Files, req.AdditionalFiles...)
123 config.Files = append(config.Files, model.AdditionalFiles...)
124
125 // TODO model.Overrides could be merged with user overrides (not defined yet)
126 if req.Overrides != nil {
127 if err := mergo.Merge(&model.Overrides, req.Overrides, mergo.WithOverride); err != nil {
128 return err
129 }
130 }
131
132 installedModel, err := InstallModel(ctx, systemState, installName, &config, model.Overrides, downloadStatus, enforceScan)

Callers 6

installModelFunction · 0.92
ModelInferenceFunction · 0.92
processRequestsFunction · 0.92
InstallModelMethod · 0.92
prefetch.goFile · 0.92
models_test.goFile · 0.85

Calls 4

InstallModelFunction · 0.85
AvailableGalleryModelsFunction · 0.85
FindGalleryElementFunction · 0.85

Tested by

no test coverage detected