-
-void* load_model(const char *fname, int n_threads);
-
-void model_prompt(const char *prompt, const char *prompt_template, int special, const char *fake_reply,
- void *m, char* result, int repeat_last_n, float repeat_penalty, int n_ctx, int tokens,
- int top_k, float top_p, float min_p, float temp, int n_batch,float ctx_erase);
-
-void free_model(void *state_ptr);
-
-extern unsigned char getTokenCallback(void *, char *);
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/gpt4all-bindings/golang/example/main.go b/gpt4all-bindings/golang/example/main.go
deleted file mode 100644
index 7351e855..00000000
--- a/gpt4all-bindings/golang/example/main.go
+++ /dev/null
@@ -1,82 +0,0 @@
-package main
-
-import (
- "bufio"
- "flag"
- "fmt"
- "io"
- "os"
- "runtime"
- "strings"
-
- gpt4all "github.com/nomic-ai/gpt4all/gpt4all-bindings/golang"
-)
-
-var (
- threads = 4
- tokens = 128
-)
-
-func main() {
- var model string
-
- flags := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
- flags.StringVar(&model, "m", "./models/7B/ggml-model-q4_0.bin", "path to q4_0.bin model file to load")
- flags.IntVar(&threads, "t", runtime.NumCPU(), "number of threads to use during computation")
- flags.IntVar(&tokens, "n", 512, "number of tokens to predict")
-
- err := flags.Parse(os.Args[1:])
- if err != nil {
- fmt.Printf("Parsing program arguments failed: %s", err)
- os.Exit(1)
- }
- l, err := gpt4all.New(model, gpt4all.SetThreads(threads))
- if err != nil {
- fmt.Println("Loading the model failed:", err.Error())
- os.Exit(1)
- }
- fmt.Printf("Model loaded successfully.\n")
-
- l.SetTokenCallback(func(token string) bool {
- fmt.Print(token)
- return true
- })
-
- reader := bufio.NewReader(os.Stdin)
-
- for {
- text := readMultiLineInput(reader)
-
- _, err := l.Predict(text, "", "", gpt4all.SetTokens(tokens), gpt4all.SetTopK(90), gpt4all.SetTopP(0.86))
- if err != nil {
- panic(err)
- }
- fmt.Printf("\n\n")
- }
-}
-
-// readMultiLineInput reads input until an empty line is entered.
-func readMultiLineInput(reader *bufio.Reader) string {
- var lines []string
- fmt.Print(">>> ")
-
- for {
- line, err := reader.ReadString('\n')
- if err != nil {
- if err == io.EOF {
- os.Exit(0)
- }
- fmt.Printf("Reading the prompt failed: %s", err)
- os.Exit(1)
- }
-
- if len(strings.TrimSpace(line)) == 0 {
- break
- }
-
- lines = append(lines, line)
- }
-
- text := strings.Join(lines, "")
- return text
-}
diff --git a/gpt4all-bindings/golang/go.mod b/gpt4all-bindings/golang/go.mod
deleted file mode 100644
index e45c3dad..00000000
--- a/gpt4all-bindings/golang/go.mod
+++ /dev/null
@@ -1,20 +0,0 @@
-module github.com/nomic-ai/gpt4all/gpt4all-bindings/golang
-
-go 1.19
-
-require (
- github.com/onsi/ginkgo/v2 v2.9.4
- github.com/onsi/gomega v1.27.6
-)
-
-require (
- github.com/go-logr/logr v1.2.4 // indirect
- github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
- github.com/google/go-cmp v0.5.9 // indirect
- github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
- golang.org/x/net v0.9.0 // indirect
- golang.org/x/sys v0.7.0 // indirect
- golang.org/x/text v0.9.0 // indirect
- golang.org/x/tools v0.8.0 // indirect
- gopkg.in/yaml.v3 v3.0.1 // indirect
-)
diff --git a/gpt4all-bindings/golang/go.sum b/gpt4all-bindings/golang/go.sum
deleted file mode 100644
index fa0bcd86..00000000
--- a/gpt4all-bindings/golang/go.sum
+++ /dev/null
@@ -1,40 +0,0 @@
-github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
-github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
-github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
-github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
-github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
-github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
-github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
-github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
-github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
-github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
-github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
-github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE=
-github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
-github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
-github.com/onsi/ginkgo/v2 v2.9.4 h1:xR7vG4IXt5RWx6FfIjyAtsoMAtnc3C/rFXBBd2AjZwE=
-github.com/onsi/ginkgo/v2 v2.9.4/go.mod h1:gCQYp2Q+kSoIj7ykSVb9nskRSsR6PUj4AiLywzIhbKM=
-github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE=
-github.com/onsi/gomega v1.27.6/go.mod h1:PIQNjfQwkP3aQAH7lf7j87O/5FiNr+ZR8+ipb+qQlhg=
-github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
-github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
-github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
-github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM=
-golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
-golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
-golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
-golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
-golang.org/x/tools v0.8.0 h1:vSDcovVPld282ceKgDimkRSC8kpaH1dgyc9UMzlt84Y=
-golang.org/x/tools v0.8.0/go.mod h1:JxBZ99ISMI5ViVkT1tr6tdNmXeTrcpVSD3vZ1RsRdN4=
-google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
-gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/gpt4all-bindings/golang/gpt4all.go b/gpt4all-bindings/golang/gpt4all.go
deleted file mode 100644
index 57604cf4..00000000
--- a/gpt4all-bindings/golang/gpt4all.go
+++ /dev/null
@@ -1,112 +0,0 @@
-package gpt4all
-
-// #cgo CFLAGS: -I${SRCDIR}../../gpt4all-backend/ -I${SRCDIR}../../gpt4all-backend/llama.cpp -I./
-// #cgo CXXFLAGS: -std=c++17 -I${SRCDIR}../../gpt4all-backend/ -I${SRCDIR}../../gpt4all-backend/llama.cpp -I./
-// #cgo darwin LDFLAGS: -framework Accelerate
-// #cgo darwin CXXFLAGS: -std=c++17
-// #cgo LDFLAGS: -lgpt4all -lm -lstdc++ -ldl
-// void* load_model(const char *fname, int n_threads);
-// void model_prompt( const char *prompt, const char *prompt_template, int special, const char *fake_reply, void *m, char* result, int repeat_last_n, float repeat_penalty, int n_ctx, int tokens, int top_k,
-// float top_p, float min_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"
- "runtime"
- "strings"
- "sync"
- "unsafe"
-)
-
-// The following code is https://github.com/go-skynet/go-llama.cpp with small adaptations
-type Model struct {
- state unsafe.Pointer
-}
-
-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 {
- return nil, fmt.Errorf("failed loading model")
- }
-
- gpt := &Model{state: state}
- // set a finalizer to remove any callbacks when the struct is reclaimed by the garbage collector.
- runtime.SetFinalizer(gpt, func(g *Model) {
- setTokenCallback(g.state, nil)
- })
-
- return gpt, nil
-}
-
-func (l *Model) Predict(text, template, fakeReplyText string, opts ...PredictOption) (string, error) {
-
- po := NewPredictOptions(opts...)
-
- input := C.CString(text)
- if po.Tokens == 0 {
- po.Tokens = 99999999
- }
- templateInput := C.CString(template)
- fakeReplyInput := C.CString(fakeReplyText)
- out := make([]byte, po.Tokens)
-
- C.model_prompt(input, templateInput, C.int(po.Special), fakeReplyInput, l.state, (*C.char)(unsafe.Pointer(&out[0])),
- C.int(po.RepeatLastN), C.float(po.RepeatPenalty), C.int(po.ContextSize), C.int(po.Tokens),
- C.int(po.TopK), C.float(po.TopP), C.float(po.MinP), C.float(po.Temperature), C.int(po.Batch),
- C.float(po.ContextErase))
-
- res := C.GoString((*C.char)(unsafe.Pointer(&out[0])))
- res = strings.TrimPrefix(res, " ")
- res = strings.TrimPrefix(res, text)
- res = strings.TrimPrefix(res, "\n")
- res = strings.TrimSuffix(res, "<|endoftext|>")
-
- return res, nil
-}
-
-func (l *Model) Free() {
- C.free_model(l.state)
-}
-
-func (l *Model) SetTokenCallback(callback func(token string) bool) {
- setTokenCallback(l.state, callback)
-}
-
-var (
- m sync.Mutex
- callbacks = map[uintptr]func(string) bool{}
-)
-
-//export getTokenCallback
-func getTokenCallback(statePtr unsafe.Pointer, token *C.char) bool {
- m.Lock()
- defer m.Unlock()
-
- if callback, ok := callbacks[uintptr(statePtr)]; ok {
- return callback(C.GoString(token))
- }
-
- return true
-}
-
-// setCallback can be used to register a token callback for LLama. Pass in a nil callback to
-// remove the callback.
-func setTokenCallback(statePtr unsafe.Pointer, callback func(string) bool) {
- m.Lock()
- defer m.Unlock()
-
- if callback == nil {
- delete(callbacks, uintptr(statePtr))
- } else {
- callbacks[uintptr(statePtr)] = callback
- }
-}
diff --git a/gpt4all-bindings/golang/gpt4all_suite_test.go b/gpt4all-bindings/golang/gpt4all_suite_test.go
deleted file mode 100644
index 3f379b1e..00000000
--- a/gpt4all-bindings/golang/gpt4all_suite_test.go
+++ /dev/null
@@ -1,13 +0,0 @@
-package gpt4all_test
-
-import (
- "testing"
-
- . "github.com/onsi/ginkgo/v2"
- . "github.com/onsi/gomega"
-)
-
-func TestGPT(t *testing.T) {
- RegisterFailHandler(Fail)
- RunSpecs(t, "go-gpt4all-j test suite")
-}
diff --git a/gpt4all-bindings/golang/gpt4all_test.go b/gpt4all-bindings/golang/gpt4all_test.go
deleted file mode 100644
index fd96584c..00000000
--- a/gpt4all-bindings/golang/gpt4all_test.go
+++ /dev/null
@@ -1,17 +0,0 @@
-package gpt4all_test
-
-import (
- . "github.com/nomic-ai/gpt4all/gpt4all-bindings/golang"
- . "github.com/onsi/ginkgo/v2"
- . "github.com/onsi/gomega"
-)
-
-var _ = Describe("LLama binding", func() {
- Context("Declaration", func() {
- It("fails with no model", func() {
- model, err := New("not-existing")
- Expect(err).To(HaveOccurred())
- Expect(model).To(BeNil())
- })
- })
-})
diff --git a/gpt4all-bindings/golang/options.go b/gpt4all-bindings/golang/options.go
deleted file mode 100644
index 56b0efc8..00000000
--- a/gpt4all-bindings/golang/options.go
+++ /dev/null
@@ -1,138 +0,0 @@
-package gpt4all
-
-type PredictOptions struct {
- ContextSize, RepeatLastN, Tokens, TopK, Batch, Special int
- TopP, MinP, Temperature, ContextErase, RepeatPenalty float64
-}
-
-type PredictOption func(p *PredictOptions)
-
-var DefaultOptions PredictOptions = PredictOptions{
- Tokens: 200,
- TopK: 10,
- TopP: 0.90,
- MinP: 0.0,
- Temperature: 0.96,
- Batch: 1,
- Special: 0,
- ContextErase: 0.55,
- ContextSize: 1024,
- RepeatLastN: 10,
- RepeatPenalty: 1.2,
-}
-
-var DefaultModelOptions ModelOptions = ModelOptions{
- Threads: 4,
-}
-
-type ModelOptions struct {
- Threads int
- LibrarySearchPath string
-}
-type ModelOption func(p *ModelOptions)
-
-// SetTokens sets the number of tokens to generate.
-func SetTokens(tokens int) PredictOption {
- return func(p *PredictOptions) {
- p.Tokens = tokens
- }
-}
-
-// SetTopK sets the value for top-K sampling.
-func SetTopK(topk int) PredictOption {
- return func(p *PredictOptions) {
- p.TopK = topk
- }
-}
-
-// SetTopP sets the value for nucleus sampling.
-func SetTopP(topp float64) PredictOption {
- return func(p *PredictOptions) {
- p.TopP = topp
- }
-}
-
-// SetMinP sets the value for min p sampling
-func SetMinP(minp float64) PredictOption {
- return func(p *PredictOptions) {
- p.MinP = minp
- }
-}
-
-// SetRepeatPenalty sets the repeat penalty.
-func SetRepeatPenalty(ce float64) PredictOption {
- return func(p *PredictOptions) {
- p.RepeatPenalty = ce
- }
-}
-
-// SetRepeatLastN sets the RepeatLastN.
-func SetRepeatLastN(ce int) PredictOption {
- return func(p *PredictOptions) {
- p.RepeatLastN = ce
- }
-}
-
-// SetContextErase sets the context erase %.
-func SetContextErase(ce float64) PredictOption {
- return func(p *PredictOptions) {
- p.ContextErase = ce
- }
-}
-
-// SetTemperature sets the temperature value for text generation.
-func SetTemperature(temp float64) PredictOption {
- return func(p *PredictOptions) {
- p.Temperature = temp
- }
-}
-
-// SetBatch sets the batch size.
-func SetBatch(size int) PredictOption {
- return func(p *PredictOptions) {
- p.Batch = size
- }
-}
-
-// SetSpecial is true if special tokens in the prompt should be processed, false otherwise.
-func SetSpecial(special bool) PredictOption {
- return func(p *PredictOptions) {
- if special {
- p.Special = 1
- } else {
- p.Special = 0
- }
- }
-}
-
-// Create a new PredictOptions object with the given options.
-func NewPredictOptions(opts ...PredictOption) PredictOptions {
- p := DefaultOptions
- for _, opt := range opts {
- opt(&p)
- }
- return p
-}
-
-// SetThreads sets the number of threads to use for text generation.
-func SetThreads(c int) ModelOption {
- return func(p *ModelOptions) {
- p.Threads = c
- }
-}
-
-// 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
- for _, opt := range opts {
- opt(&p)
- }
- return p
-}
diff --git a/gpt4all-bindings/java/.gitignore b/gpt4all-bindings/java/.gitignore
deleted file mode 100644
index 081e799c..00000000
--- a/gpt4all-bindings/java/.gitignore
+++ /dev/null
@@ -1,5 +0,0 @@
-# Make sure native directory never gets commited to git for the project.
-/src/main/resources/native
-
-# IntelliJ project file
-*.iml
\ No newline at end of file
diff --git a/gpt4all-bindings/java/Developer_docs.md b/gpt4all-bindings/java/Developer_docs.md
deleted file mode 100644
index a90dc68c..00000000
--- a/gpt4all-bindings/java/Developer_docs.md
+++ /dev/null
@@ -1,80 +0,0 @@
-# Java Bindings Developer documents.
-
-This document is meant to anyone looking to build the Java bindings from source, test a build locally and perform a release.
-
-## Building locally
-
-Maven is the build tool used by the project. Maven version of 3.8 or higher is recommended. Make sure the **mvn**
-is available on the command path.
-
-The project builds to Java version 11 target so make sure that a JDK at version 11 or newer is installed.
-
-### Setting up location of native shared libraries
-The property **native.libs.location** in pom.xml may need to be set:
-```
-
- ...
- C:\Users\felix\dev\gpt4all_java_bins\release_1_1_3_Jun22_2023
-
-```
-All the native shared libraries bundled with the Java binding jar will be copied from this location.
-The directory structure is **native/linux**, **native/macos**, **native/windows**. These directories are copied
-into the **src/main/resources** folder during the build process.
-
-For the purposes of local testing, none of these directories have to be present or just one OS type may be present.
-
-If none of the native libraries are present in **native.libs.location** the shared libraries will be searched for
-in location path set by **LLModel.LIBRARY_SEARCH_PATH** static variable in Java source code that is using the bindings.
-
-Alternately you can copy the shared libraries into the **src/resources/native/linux** before
-you build, but note **src/main/resources/native** is on the .gitignore, so it will not be committed to sources.
-
-### Building
-
-To package the bindings jar run:
-```
-mvn package
-```
-This will build two jars. One has only the Java bindings and the other is a fat jar that will have required dependencies included as well.
-
-To package and install the Java bindings to your local maven repository run:
-```
-mvn install
-```
-
-### Using in a sample application
-
-You can check out a sample project that uses the java bindings here:
-https://github.com/felix-zaslavskiy/gpt4all-java-bindings-sample.git
-
-1. First, update the dependency of java bindings to whatever you have installed in local repository such as **1.1.4-SNAPSHOT**
-2. Second, update **Main.java** and set **baseModelPath** to the correct location of model weight files.
-
-3. To make a runnable jar run:
-```
-mvn package
-```
-
-A fat jar is also created which is easy to run from command line:
-```
-java -jar target/gpt4all-java-bindings-sample-1.0-SNAPSHOT-jar-with-dependencies.jar
-```
-
-### Publish a public release.
-
-For publishing a new version to maven central repository requires password and signing keys which F.Z. currently maintains, so
-he is responsible for making a public release.
-
-The procedure is as follows:
-
-For a snapshot release
-Run:
-```
-mvn deploy -P signing-profile
-```
-
-For a non-snapshot release
-Run:
-```
-mvn clean deploy -P signing-profile,release
-```
\ No newline at end of file
diff --git a/gpt4all-bindings/java/README.md b/gpt4all-bindings/java/README.md
deleted file mode 100644
index af996054..00000000
--- a/gpt4all-bindings/java/README.md
+++ /dev/null
@@ -1,126 +0,0 @@
-# Java bindings
-
-Java bindings let you load a gpt4all library into your Java application and execute text
-generation using an intuitive and easy to use API. No GPU is required because gpt4all executes on the CPU.
-The gpt4all models are quantized to easily fit into system RAM and use about 4 to 7GB of system RAM.
-
-## Getting Started
-You can add Java bindings into your Java project by adding the following dependency to your project:
-
-**Maven**
-```
-
- com.hexadevlabs
- gpt4all-java-binding
- 1.1.5
-
-```
-**Gradle**
-```
-implementation 'com.hexadevlabs:gpt4all-java-binding:1.1.5'
-```
-
-To add the library dependency for another build system see [Maven Central Java bindings](https://central.sonatype.com/artifact/com.hexadevlabs/gpt4all-java-binding/).
-
-To download model binary weights file use a URL such as [`https://gpt4all.io/models/gguf/gpt4all-13b-snoozy-q4_0.gguf`](https://gpt4all.io/models/gguf/gpt4all-13b-snoozy-q4_0.gguf).
-
-For information about other models available see the [model file list](https://github.com/nomic-ai/gpt4all/tree/main/gpt4all-chat#manual-download-of-models).
-
-### Sample code
-```java
-public class Example {
- public static void main(String[] args) {
-
- String prompt = "### Human:\nWhat is the meaning of life\n### Assistant:";
-
- // Replace the hardcoded path with the actual path where your model file resides
- String modelFilePath = "C:\\Users\\felix\\AppData\\Local\\nomic.ai\\GPT4All\\ggml-gpt4all-j-v1.3-groovy.bin";
-
- try (LLModel model = new LLModel(Path.of(modelFilePath))) {
-
- // May generate up to 4096 tokens but generally stops early
- LLModel.GenerationConfig config = LLModel.config()
- .withNPredict(4096).build();
-
- // Will also stream to standard output
- String fullGeneration = model.generate(prompt, config, true);
-
- } catch (Exception e) {
- // Exceptions generally may happen if the model file fails to load
- // for a number of reasons such as a file not found.
- // It is possible that Java may not be able to dynamically load the native shared library or
- // the llmodel shared library may not be able to dynamically load the backend
- // implementation for the model file you provided.
- //
- // Once the LLModel class is successfully loaded into memory the text generation calls
- // generally should not throw exceptions.
- e.printStackTrace(); // Printing here but in a production system you may want to take some action.
- }
- }
-
-}
-```
-
-For a Maven-based sample project that uses this library see this [sample project](https://github.com/felix-zaslavskiy/gpt4all-java-bindings-sample)
-
-### Additional considerations
-#### Logger warnings
-The Java bindings library may produce a warning if you don't have a SLF4J binding included in your project:
-```
-SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
-SLF4J: Defaulting to no-operation (NOP) logger implementation
-SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
-```
-The Java bindings only use logging for informational
-purposes, so a logger is not essential to correctly use the library. You can ignore this warning if you don't have SLF4J bindings
-in your project.
-
-To add a simple logger using a Maven dependency you may use:
-```
-
- org.slf4j
- slf4j-simple
- 1.7.36
-
-```
-
-#### Loading your native libraries
-1. the Java bindings package JAR comes bundled with a native library files for Windows, macOS and Linux. These library files are
-copied to a temporary directory and loaded at runtime. For advanced users who may want to package shared libraries into Docker containers
-or want to use a custom build of the shared libraries and ignore the once bundled with the Java package they have option
-to load libraries from your local directory by setting a static property to the location of library files.
-There are no guarantees of compatibility if used in such a way so be careful if you really want to do it.
-
-For example:
-```java
-class Example {
- public static void main(String[] args) {
- // gpt4all native shared libraries location
- LLModel.LIBRARY_SEARCH_PATH = "C:\\Users\\felix\\gpt4all\\lib\\";
- // ... use the library normally
- }
-}
-```
-2. Not every AVX-only shared library is bundled with the JAR right now to reduce size. Only libgptj-avx is included.
-If you are running into issues please let us know using the [gpt4all project issue tracker](https://github.com/nomic-ai/gpt4all/issues).
-
-3. For Windows the native library included in jar depends on specific Microsoft C and C++ (MSVC) runtime libraries which may not be installed on your system.
-If this is the case you can easily download and install the latest x64 Microsoft Visual C++ Redistributable package from https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170
-
-4. When running Java in a Docker container it is advised to use eclipse-temurin:17-jre parent image. Alpine based parent images don't work due to the native library dependencies.
-
-## Version history
-1. Version **1.1.2**:
- - Java bindings is compatible with gpt4ll version 2.4.6
- - Initial stable release with the initial feature set
-2. Version **1.1.3**:
- - Java bindings is compatible with gpt4all version 2.4.8
- - Add static GPT4ALL_VERSION to signify gpt4all version of the bindings
- - Add PromptIsTooLongException for prompts that are longer than context size.
- - Replit model support to include Metal Mac hardware support.
-3. Version **1.1.4**:
- - Java bindings is compatible with gpt4all version 2.4.11
- - Falcon model support included.
-4. Version **1.1.5**:
- - Add a check for model file readability before loading model.
-
diff --git a/gpt4all-bindings/java/TODO.md b/gpt4all-bindings/java/TODO.md
deleted file mode 100644
index 48342f78..00000000
--- a/gpt4all-bindings/java/TODO.md
+++ /dev/null
@@ -1,6 +0,0 @@
-## Needed
-1. Integrate with circleci build pipeline like the C# binding.
-
-## These are just ideas
-1. Better Chat completions function.
-2. Chat completion that returns result in OpenAI compatible format.
diff --git a/gpt4all-bindings/java/pom.xml b/gpt4all-bindings/java/pom.xml
deleted file mode 100644
index 4687aa1a..00000000
--- a/gpt4all-bindings/java/pom.xml
+++ /dev/null
@@ -1,216 +0,0 @@
-
-
- 4.0.0
-
- com.hexadevlabs
- gpt4all-java-binding
- 1.1.5
- jar
-
-
- 11
- 11
- UTF-8
- C:\Users\felix\dev\gpt4all_java_bins\release_1_1_4_July8_2023
-
-
- ${project.groupId}:${project.artifactId}
- Java bindings for GPT4ALL LLM
- https://github.com/nomic-ai/gpt4all
-
-
- The Apache License, Version 2.0
- https://github.com/nomic-ai/gpt4all/blob/main/LICENSE.txt
-
-
-
-
- Felix Zaslavskiy
- felixz@hexadevlabs.com
- https://github.com/felix-zaslavskiy/
-
-
-
- scm:git:git://github.com/nomic-ai/gpt4all.git
- scm:git:ssh://github.com/nomic-ai/gpt4all.git
- https://github.com/nomic-ai/gpt4all/tree/main
-
-
-
-
- com.github.jnr
- jnr-ffi
- 2.2.13
-
-
-
- org.slf4j
- slf4j-api
- 1.7.36
-
-
-
- org.junit.jupiter
- junit-jupiter-api
- 5.9.2
- test
-
-
-
- org.mockito
- mockito-junit-jupiter
- 5.4.0
- test
-
-
-
- org.mockito
- mockito-core
- 5.4.0
- test
-
-
-
-
-
- ossrh
- https://s01.oss.sonatype.org/content/repositories/snapshots
-
-
- ossrh
- https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/
-
-
-
-
-
-
- src/main/resources
-
-
- ${project.build.directory}/generated-resources
-
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
- 3.0.0
-
- 0
-
-
-
- org.apache.maven.plugins
- maven-resources-plugin
- 3.3.1
-
-
- copy-resources
-
- validate
-
- copy-resources
-
-
- ${project.build.directory}/generated-resources
-
-
- ${native.libs.location}
-
-
-
-
-
-
-
-
-
- org.sonatype.plugins
- nexus-staging-maven-plugin
- 1.6.13
- true
-
- ossrh
- https://s01.oss.sonatype.org/
- true
-
-
-
- org.apache.maven.plugins
- maven-source-plugin
- 2.2.1
-
-
- attach-sources
-
- jar-no-fork
-
-
-
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
- 3.5.0
-
-
- attach-javadocs
-
- jar
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-assembly-plugin
- 3.6.0
-
-
- jar-with-dependencies
-
-
-
-
- make-assembly
- package
-
- single
-
-
-
-
-
-
-
-
-
-
- signing-profile
-
-
-
-
- org.apache.maven.plugins
- maven-gpg-plugin
- 3.1.0
-
-
- sign-artifacts
- verify
-
- sign
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/gpt4all-bindings/java/src/main/java/com/hexadevlabs/gpt4all/LLModel.java b/gpt4all-bindings/java/src/main/java/com/hexadevlabs/gpt4all/LLModel.java
deleted file mode 100644
index 6114cfad..00000000
--- a/gpt4all-bindings/java/src/main/java/com/hexadevlabs/gpt4all/LLModel.java
+++ /dev/null
@@ -1,641 +0,0 @@
-package com.hexadevlabs.gpt4all;
-
-import jnr.ffi.Pointer;
-import jnr.ffi.byref.PointerByReference;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.ByteArrayOutputStream;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.*;
-import java.util.stream.Collectors;
-
-public class LLModel implements AutoCloseable {
-
- /**
- * Config used for how to decode LLM outputs.
- * High temperature closer to 1 gives more creative outputs
- * while low temperature closer to 0 produce more precise outputs.
- *
- * Use builder to set settings you want.
- */
- public static class GenerationConfig extends LLModelLibrary.LLModelPromptContext {
-
- private GenerationConfig() {
- super(jnr.ffi.Runtime.getSystemRuntime());
- logits_size.set(0);
- tokens_size.set(0);
- n_past.set(0);
- n_ctx.set(1024);
- n_predict.set(128);
- top_k.set(40);
- top_p.set(0.95);
- min_p.set(0.0);
- temp.set(0.28);
- n_batch.set(8);
- repeat_penalty.set(1.1);
- repeat_last_n.set(10);
- context_erase.set(0.55);
- }
-
- public static class Builder {
- private final GenerationConfig configToBuild;
-
- public Builder() {
- configToBuild = new GenerationConfig();
- }
-
- public Builder withNPast(int n_past) {
- configToBuild.n_past.set(n_past);
- return this;
- }
-
- public Builder withNCtx(int n_ctx) {
- configToBuild.n_ctx.set(n_ctx);
- return this;
- }
-
- public Builder withNPredict(int n_predict) {
- configToBuild.n_predict.set(n_predict);
- return this;
- }
-
- public Builder withTopK(int top_k) {
- configToBuild.top_k.set(top_k);
- return this;
- }
-
- public Builder withTopP(float top_p) {
- configToBuild.top_p.set(top_p);
- return this;
- }
-
- public Builder withMinP(float min_p) {
- configToBuild.min_p.set(min_p);
- return this;
- }
-
- public Builder withTemp(float temp) {
- configToBuild.temp.set(temp);
- return this;
- }
-
- public Builder withNBatch(int n_batch) {
- configToBuild.n_batch.set(n_batch);
- return this;
- }
-
- public Builder withRepeatPenalty(float repeat_penalty) {
- configToBuild.repeat_penalty.set(repeat_penalty);
- return this;
- }
-
- public Builder withRepeatLastN(int repeat_last_n) {
- configToBuild.repeat_last_n.set(repeat_last_n);
- return this;
- }
-
- public Builder withContextErase(float context_erase) {
- configToBuild.context_erase.set(context_erase);
- return this;
- }
-
- /**
- *
- * @return GenerationConfig build instance of the config
- */
- public GenerationConfig build() {
- return configToBuild;
- }
- }
- }
-
- /**
- * Shortcut for making GenerativeConfig builder.
- *
- * @return GenerationConfig.Builder - builder that can be used to make a GenerationConfig
- */
- public static GenerationConfig.Builder config(){
- return new GenerationConfig.Builder();
- }
-
- /**
- * This may be set before any Model instance classes are instantiated to
- * set where the native shared libraries are to be found.
- *
- * This may be needed if setting library search path by standard means is not available
- * or the libraries loaded from the temp folder bundled with the binding jar is not desirable.
- */
- public static String LIBRARY_SEARCH_PATH;
-
-
- /**
- * Generally for debugging purposes only. Will print
- * the numerical tokens as they are generated instead of the string representations.
- * Will also print out the processed input tokens as numbers to standard out.
- */
- public static boolean OUTPUT_DEBUG = false;
-
- private static final Logger logger = LoggerFactory.getLogger(LLModel.class);
-
- /**
- * Which version of GPT4ALL that this binding is built for.
- * The binding is guaranteed to work with this version of
- * GPT4ALL native libraries. The binding may work for older
- * versions but that is not guaranteed.
- */
- public static final String GPT4ALL_VERSION = "2.4.11";
-
- protected static LLModelLibrary library;
-
- protected Pointer model;
-
- protected String modelName;
-
- /**
- * Package private default constructor, for testing purposes.
- */
- LLModel(){
- }
-
- public LLModel(Path modelPath) {
-
- logger.info("Java bindings for gpt4all version: " + GPT4ALL_VERSION);
-
- if(library==null) {
-
- if (LIBRARY_SEARCH_PATH != null){
- library = Util.loadSharedLibrary(LIBRARY_SEARCH_PATH);
- library.llmodel_set_implementation_search_path(LIBRARY_SEARCH_PATH);
- } else {
- // Copy system libraries to Temp folder
- Path tempLibraryDirectory = Util.copySharedLibraries();
- library = Util.loadSharedLibrary(tempLibraryDirectory.toString());
-
- library.llmodel_set_implementation_search_path(tempLibraryDirectory.toString() );
- }
-
- }
-
- // modelType = type;
- modelName = modelPath.getFileName().toString();
- String modelPathAbs = modelPath.toAbsolutePath().toString();
-
- PointerByReference error = new PointerByReference();
-
- // Check if model file exists
- if(!Files.exists(modelPath)){
- throw new IllegalStateException("Model file does not exist: " + modelPathAbs);
- }
-
- // Check if file is Readable
- if(!Files.isReadable(modelPath)){
- throw new IllegalStateException("Model file cannot be read: " + modelPathAbs);
- }
-
- // Create Model Struct. Will load dynamically the correct backend based on model type
- model = library.llmodel_model_create2(modelPathAbs, "auto", error);
-
- if(model == null) {
- throw new IllegalStateException("Could not load, gpt4all backend returned error: " + error.getValue().getString(0));
- }
- library.llmodel_loadModel(model, modelPathAbs, 2048, 100);
-
- if(!library.llmodel_isModelLoaded(model)){
- throw new IllegalStateException("The model " + modelName + " could not be loaded");
- }
-
- }
-
- public void setThreadCount(int nThreads) {
- library.llmodel_setThreadCount(this.model, nThreads);
- }
-
- public int threadCount() {
- return library.llmodel_threadCount(this.model);
- }
-
- /**
- * Generate text after the prompt
- *
- * @param prompt The text prompt to complete
- * @param generationConfig What generation settings to use while generating text
- * @return String The complete generated text
- */
- public String generate(String prompt, GenerationConfig generationConfig) {
- return generate(prompt, generationConfig, false);
- }
-
- /**
- * Generate text after the prompt
- *
- * @param prompt The text prompt to complete
- * @param generationConfig What generation settings to use while generating text
- * @param streamToStdOut Should the generation be streamed to standard output. Useful for troubleshooting.
- * @return String The complete generated text
- */
- public String generate(String prompt, GenerationConfig generationConfig, boolean streamToStdOut) {
-
- ByteArrayOutputStream bufferingForStdOutStream = new ByteArrayOutputStream();
- ByteArrayOutputStream bufferingForWholeGeneration = new ByteArrayOutputStream();
-
- LLModelLibrary.ResponseCallback responseCallback = getResponseCallback(streamToStdOut, bufferingForStdOutStream, bufferingForWholeGeneration);
-
- library.llmodel_prompt(this.model,
- prompt,
- (int tokenID) -> {
- if(LLModel.OUTPUT_DEBUG)
- System.out.println("token " + tokenID);
- return true; // continue processing
- },
- responseCallback,
- (boolean isRecalculating) -> {
- if(LLModel.OUTPUT_DEBUG)
- System.out.println("recalculating");
- return isRecalculating; // continue generating
- },
- generationConfig);
-
- return bufferingForWholeGeneration.toString(StandardCharsets.UTF_8);
- }
-
- /**
- * Callback method to be used by prompt method as text is generated.
- *
- * @param streamToStdOut Should send generated text to standard out.
- * @param bufferingForStdOutStream Output stream used for buffering bytes for standard output.
- * @param bufferingForWholeGeneration Output stream used for buffering a complete generation.
- * @return LLModelLibrary.ResponseCallback lambda function that is invoked by response callback.
- */
- static LLModelLibrary.ResponseCallback getResponseCallback(boolean streamToStdOut, ByteArrayOutputStream bufferingForStdOutStream, ByteArrayOutputStream bufferingForWholeGeneration) {
- return (int tokenID, Pointer response) -> {
-
- if(LLModel.OUTPUT_DEBUG)
- System.out.print("Response token " + tokenID + " " );
-
- // For all models if input sequence in tokens is longer then model context length
- // the error is generated.
- if(tokenID==-1){
- throw new PromptIsTooLongException(response.getString(0, 1000, StandardCharsets.UTF_8));
- }
-
- long len = 0;
- byte nextByte;
- do{
- try {
- nextByte = response.getByte(len);
- } catch(IndexOutOfBoundsException e){
- // Not sure if this can ever happen but just in case
- // the generation does not terminate in a Null (0) value.
- throw new RuntimeException("Empty array or not null terminated");
- }
- len++;
- if(nextByte!=0) {
- bufferingForWholeGeneration.write(nextByte);
- if(streamToStdOut){
- bufferingForStdOutStream.write(nextByte);
- // Test if Buffer is UTF8 valid string.
- byte[] currentBytes = bufferingForStdOutStream.toByteArray();
- String validString = Util.getValidUtf8(currentBytes);
- if(validString!=null){ // is valid string
- System.out.print(validString);
- // reset the buffer for next utf8 sequence to buffer
- bufferingForStdOutStream.reset();
- }
- }
- }
- } while(nextByte != 0);
-
- return true; // continue generating
- };
- }
-
- /**
- * The array of messages for the conversation.
- */
- public static class Messages {
-
- private final List messages = new ArrayList<>();
-
- public Messages(PromptMessage...messages) {
- this.messages.addAll(Arrays.asList(messages));
- }
-
- public Messages(List messages) {
- this.messages.addAll(messages);
- }
-
- public Messages addPromptMessage(PromptMessage promptMessage) {
- this.messages.add(promptMessage);
- return this;
- }
-
- List toList() {
- return Collections.unmodifiableList(this.messages);
- }
-
- List