From dbc70dc13ccf126e4a4009bcd16c9b0010ae3978 Mon Sep 17 00:00:00 2001 From: mudler Date: Sat, 25 Mar 2023 01:09:51 +0100 Subject: [PATCH] Add a simple web-page as index of the API for helping with inference testing --- api.go | 19 ++++++++- go.mod | 4 +- go.sum | 6 ++- index.html | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+), 5 deletions(-) create mode 100644 index.html diff --git a/api.go b/api.go index f9c9303..29260eb 100644 --- a/api.go +++ b/api.go @@ -1,15 +1,24 @@ package main import ( + "embed" + "net/http" "strconv" llama "github.com/go-skynet/llama/go" "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/filesystem" ) +//go:embed index.html +var indexHTML embed.FS + func api(l *llama.LLama, listenAddr string, threads int) error { app := fiber.New() - + app.Use("/", filesystem.New(filesystem.Config{ + Root: http.FS(indexHTML), + NotFoundFile: "index.html", + })) /* curl --location --request POST 'http://localhost:8080/predict' --header 'Content-Type: application/json' --data-raw '{ "text": "What is an alpaca?", @@ -19,6 +28,14 @@ func api(l *llama.LLama, listenAddr string, threads int) error { "tokens": 100 }' */ + // Serve the index.html file + app.Get("/", func(c *fiber.Ctx) error { + data, err := indexHTML.ReadFile("index.html") + if err != nil { + return err + } + return c.Send(data) + }) // Endpoint to generate the prediction app.Post("/predict", func(c *fiber.Ctx) error { diff --git a/go.mod b/go.mod index f35af34..4ddc4c6 100644 --- a/go.mod +++ b/go.mod @@ -40,6 +40,6 @@ require ( github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect golang.org/x/sync v0.1.0 // indirect golang.org/x/sys v0.6.0 // indirect - golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect - golang.org/x/text v0.3.7 // indirect + golang.org/x/term v0.5.0 // indirect + golang.org/x/text v0.7.0 // indirect ) diff --git a/go.sum b/go.sum index b26d568..d15b2e4 100644 --- a/go.sum +++ b/go.sum @@ -108,13 +108,15 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20201022035929-9cf592e881e9/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= diff --git a/index.html b/index.html new file mode 100644 index 0000000..89b455f --- /dev/null +++ b/index.html @@ -0,0 +1,120 @@ + + + + llama-cli + + + + + + + + +
+

llama-cli API

+
+ + +
+
+ + +
+
+ + + 0.20 +
+
+ + +
+
+ + + 0.9 +
+
+ + +
+ +
+
+ + +
+
+ + + + +