Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
  • Loading branch information
mudler committed Oct 13, 2024
1 parent f659304 commit 2660e07
Show file tree
Hide file tree
Showing 6 changed files with 765 additions and 1 deletion.
13 changes: 12 additions & 1 deletion core/http/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"

"github.com/dave-gray101/v2keyauth"
"github.com/gofiber/websocket/v2"
"github.com/mudler/LocalAI/pkg/utils"

"github.com/mudler/LocalAI/core/http/endpoints/localai"
Expand Down Expand Up @@ -121,7 +122,7 @@ func App(cl *config.BackendConfigLoader, ml *model.ModelLoader, appConfig *confi
})
}

// Health Checks should always be exempt from auth, so register these first
// Health Checks should always be exempt from auth, so register these first
routes.HealthRoutes(app)

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

app.Use("/ws", func(c *fiber.Ctx) error {
// IsWebSocketUpgrade returns true if the client
// requested upgrade to the WebSocket protocol.
if websocket.IsWebSocketUpgrade(c) {
c.Locals("allowed", true)
return c.Next()
}
return fiber.ErrUpgradeRequired
})

// Define a custom 404 handler
// Note: keep this at the bottom!
app.Use(notFoundHandler)
Expand Down
2 changes: 2 additions & 0 deletions core/http/ctx/fiber.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ func ModelFromContext(ctx *fiber.Ctx, cl *config.BackendConfigLoader, loader *mo
if ctx.Params("model") != "" {
modelInput = ctx.Params("model")
}

if ctx.Query("model") != "" {
modelInput = ctx.Query("model")
}

// Set model from bearer token, if available
bearer := strings.TrimLeft(ctx.Get("authorization"), "Bear ") // Reduced duplicate characters of Bearer
bearerExists := bearer != "" && loader.ExistsInModelPath(bearer)
Expand Down
Loading

0 comments on commit 2660e07

Please sign in to comment.