-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathChatExample.java
More file actions
35 lines (31 loc) · 1.37 KB
/
ChatExample.java
File metadata and controls
35 lines (31 loc) · 1.37 KB
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
27
28
29
30
31
32
33
34
35
package examples;
import de.kherud.llama.ChatMessage;
import de.kherud.llama.ChatRequest;
import de.kherud.llama.LlamaModel;
import de.kherud.llama.ModelParameters;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
public class ChatExample {
public static void main(String... args) throws Exception {
ModelParameters modelParams = new ModelParameters()
.setModel("models/codellama-7b.Q2_K.gguf")
.setGpuLayers(43);
try (LlamaModel model = new LlamaModel(modelParams)) {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
List<ChatMessage> messages = new ArrayList<>();
messages.add(new ChatMessage(ChatMessage.Role.SYSTEM, "You are a helpful assistant."));
while (true) {
System.out.print("User: ");
String input = reader.readLine();
messages.add(new ChatMessage(ChatMessage.Role.USER, input));
ChatRequest request = new ChatRequest(messages, false);
ChatMessage response = (ChatMessage) model.chat(request);
System.out.println("Assistant: " + response.getContent());
messages.add(response);
}
}
}
}