Allow to set a SetLibrarySearchPath in the golang bindings (#981)

This is used to identify the path where all the various implementations
are
This commit is contained in:
Ettore Di Giacinto 2023-06-14 16:27:19 +02:00 committed by GitHub
parent 8953b7f6a6
commit b004c53a7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View File

@ -45,7 +45,7 @@ To use the bindings in your own software:
- Import `github.com/nomic-ai/gpt4all/gpt4all-bindings/golang`;
- Compile `libgpt4all.a` (you can use `make libgpt4all.a` in the bindings/go directory);
- Link your go binary against whisper by setting the environment variables `C_INCLUDE_PATH` and `LIBRARY_PATH` to point to the `binding.h` file directory and `libgpt4all.a` file directory respectively.
- Link your go binary by setting the environment variables `C_INCLUDE_PATH` and `LIBRARY_PATH` to point to the `binding.h` file directory and `libgpt4all.a` file directory respectively.
- Note: you need to have *.so/*.dynlib/*.dll files of the implementation nearby the binary produced by the binding in order to make this to work
## Testing

View File

@ -10,6 +10,7 @@ package gpt4all
// float top_p, float temp, int n_batch,float ctx_erase);
// void free_model(void *state_ptr);
// extern unsigned char getTokenCallback(void *, char *);
// void llmodel_set_implementation_search_path(const char *path);
import "C"
import (
"fmt"
@ -27,6 +28,10 @@ type Model struct {
func New(model string, opts ...ModelOption) (*Model, error) {
ops := NewModelOptions(opts...)
if ops.LibrarySearchPath != "" {
C.llmodel_set_implementation_search_path(C.CString(ops.LibrarySearchPath))
}
state := C.load_model(C.CString(model), C.int(ops.Threads))
if state == nil {

View File

@ -24,7 +24,8 @@ var DefaultModelOptions ModelOptions = ModelOptions{
}
type ModelOptions struct {
Threads int
Threads int
LibrarySearchPath string
}
type ModelOption func(p *ModelOptions)
@ -100,6 +101,13 @@ func SetThreads(c int) ModelOption {
}
}
// SetLibrarySearchPath sets the dynamic libraries used by gpt4all for the various ggml implementations.
func SetLibrarySearchPath(t string) ModelOption {
return func(p *ModelOptions) {
p.LibrarySearchPath = t
}
}
// Create a new PredictOptions object with the given options.
func NewModelOptions(opts ...ModelOption) ModelOptions {
p := DefaultModelOptions