diff --git a/gpt4all-bindings/golang/README.md b/gpt4all-bindings/golang/README.md index 3f0e4f9e..0edc278d 100644 --- a/gpt4all-bindings/golang/README.md +++ b/gpt4all-bindings/golang/README.md @@ -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 diff --git a/gpt4all-bindings/golang/gpt4all.go b/gpt4all-bindings/golang/gpt4all.go index 8db98249..5a66fa1e 100644 --- a/gpt4all-bindings/golang/gpt4all.go +++ b/gpt4all-bindings/golang/gpt4all.go @@ -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 { diff --git a/gpt4all-bindings/golang/options.go b/gpt4all-bindings/golang/options.go index 973d88e1..d79b1723 100644 --- a/gpt4all-bindings/golang/options.go +++ b/gpt4all-bindings/golang/options.go @@ -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