Skip to content

Instantly share code, notes, and snippets.

@soudmaijer
Created July 17, 2023 13:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soudmaijer/99c0204251d4b4acd9cdcaebb1febe21 to your computer and use it in GitHub Desktop.
Save soudmaijer/99c0204251d4b4acd9cdcaebb1febe21 to your computer and use it in GitHub Desktop.
package nl.sourcelabs;
import com.hexadevlabs.gpt4all.LLModel;
import java.nio.file.Path;
import java.time.LocalDateTime;
public class Gpt4allJavaExample {
private String modelPath = "/Users/soudmaijer/gpt4all/models/ggml-gpt4all-j-v1.3-groovy.bin";
private LLModel model;
private LLModel.GenerationConfig config;
public Gpt4allJavaExample() {
model = new LLModel(Path.of(modelPath));
config = LLModel.config().withNPredict(4096).build();
}
public String qa(String prompt) {
System.out.println(LocalDateTime.now() + " - Q: "+ prompt);
String fullGeneration = model.generate(prompt, config, false);
System.out.println(LocalDateTime.now() +" - A: "+ fullGeneration);
return fullGeneration;
}
public static void main(String[] args) {
var gpt = new Gpt4allJavaExample();
gpt.qa("Give an example of a Spring rest controller");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment