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

Function RegisterUIAPIRoutes

core/http/routes/ui_api.go:155–1641  ·  view source on GitHub ↗

RegisterUIAPIRoutes registers JSON API routes for the web UI

(app *echo.Echo, cl *config.ModelConfigLoader, ml *model.ModelLoader, appConfig *config.ApplicationConfig, galleryService *galleryop.GalleryService, opcache *galleryop.OpCache, applicationInstance *application.Application, adminMiddleware echo.MiddlewareFunc)

Source from the content-addressed store, hash-verified

153
154// RegisterUIAPIRoutes registers JSON API routes for the web UI
155func RegisterUIAPIRoutes(app *echo.Echo, cl *config.ModelConfigLoader, ml *model.ModelLoader, appConfig *config.ApplicationConfig, galleryService *galleryop.GalleryService, opcache *galleryop.OpCache, applicationInstance *application.Application, adminMiddleware echo.MiddlewareFunc) {
156
157 // Operations API - Get all current operations (models + backends)
158 app.GET("/api/operations", func(c echo.Context) error {
159 processingData, taskTypes := opcache.GetStatus()
160
161 operations := []map[string]any{}
162 for galleryID, jobID := range processingData {
163 taskType := "installation"
164 if tt, ok := taskTypes[galleryID]; ok {
165 taskType = tt
166 }
167
168 status := galleryService.GetStatus(jobID)
169 progress := 0
170 isDeletion := false
171 isQueued := false
172 isCancelled := false
173 isCancellable := false
174 message := ""
175
176 if status != nil {
177 // Skip successfully completed operations
178 if status.Processed && !status.Cancelled && status.Error == nil {
179 continue
180 }
181 // Skip cancelled operations that are processed (they're done, no need to show)
182 if status.Processed && status.Cancelled {
183 continue
184 }
185
186 progress = int(status.Progress)
187 isDeletion = status.Deletion
188 isCancelled = status.Cancelled
189 isCancellable = status.Cancellable
190 message = status.Message
191 if isDeletion {
192 taskType = "deletion"
193 }
194 if isCancelled {
195 taskType = "cancelled"
196 }
197 } else {
198 // Job is queued but hasn't started
199 isQueued = true
200 isCancellable = true
201 message = "Operation queued"
202 }
203
204 // Determine if it's a model or backend
205 // First check if it was explicitly marked as a backend operation
206 isBackend := opcache.IsBackendOp(galleryID)
207 // If not explicitly marked, check if it matches a known backend from the gallery
208 if !isBackend {
209 backends, _ := gallery.AvailableBackends(appConfig.BackendGalleries, appConfig.SystemState)
210 for _, b := range backends {
211 backendID := fmt.Sprintf("%s@%s", b.Gallery.Name, b.Name)
212 if backendID == galleryID || b.Name == galleryID {

Callers 3

APIFunction · 0.92

Calls 15

AvailableBackendsFunction · 0.92
ParseNodeScopedKeyFunction · 0.92
ListModelsFunction · 0.92
GetSystemRAMInfoFunction · 0.92
GetUserFunction · 0.92
GetCachedUserPermissionsFunction · 0.92
FindGalleryElementFunction · 0.92
GetGalleryConfigFromURLFunction · 0.92

Tested by

no test coverage detected