gpt4all/gpt4all-bindings/golang
2023-05-20 16:36:29 -04:00
..
example Golang bindings initial working version(#534) 2023-05-15 12:45:56 -04:00
binding.cpp Golang bindings initial working version(#534) 2023-05-15 12:45:56 -04:00
binding.h Golang bindings initial working version(#534) 2023-05-15 12:45:56 -04:00
go.mod Golang bindings initial working version(#534) 2023-05-15 12:45:56 -04:00
go.sum Golang bindings initial working version(#534) 2023-05-15 12:45:56 -04:00
gpt4all_suite_test.go Golang bindings initial working version(#534) 2023-05-15 12:45:56 -04:00
gpt4all_test.go Golang bindings initial working version(#534) 2023-05-15 12:45:56 -04:00
gpt4all.go Fix #614, where relative paths to includes makes imports fail (#644) 2023-05-20 16:36:29 -04:00
Makefile Golang bindings initial working version(#534) 2023-05-15 12:45:56 -04:00
options.go Golang bindings initial working version(#534) 2023-05-15 12:45:56 -04:00
placeholder rough draft of monorepo plan 2023-05-01 15:45:39 -04:00
README.md Update README.md 2023-05-15 19:00:11 -04:00

GPT4All Golang bindings

The golang bindings have been tested on:

  • MacOS
  • Linux

Usage

import (
	"github.com/nomic/gpt4all/gpt4all-bindings/golang"
)

func main() {
	// Load the model
	model, err := gpt4all.New("model.bin", gpt4all.SetModelType(gpt4all.GPTJType))
	if err != nil {
		panic(err)
	}
	defer model.Free()

	model.SetTokenCallback(func(s string) bool {
		fmt.Print(s)
		return true
	})

	_, err = model.Predict("Here are 4 steps to create a website:", gpt4all.SetTemperature(0.1))
	if err != nil {
		panic(err)
	}
}

Building

In order to use the bindings you will need to build libgpt4all.a:

git clone https://github.com/nomic-ai/gpt4all
cd gpt4all/gpt4all-bindings/golang
make libgpt4all.a

To use the bindings in your own software:

  • Import github.com/nomic/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.

Testing

To run tests, run make test:

git clone https://github.com/nomic-ai/gpt4all
cd gpt4all/gpt4all-bindings/golang
make test