-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Update gpt4all, support multiple implementations in runtime (#472)
Signed-off-by: mudler <[email protected]>
- Loading branch information
Showing
12 changed files
with
142 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,6 @@ release/ | |
# just in case | ||
.DS_Store | ||
.idea | ||
|
||
# Generated during build | ||
backend-assets/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package main | ||
|
||
import "embed" | ||
|
||
//go:embed backend-assets/* | ||
var backendAssets embed.FS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters