mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-11-05 16:44:22 +00:00
Embed webui
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -32,3 +32,4 @@ go.work.sum
|
||||
# .vscode/
|
||||
|
||||
node_modules/
|
||||
dist/
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
23
webui/webui.go
Normal file
23
webui/webui.go
Normal file
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user