Skip to content

Commit 5435a07

Browse files
committed
WIP
Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent 04f284d commit 5435a07

File tree

7 files changed

+769
-1
lines changed

7 files changed

+769
-1
lines changed

core/http/app.go

+12-1
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"
@@ -121,7 +122,7 @@ func App(cl *config.BackendConfigLoader, ml *model.ModelLoader, appConfig *confi
121122
})
122123
}
123124

124-
// Health Checks should always be exempt from auth, so register these first
125+
// Health Checks should always be exempt from auth, so register these first
125126
routes.HealthRoutes(app)
126127

127128
kaConfig, err := middleware.GetKeyAuthConfig(appConfig)
@@ -178,6 +179,16 @@ func App(cl *config.BackendConfigLoader, ml *model.ModelLoader, appConfig *confi
178179
Browse: true,
179180
}))
180181

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

core/http/ctx/fiber.go

+2
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)