Skip to content

Commit d7e1372

Browse files
authored
feat(util): add util command to print GGUF informations (#2528)
Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent 6c087ae commit d7e1372

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

core/cli/cli.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ var CLI struct {
1313
TTS TTSCMD `cmd:"" help:"Convert text to speech"`
1414
Transcript TranscriptCMD `cmd:"" help:"Convert audio to text"`
1515
Worker worker.Worker `cmd:"" help:"Run workers to distribute workload (llama.cpp-only)"`
16+
Util UtilCMD `cmd:"" help:"Utility commands"`
1617
}

core/cli/util.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/rs/zerolog/log"
7+
8+
cliContext "github.com/go-skynet/LocalAI/core/cli/context"
9+
gguf "github.com/thxcode/gguf-parser-go"
10+
)
11+
12+
type UtilCMD struct {
13+
GGUFInfo GGUFInfoCMD `cmd:"" name:"gguf-info" help:"Get information about a GGUF file"`
14+
}
15+
16+
type GGUFInfoCMD struct {
17+
Args []string `arg:"" optional:"" name:"args" help:"Arguments to pass to the utility command"`
18+
}
19+
20+
func (u *GGUFInfoCMD) Run(ctx *cliContext.Context) error {
21+
if u.Args == nil || len(u.Args) == 0 {
22+
return fmt.Errorf("no GGUF file provided")
23+
}
24+
// We try to guess only if we don't have a template defined already
25+
f, err := gguf.ParseGGUFFile(u.Args[0])
26+
if err != nil {
27+
// Only valid for gguf files
28+
log.Error().Msgf("guessDefaultsFromFile: %s", "not a GGUF file")
29+
return err
30+
}
31+
32+
log.Info().
33+
Any("eosTokenID", f.Tokenizer().EOSTokenID).
34+
Any("bosTokenID", f.Tokenizer().BOSTokenID).
35+
Any("modelName", f.Model().Name).
36+
Any("architecture", f.Architecture().Architecture).Msgf("GGUF file loaded: %s", u.Args[0])
37+
38+
return nil
39+
}

main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func main() {
4242

4343
for _, envFile := range envFiles {
4444
if _, err := os.Stat(envFile); err == nil {
45-
log.Info().Str("envFile", envFile).Msg("loading environment variables from file")
45+
log.Info().Str("envFile", envFile).Msg("env file found, loading environment variables from file")
4646
err = godotenv.Load(envFile)
4747
if err != nil {
4848
log.Error().Err(err).Str("envFile", envFile).Msg("failed to load environment variables from file")
@@ -117,6 +117,7 @@ Version: ${version}
117117

118118
// Run the thing!
119119
err = ctx.Run(&cli.CLI.Context)
120-
121-
ctx.FatalIfErrorf(err)
120+
if err != nil {
121+
log.Fatal().Err(err).Msg("Error running the application")
122+
}
122123
}

pkg/templates/cache.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func (tc *TemplateCache) loadTemplateIfExists(templateType TemplateType, templat
8282
return fmt.Errorf("template file outside path: %s", file)
8383
}
8484

85+
// can either be a file in the system or a string with the template
8586
if utils.ExistsInPath(tc.templatesPath, modelTemplateFile) {
8687
d, err := os.ReadFile(file)
8788
if err != nil {

0 commit comments

Comments
 (0)