fix: correctly handle errors from App constructor (#430)

Signed-off-by: mudler <mudler@mocaccino.org>
examples_update
Ettore Di Giacinto 2 years ago committed by GitHub
parent ca9115d6d0
commit aacb96df7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      Dockerfile
  2. 2
      Dockerfile.dev
  3. 8
      api/api.go
  4. 9
      main.go

@ -42,7 +42,7 @@ COPY . .
RUN make build RUN make build
# Define the health check command # Define the health check command
HEALTHCHECK --interval=30s --timeout=360s --retries=10 \ HEALTHCHECK --interval=1m --timeout=10m --retries=10 \
CMD curl -f $HEALTHCHECK_ENDPOINT || exit 1 CMD curl -f $HEALTHCHECK_ENDPOINT || exit 1
EXPOSE 8080 EXPOSE 8080

@ -72,7 +72,7 @@ RUN apt-get install -y libgomp1 libopencv-core4.5 libopencv-imgcodecs4.5
COPY --from=builder /build/local-ai /usr/bin/local-ai COPY --from=builder /build/local-ai /usr/bin/local-ai
# Define the health check command # Define the health check command
HEALTHCHECK --interval=30s --timeout=360s --retries=10 \ HEALTHCHECK --interval=1m --timeout=10m --retries=10 \
CMD curl -f $HEALTHCHECK_ENDPOINT || exit 1 CMD curl -f $HEALTHCHECK_ENDPOINT || exit 1
EXPOSE 8080 EXPOSE 8080

@ -11,7 +11,7 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
func App(opts ...AppOption) *fiber.App { func App(opts ...AppOption) (*fiber.App, error) {
options := newOptions(opts...) options := newOptions(opts...)
zerolog.SetGlobalLevel(zerolog.InfoLevel) zerolog.SetGlobalLevel(zerolog.InfoLevel)
@ -71,13 +71,13 @@ func App(opts ...AppOption) *fiber.App {
if options.preloadJSONModels != "" { if options.preloadJSONModels != "" {
if err := ApplyGalleryFromString(options.loader.ModelPath, options.preloadJSONModels, cm); err != nil { if err := ApplyGalleryFromString(options.loader.ModelPath, options.preloadJSONModels, cm); err != nil {
return nil return nil, err
} }
} }
if options.preloadModelsFromPath != "" { if options.preloadModelsFromPath != "" {
if err := ApplyGalleryFromFile(options.loader.ModelPath, options.preloadModelsFromPath, cm); err != nil { if err := ApplyGalleryFromFile(options.loader.ModelPath, options.preloadModelsFromPath, cm); err != nil {
return nil return nil, err
} }
} }
@ -138,5 +138,5 @@ func App(opts ...AppOption) *fiber.App {
app.Get("/v1/models", listModels(options.loader, cm)) app.Get("/v1/models", listModels(options.loader, cm))
app.Get("/models", listModels(options.loader, cm)) app.Get("/models", listModels(options.loader, cm))
return app return app, nil
} }

@ -111,7 +111,7 @@ It uses llama.cpp, ggml and gpt4all as backend with golang c bindings.
Copyright: "go-skynet authors", Copyright: "go-skynet authors",
Action: func(ctx *cli.Context) error { Action: func(ctx *cli.Context) error {
fmt.Printf("Starting LocalAI using %d threads, with models path: %s\n", ctx.Int("threads"), ctx.String("models-path")) fmt.Printf("Starting LocalAI using %d threads, with models path: %s\n", ctx.Int("threads"), ctx.String("models-path"))
return api.App( app, err := api.App(
api.WithConfigFile(ctx.String("config-file")), api.WithConfigFile(ctx.String("config-file")),
api.WithJSONStringPreload(ctx.String("preload-models")), api.WithJSONStringPreload(ctx.String("preload-models")),
api.WithYAMLConfigPreload(ctx.String("preload-models-config")), api.WithYAMLConfigPreload(ctx.String("preload-models-config")),
@ -124,7 +124,12 @@ It uses llama.cpp, ggml and gpt4all as backend with golang c bindings.
api.WithCors(ctx.Bool("cors")), api.WithCors(ctx.Bool("cors")),
api.WithCorsAllowOrigins(ctx.String("cors-allow-origins")), api.WithCorsAllowOrigins(ctx.String("cors-allow-origins")),
api.WithThreads(ctx.Int("threads")), api.WithThreads(ctx.Int("threads")),
api.WithUploadLimitMB(ctx.Int("upload-limit"))).Listen(ctx.String("address")) api.WithUploadLimitMB(ctx.Int("upload-limit")))
if err != nil {
return err
}
return app.Listen(ctx.String("address"))
}, },
} }

Loading…
Cancel
Save