Skip to content

Commit f6c02b6

Browse files
committed
WIP
Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent e884686 commit f6c02b6

File tree

6 files changed

+764
-0
lines changed

6 files changed

+764
-0
lines changed

core/http/app.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88

99
"github.com/dave-gray101/v2keyauth"
10+
"github.com/gofiber/websocket/v2"
1011
"github.com/mudler/LocalAI/pkg/utils"
1112

1213
"github.com/mudler/LocalAI/core/http/endpoints/localai"
@@ -180,6 +181,16 @@ func App(cl *config.BackendConfigLoader, ml *model.ModelLoader, appConfig *confi
180181
Browse: true,
181182
}))
182183

184+
app.Use("/ws", func(c *fiber.Ctx) error {
185+
// IsWebSocketUpgrade returns true if the client
186+
// requested upgrade to the WebSocket protocol.
187+
if websocket.IsWebSocketUpgrade(c) {
188+
c.Locals("allowed", true)
189+
return c.Next()
190+
}
191+
return fiber.ErrUpgradeRequired
192+
})
193+
183194
// Define a custom 404 handler
184195
// Note: keep this at the bottom!
185196
app.Use(notFoundHandler)

core/http/ctx/fiber.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ func ModelFromContext(ctx *fiber.Ctx, cl *config.BackendConfigLoader, loader *mo
1919
if ctx.Params("model") != "" {
2020
modelInput = ctx.Params("model")
2121
}
22+
2223
if ctx.Query("model") != "" {
2324
modelInput = ctx.Query("model")
2425
}
26+
2527
// Set model from bearer token, if available
2628
bearer := strings.TrimLeft(ctx.Get("authorization"), "Bear ") // Reduced duplicate characters of Bearer
2729
bearerExists := bearer != "" && loader.ExistsInModelPath(bearer)

0 commit comments

Comments
 (0)