forked from kherud/java-llama.cpp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGrammarExample.java
More file actions
26 lines (21 loc) · 757 Bytes
/
GrammarExample.java
File metadata and controls
26 lines (21 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package examples;
import net.ladenthin.llama.LlamaOutput;
import net.ladenthin.llama.ModelParameters;
import net.ladenthin.llama.InferenceParameters;
import net.ladenthin.llama.LlamaModel;
public class GrammarExample {
public static void main(String... args) {
String grammar = "root ::= (expr \"=\" term \"\\n\")+\n" +
"expr ::= term ([-+*/] term)*\n" +
"term ::= [0-9]";
ModelParameters modelParams = new ModelParameters()
.setModel("models/mistral-7b-instruct-v0.2.Q2_K.gguf");
InferenceParameters inferParams = new InferenceParameters("")
.setGrammar(grammar);
try (LlamaModel model = new LlamaModel(modelParams)) {
for (LlamaOutput output : model.generate(inferParams)) {
System.out.print(output);
}
}
}
}