You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To add the library dependency for another build system see [Maven Central Java bindings](https://central.sonatype.com/artifact/com.hexadevlabs/gpt4all-java-binding/).
24
+
25
+
To download a model binary weights file use an url such as https://gpt4all.io/models/ggml-gpt4all-j-v1.3-groovy.bin.
26
+
27
+
For information about other models available see [Model file list](https://github.com/nomic-ai/gpt4all/tree/main/gpt4all-chat#manual-download-of-models).
28
+
29
+
### Sample code
30
+
```java
31
+
publicclassExample {
32
+
publicstaticvoidmain(String[] args) {
33
+
34
+
String prompt ="### Human:\nWhat is the meaning of life\n### Assistant:";
35
+
36
+
// Replace the hardcoded path with the actual path where your model file resides
// Exception generally may happen if model file fails to load
50
+
// for a number of reasons such as file not found.
51
+
// It is possible that Java may not be able to dynamically load the native shared library or
52
+
// the llmodel shared library may not be able to dynamically load the backend
53
+
// implementation for the model file you provided.
54
+
//
55
+
// Once the LLModel class is successfully loaded into memory the text generation calls
56
+
// generally should not throw exceptions.
57
+
e.printStackTrace(); // Printing here but in production system you may want to take some action.
58
+
}
59
+
}
60
+
61
+
}
62
+
```
63
+
64
+
For a maven based sample project that uses this library see [Sample project](https://github.com/felix-zaslavskiy/gpt4all-java-bindings-sample)
65
+
66
+
### Additional considerations
67
+
#### Logger warnings
68
+
The Java bindings library may produce a warning:
69
+
```
70
+
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
71
+
SLF4J: Defaulting to no-operation (NOP) logger implementation
72
+
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
73
+
```
74
+
If you don't have a SLF4J binding included in your project. Java bindings only use logging for informational
75
+
purposes, so logger is not essential to correctly use the library. You can ignore this warning if you don't have SLF4J bindings
76
+
in your project.
77
+
78
+
To add a simple logger using maven dependency you may use:
79
+
```
80
+
<dependency>
81
+
<groupId>org.slf4j</groupId>
82
+
<artifactId>slf4j-simple</artifactId>
83
+
<version>1.7.36</version>
84
+
</dependency>
85
+
```
86
+
87
+
#### Loading your native libraries
88
+
1. Java bindings package jar comes bundled with native library files for Windows, macOS and Linux. These library files are
89
+
copied to a temporary directory and loaded at runtime. For advanced users who may want to package shared libraries into Docker containers
90
+
or want to use a custom build of the shared libraries and ignore the once bundled with the java package they have option
91
+
to load libraries from your local directory by setting a static property to the location of library files.
92
+
There are no guarantees of compatibility if used in such a way so be careful if you really want to do it.
0 commit comments