Skip to content

Commit dde0353

Browse files
committed
chore(api): add path to expose collection raw files
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent 8e8b7df commit dde0353

5 files changed

Lines changed: 31 additions & 6 deletions

File tree

core/http/endpoints/localai/agent_collections.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,26 @@ func RemoveCollectionSourceEndpoint(app *application.Application) echo.HandlerFu
203203
}
204204
}
205205

206+
// GetCollectionEntryRawFileEndpoint serves the original uploaded binary file.
207+
func GetCollectionEntryRawFileEndpoint(app *application.Application) echo.HandlerFunc {
208+
return func(c echo.Context) error {
209+
svc := app.AgentPoolService()
210+
entryParam := c.Param("*")
211+
entry, err := url.PathUnescape(entryParam)
212+
if err != nil {
213+
entry = entryParam
214+
}
215+
fpath, err := svc.GetCollectionEntryFilePath(c.Param("name"), entry)
216+
if err != nil {
217+
if strings.Contains(err.Error(), "not found") {
218+
return c.JSON(http.StatusNotFound, map[string]string{"error": err.Error()})
219+
}
220+
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
221+
}
222+
return c.File(fpath)
223+
}
224+
}
225+
206226
func ListCollectionSourcesEndpoint(app *application.Application) echo.HandlerFunc {
207227
return func(c echo.Context) error {
208228
svc := app.AgentPoolService()

core/http/routes/agents.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func RegisterAgentPoolRoutes(e *echo.Echo, app *application.Application) {
8080
g.POST("/collections/:name/upload", localai.UploadToCollectionEndpoint(app))
8181
g.GET("/collections/:name/entries", localai.ListCollectionEntriesEndpoint(app))
8282
g.GET("/collections/:name/entries/*", localai.GetCollectionEntryContentEndpoint(app))
83+
g.GET("/collections/:name/entries-raw/*", localai.GetCollectionEntryRawFileEndpoint(app))
8384
g.POST("/collections/:name/search", localai.SearchCollectionEndpoint(app))
8485
g.POST("/collections/:name/reset", localai.ResetCollectionEndpoint(app))
8586
g.DELETE("/collections/:name/entry/delete", localai.DeleteCollectionEntryEndpoint(app))

core/services/agent_pool.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,10 @@ func (s *AgentPoolService) CollectionEntryExists(collection, entry string) bool
10531053
return s.collectionsBackend.EntryExists(collection, entry)
10541054
}
10551055

1056+
func (s *AgentPoolService) GetCollectionEntryFilePath(collection, entry string) (string, error) {
1057+
return s.collectionsBackend.GetEntryFilePath(collection, entry)
1058+
}
1059+
10561060
// --- Actions ---
10571061

10581062
// ListAvailableActions returns the list of all available action type names.

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ require (
128128
github.com/kevinburke/ssh_config v1.2.0 // indirect
129129
github.com/labstack/gommon v0.4.2 // indirect
130130
github.com/mschoch/smat v0.2.0 // indirect
131-
github.com/mudler/LocalAGI v0.0.0-20260311165347-2d2da7df95e1
132-
github.com/mudler/localrecall v0.5.7-0.20260314101322-43426c06c67a // indirect
131+
github.com/mudler/LocalAGI v0.0.0-20260314222828-e38f13ab8cec
132+
github.com/mudler/localrecall v0.5.9-0.20260314221856-96d63875cc47 // indirect
133133
github.com/mudler/skillserver v0.0.5-0.20260221145827-0639a82c8f49
134134
github.com/olekukonko/tablewriter v0.0.5 // indirect
135135
github.com/oxffaa/gopher-parse-sitemap v0.0.0-20191021113419-005d2eb1def4 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,8 @@ github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
654654
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
655655
github.com/mschoch/smat v0.2.0 h1:8imxQsjDm8yFEAVBe7azKmKSgzSkZXDuKkSq9374khM=
656656
github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOlotKw=
657-
github.com/mudler/LocalAGI v0.0.0-20260311165347-2d2da7df95e1 h1:EvG0FDIDGciO7laxgSTUuFjcpWEwhfUM9zfl/T3TVF0=
658-
github.com/mudler/LocalAGI v0.0.0-20260311165347-2d2da7df95e1/go.mod h1:6LQyB+kxvh3LGrv4tXk9FVvBvaFRJ14vn09+4xWwmI8=
657+
github.com/mudler/LocalAGI v0.0.0-20260314222828-e38f13ab8cec h1:Y6JYhfJidFktfmQC00SwHtQVh0lr0O52qihgTKddSNU=
658+
github.com/mudler/LocalAGI v0.0.0-20260314222828-e38f13ab8cec/go.mod h1:yf+IlZzQCGgKPGFn5yclzA2Dxxhy75K3YDubkjCub04=
659659
github.com/mudler/cogito v0.9.5-0.20260313170202-42271c7e1a6b h1:Hs2Byjnukgkwm5Vw7z5aSZEjznPHaxjr2vLc5Uu1fHQ=
660660
github.com/mudler/cogito v0.9.5-0.20260313170202-42271c7e1a6b/go.mod h1:6sfja3lcu2nWRzEc0wwqGNu/eCG3EWgij+8s7xyUeQ4=
661661
github.com/mudler/edgevpn v0.31.1 h1:7qegiDWd0kAg6ljhNHxqvp8hbo/6BbzSdbb7/2WZfiY=
@@ -664,8 +664,8 @@ github.com/mudler/go-piper v0.0.0-20241023091659-2494246fd9fc h1:RxwneJl1VgvikiX
664664
github.com/mudler/go-piper v0.0.0-20241023091659-2494246fd9fc/go.mod h1:O7SwdSWMilAWhBZMK9N9Y/oBDyMMzshE3ju8Xkexwig=
665665
github.com/mudler/go-processmanager v0.1.0 h1:fcSKgF9U/a1Z7KofAFeZnke5YseadCI5GqL9oT0LS3E=
666666
github.com/mudler/go-processmanager v0.1.0/go.mod h1:h6kmHUZeafr+k5hRYpGLMzJFH4hItHffgpRo2QIkP+o=
667-
github.com/mudler/localrecall v0.5.7-0.20260314101322-43426c06c67a h1:Ah71V/UgF78i0I7yxu0EUweum6p3KwErz9qVFms9/VI=
668-
github.com/mudler/localrecall v0.5.7-0.20260314101322-43426c06c67a/go.mod h1:TZVXQI840MqjDtilBLc7kfmnctK4oNf1IR+cE68zno8=
667+
github.com/mudler/localrecall v0.5.9-0.20260314221856-96d63875cc47 h1:fHIkLJgfcYDF4bhwVZdfFcQB2HVw93ClOQSKRci8qQs=
668+
github.com/mudler/localrecall v0.5.9-0.20260314221856-96d63875cc47/go.mod h1:TZVXQI840MqjDtilBLc7kfmnctK4oNf1IR+cE68zno8=
669669
github.com/mudler/memory v0.0.0-20251216220809-d1256471a6c2 h1:+WHsL/j6EWOMUiMVIOJNKOwSKiQt/qDPc9fePCf87fA=
670670
github.com/mudler/memory v0.0.0-20251216220809-d1256471a6c2/go.mod h1:EA8Ashhd56o32qN7ouPKFSRUs/Z+LrRCF4v6R2Oarm8=
671671
github.com/mudler/skillserver v0.0.5-0.20260221145827-0639a82c8f49 h1:dAF1ALXqqapRZo80x56BIBBcPrPbRNerbd66rdyO8J4=

0 commit comments

Comments
 (0)