2023-05-15 12:45:56 -04:00
# GPT4All Golang bindings
2023-05-15 19:00:11 -04:00
The golang bindings have been tested on:
2023-05-15 12:45:56 -04:00
- MacOS
- Linux
### Usage
```
import (
2023-05-28 19:51:11 -04:00
"github.com/nomic-ai/gpt4all/gpt4all-bindings/golang"
2023-05-15 12:45:56 -04:00
)
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` :
```
2023-12-11 12:58:58 -05:00
git clone --recurse-submodules https://github.com/nomic-ai/gpt4all
2023-05-15 12:45:56 -04:00
cd gpt4all/gpt4all-bindings/golang
make libgpt4all.a
```
To use the bindings in your own software:
2023-05-28 19:51:11 -04:00
- Import `github.com/nomic-ai/gpt4all/gpt4all-bindings/golang` ;
2023-05-15 12:45:56 -04:00
- Compile `libgpt4all.a` (you can use `make libgpt4all.a` in the bindings/go directory);
2023-06-14 10:27:19 -04:00
- 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.
2023-06-01 10:09:06 -04:00
- 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
2023-05-15 12:45:56 -04:00
## Testing
To run tests, run `make test` :
```
git clone https://github.com/nomic-ai/gpt4all
cd gpt4all/gpt4all-bindings/golang
make test
2023-05-15 19:00:11 -04:00
```