feat: Update gpt4all, support multiple implementations in runtime (#472)
Signed-off-by: mudler <mudler@mocaccino.org>renovate/github.com-imdario-mergo-1.x
parent
42d753846e
commit
78ad4813df
@ -0,0 +1,27 @@ |
||||
package api |
||||
|
||||
import ( |
||||
"embed" |
||||
"os" |
||||
"path/filepath" |
||||
|
||||
"github.com/go-skynet/LocalAI/pkg/assets" |
||||
"github.com/rs/zerolog/log" |
||||
) |
||||
|
||||
func PrepareBackendAssets(backendAssets embed.FS, dst string) error { |
||||
|
||||
// Extract files from the embedded FS
|
||||
err := assets.ExtractFiles(backendAssets, dst) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
|
||||
// Set GPT4ALL libs where we extracted the files
|
||||
// https://github.com/nomic-ai/gpt4all/commit/27e80e1d10985490c9fd4214e4bf458cfcf70896
|
||||
gpt4alldir := filepath.Join(dst, "backend-assets", "gpt4all") |
||||
os.Setenv("GPT4ALL_IMPLEMENTATIONS_PATH", gpt4alldir) |
||||
log.Debug().Msgf("GPT4ALL_IMPLEMENTATIONS_PATH: %s", gpt4alldir) |
||||
|
||||
return nil |
||||
} |
@ -0,0 +1,6 @@ |
||||
package main |
||||
|
||||
import "embed" |
||||
|
||||
//go:embed backend-assets/*
|
||||
var backendAssets embed.FS |
@ -0,0 +1,51 @@ |
||||
package assets |
||||
|
||||
import ( |
||||
"embed" |
||||
"fmt" |
||||
"io/fs" |
||||
"os" |
||||
"path/filepath" |
||||
) |
||||
|
||||
func ExtractFiles(content embed.FS, extractDir string) error { |
||||
// Create the target directory if it doesn't exist
|
||||
err := os.MkdirAll(extractDir, 0755) |
||||
if err != nil { |
||||
return fmt.Errorf("failed to create directory: %v", err) |
||||
} |
||||
|
||||
// Walk through the embedded FS and extract files
|
||||
err = fs.WalkDir(content, ".", func(path string, d fs.DirEntry, err error) error { |
||||
if err != nil { |
||||
return err |
||||
} |
||||
|
||||
// Reconstruct the directory structure in the target directory
|
||||
targetFile := filepath.Join(extractDir, path) |
||||
if d.IsDir() { |
||||
// Create the directory in the target directory
|
||||
err := os.MkdirAll(targetFile, 0755) |
||||
if err != nil { |
||||
return fmt.Errorf("failed to create directory: %v", err) |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
// Read the file from the embedded FS
|
||||
fileData, err := content.ReadFile(path) |
||||
if err != nil { |
||||
return fmt.Errorf("failed to read file: %v", err) |
||||
} |
||||
|
||||
// Create the file in the target directory
|
||||
err = os.WriteFile(targetFile, fileData, 0644) |
||||
if err != nil { |
||||
return fmt.Errorf("failed to write file: %v", err) |
||||
} |
||||
|
||||
return nil |
||||
}) |
||||
|
||||
return err |
||||
} |
Loading…
Reference in new issue