Created
July 17, 2023 13:44
-
-
Save soudmaijer/99c0204251d4b4acd9cdcaebb1febe21 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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