MCPcopy
hub / github.com/sammcj/gollama / unloadModel

Function unloadModel

operations.go:143–182  ·  view source on GitHub ↗
(client *api.Client, modelName string)

Source from the content-addressed store, hash-verified

141}
142
143func unloadModel(client *api.Client, modelName string) (string, error) {
144 if client == nil {
145 return "", fmt.Errorf("invalid API client: client is nil")
146 }
147
148 ctx := context.Background()
149
150 if strings.Contains(modelName, "embed") {
151 req := &api.EmbeddingRequest{
152 Model: modelName,
153 KeepAlive: &api.Duration{Duration: 0},
154 }
155 logging.DebugLogger.Printf("Attempting to unload embedding model: %s\n", modelName)
156
157 _, err := client.Embeddings(ctx, req)
158 if err != nil {
159 logging.ErrorLogger.Printf("Failed to unload embedding model: %v\n", err)
160 return modelName, err
161 }
162 } else {
163 req := &api.GenerateRequest{
164 Model: modelName,
165 Prompt: "",
166 KeepAlive: &api.Duration{Duration: 0},
167 }
168 logging.DebugLogger.Printf("Attempting to unload model: %s\n", modelName)
169
170 response := func(resp api.GenerateResponse) error {
171 logging.DebugLogger.Printf("done")
172 return nil
173 }
174 err := client.Generate(ctx, req, response)
175 if err != nil {
176 logging.ErrorLogger.Printf("Failed to unload model: %v\n", err)
177 return "", err
178 }
179 }
180
181 return modelName, nil
182}
183
184func getModelParams(modelName string, client *api.Client) (map[string]string, string, error) {
185 logging.InfoLogger.Printf("Getting parameters for model: %s\n", modelName)

Callers 2

handleUnloadModelsKeyMethod · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected