-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webui): add partials, show backends associated to models (#1922)
* feat(webui): add partials, show backends associated to models * fix(auth): put assistant and backend under auth
- Loading branch information
Showing
5 changed files
with
155 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package http | ||
|
||
import ( | ||
"embed" | ||
"fmt" | ||
"html/template" | ||
"net/http" | ||
|
||
"github.com/Masterminds/sprig/v3" | ||
"github.com/go-skynet/LocalAI/core/config" | ||
"github.com/go-skynet/LocalAI/core/schema" | ||
"github.com/go-skynet/LocalAI/internal" | ||
"github.com/go-skynet/LocalAI/pkg/model" | ||
"github.com/gofiber/fiber/v2" | ||
fiberhtml "github.com/gofiber/template/html/v2" | ||
"github.com/russross/blackfriday" | ||
) | ||
|
||
//go:embed views/* | ||
var viewsfs embed.FS | ||
|
||
func notFoundHandler(c *fiber.Ctx) error { | ||
// Check if the request accepts JSON | ||
if string(c.Context().Request.Header.ContentType()) == "application/json" || len(c.Accepts("html")) == 0 { | ||
// The client expects a JSON response | ||
c.Status(fiber.StatusNotFound).JSON(schema.ErrorResponse{ | ||
Error: &schema.APIError{Message: "Resource not found", Code: fiber.StatusNotFound}, | ||
}) | ||
} else { | ||
// The client expects an HTML response | ||
c.Status(fiber.StatusNotFound).Render("views/404", fiber.Map{}) | ||
} | ||
return nil | ||
} | ||
|
||
func welcomeRoute( | ||
app *fiber.App, | ||
cl *config.BackendConfigLoader, | ||
ml *model.ModelLoader, | ||
appConfig *config.ApplicationConfig, | ||
auth func(*fiber.Ctx) error, | ||
) { | ||
if appConfig.DisableWelcomePage { | ||
return | ||
} | ||
|
||
models, _ := ml.ListModels() | ||
backendConfigs := cl.GetAllBackendConfigs() | ||
|
||
app.Get("/", auth, func(c *fiber.Ctx) error { | ||
summary := fiber.Map{ | ||
"Title": "LocalAI API - " + internal.PrintableVersion(), | ||
"Version": internal.PrintableVersion(), | ||
"Models": models, | ||
"ModelsConfig": backendConfigs, | ||
"ApplicationConfig": appConfig, | ||
} | ||
|
||
if string(c.Context().Request.Header.ContentType()) == "application/json" || len(c.Accepts("html")) == 0 { | ||
// The client expects a JSON response | ||
return c.Status(fiber.StatusOK).JSON(summary) | ||
} else { | ||
// Render index | ||
return c.Render("views/index", summary) | ||
} | ||
}) | ||
|
||
} | ||
|
||
func renderEngine() *fiberhtml.Engine { | ||
engine := fiberhtml.NewFileSystem(http.FS(viewsfs), ".html") | ||
engine.AddFuncMap(sprig.FuncMap()) | ||
engine.AddFunc("MDToHTML", markDowner) | ||
return engine | ||
} | ||
|
||
func markDowner(args ...interface{}) template.HTML { | ||
s := blackfriday.MarkdownCommon([]byte(fmt.Sprintf("%s", args...))) | ||
return template.HTML(s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,50 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>{{.Title}}</title> | ||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&family=Roboto:wght@400;500&display=swap" rel="stylesheet"> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet"> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css"> | ||
<style> | ||
body { | ||
font-family: 'Inter', sans-serif; | ||
} | ||
</style> | ||
</head> | ||
<body class="bg-black text-white"> | ||
{{template "views/partials/head" .}} | ||
|
||
<body class="bg-gray-900 text-gray-200"> | ||
<div class="flex flex-col min-h-screen"> | ||
|
||
{{template "views/partials/navbar" .}} | ||
|
||
<div class="container mx-auto px-4 flex-grow"> | ||
<div class="header text-center py-12"> | ||
<h1 class="text-5xl font-bold">Welcome to your LocalAI instance!</h1> | ||
<h1 class="text-5xl font-bold text-gray-100">Welcome to <i>your</i> LocalAI instance!</h1> | ||
<div class="mt-6"> | ||
<!-- <a href="/" aria-label="HomePage" alt="HomePage"> | ||
<img class="mx-auto w-1/4 h-auto" src="https://github.com/go-skynet/LocalAI/assets/2420543/0966aa2a-166e-4f99-a3e5-6c915fc997dd" alt="LocalAI Logo"> | ||
</a> | ||
--> | ||
<!-- Logo can be uncommented and updated with a valid URL --> | ||
</div> | ||
<p class="mt-4 text-lg">The FOSS alternative to OpenAI, Claude, ...</p> | ||
<a href="https://localai.io" target="_blank" class="mt-4 inline-block bg-blue-500 text-white py-2 px-4 rounded transition duration-300 ease-in-out hover:bg-blue-700"><i class="fas fa-book-reader pr-2"></i>Documentation</a> | ||
<a href="https://localai.io" target="_blank" class="mt-4 inline-block bg-blue-500 text-white py-2 px-4 rounded-lg shadow transition duration-300 ease-in-out hover:bg-blue-700 hover:shadow-lg"> | ||
<i class="fas fa-book-reader pr-2"></i>Documentation | ||
</a> | ||
</div> | ||
|
||
<div class="models mt-12"> | ||
<h2 class="text-center text-3xl font-semibold">Installed models</h2> | ||
<h2 class="text-center text-3xl font-semibold text-gray-100">Installed models</h2> | ||
<p class="text-center mt-4 text-xl">We have {{len .ModelsConfig}} pre-loaded models available.</p> | ||
<ul class="mt-8"> | ||
<ul class="mt-8 space-y-4"> | ||
{{ range .ModelsConfig }} | ||
<li class="border border-gray-600 p-4 rounded mb-4"> | ||
<p class="font-bold"><i class="fas fa-brain pr-2"></i>{{.Name}}</p> | ||
{{ if .Usage }} | ||
<div class="text-sm bg-gray-800 text-gray-300 p-2 rounded mt-2"><code>{{.Usage}}</code></div> | ||
{{ end }} | ||
{{ if .Description }} | ||
<p class="mt-2 text-gray-400">{{.Description}}</p> | ||
{{ end }} | ||
<li class="bg-gray-800 border border-gray-700 p-4 rounded-lg"> | ||
<div class="flex justify-between items-center"> | ||
<p class="font-bold text-white flex items-center"><i class="fas fa-brain pr-2"></i>{{.Name}}</p> | ||
{{ if .Backend }} | ||
<!-- Badge for Backend --> | ||
<span class="inline-block bg-blue-500 text-white py-1 px-3 rounded-full text-xs"> | ||
{{.Backend}} | ||
</span> | ||
{{ else }} | ||
<span class="inline-block bg-yellow-500 text-white py-1 px-3 rounded-full text-xs"> | ||
auto | ||
</span> | ||
{{ end }} | ||
</div> | ||
<!-- Additional details can go here --> | ||
</li> | ||
{{ end }} | ||
</ul> | ||
</div> | ||
</div> | ||
|
||
{{template "views/partials/footer" .}} | ||
</div> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.