From ffd7ff246e061dbd51adc19b2b138dbfbc6fa3d0 Mon Sep 17 00:00:00 2001 From: LordMathis Date: Sat, 26 Jul 2025 12:25:51 +0200 Subject: [PATCH] Embed webui --- .gitignore | 1 + cmd/server/main.go | 2 +- pkg/routes.go | 18 +++++++++++++----- webui/webui.go | 23 +++++++++++++++++++++++ 4 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 webui/webui.go diff --git a/.gitignore b/.gitignore index cc825a3..160028f 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ go.work.sum # .vscode/ node_modules/ +dist/ \ No newline at end of file diff --git a/cmd/server/main.go b/cmd/server/main.go index 6d85de6..11d3837 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -21,7 +21,7 @@ func main() { fmt.Println("Using default configuration.") } - // Crate the log directory if it doesn't exist + // Create the log directory if it doesn't exist err = os.MkdirAll(config.Instances.LogDirectory, 0755) if err != nil { fmt.Printf("Error creating log directory: %v\n", err) diff --git a/pkg/routes.go b/pkg/routes.go index a7689b9..b6bcda9 100644 --- a/pkg/routes.go +++ b/pkg/routes.go @@ -1,11 +1,14 @@ package llamactl import ( + "fmt" + "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" httpSwagger "github.com/swaggo/http-swagger" _ "llamactl/docs" + "llamactl/webui" ) func SetupRouter(handler *Handler) *chi.Mux { @@ -49,11 +52,16 @@ func SetupRouter(handler *Handler) *chi.Mux { // OpenAI-compatible endpoints (model name in request body determines routing) r.Post("/v1/", handler.OpenAIProxy()) // Proxy to OpenAI-compatible endpoints based on instance name in request body - // r.Post("/v1/completions", handler.OpenAICompletions()) // Route based on model name in request - // r.Post("/v1/chat/completions", handler.OpenAIChatCompletions()) // Route based on model name in request - // r.Post("/v1/embeddings", handler.OpenAIEmbeddings()) // Route based on model name in request (if supported) - // r.Post("/v1/rerank", handler.OpenAIRerank()) // Route based on model name in request (if supported) - // r.Post("/v1/reranking", handler.OpenAIReranking()) // Route based on model name in request (if supported) + // r.Post("/v1/completions", handler.OpenAICompletions()) + // r.Post("/v1/chat/completions", handler.OpenAIChatCompletions()) + // r.Post("/v1/embeddings", handler.OpenAIEmbeddings()) + // r.Post("/v1/rerank", handler.OpenAIRerank()) + // r.Post("/v1/reranking", handler.OpenAIReranking()) + + // Serve WebUI files + if err := webui.SetupWebUI(r); err != nil { + fmt.Printf("Failed to set up WebUI: %v\n", err) + } return r } diff --git a/webui/webui.go b/webui/webui.go new file mode 100644 index 0000000..9be1828 --- /dev/null +++ b/webui/webui.go @@ -0,0 +1,23 @@ +package webui + +import ( + "embed" + "io/fs" + "net/http" + + "github.com/go-chi/chi/v5" +) + +//go:embed dist/* +var webuiFS embed.FS + +func SetupWebUI(r chi.Router) error { + distFS, err := fs.Sub(webuiFS, "dist") + if err != nil { + return err + } + + fileServer := http.FileServer(http.FS(distFS)) + r.Handle("/*", fileServer) + return nil +}