Ollama4j
A Java library (wrapper/binding) for Ollama server.
Loading...
Searching...
No Matches
OllamaChatMessageRole.java
Go to the documentation of this file.
1package io.github.ollama4j.models.chat;
2
3import com.fasterxml.jackson.annotation.JsonValue;
4import io.github.ollama4j.exceptions.RoleNotFoundException;
5import lombok.Getter;
6
7import java.util.ArrayList;
8import java.util.List;
9
13@Getter
15 private static final List<OllamaChatMessageRole> roles = new ArrayList<>();
16
17 public static final OllamaChatMessageRole SYSTEM = new OllamaChatMessageRole("system");
18 public static final OllamaChatMessageRole USER = new OllamaChatMessageRole("user");
19 public static final OllamaChatMessageRole ASSISTANT = new OllamaChatMessageRole("assistant");
20 public static final OllamaChatMessageRole TOOL = new OllamaChatMessageRole("tool");
21
22 @JsonValue
23 private final String roleName;
24
25 private OllamaChatMessageRole(String roleName) {
26 this.roleName = roleName;
27 roles.add(this);
28 }
29
30 public static OllamaChatMessageRole newCustomRole(String roleName) {
31 OllamaChatMessageRole customRole = new OllamaChatMessageRole(roleName);
32 roles.add(customRole);
33 return customRole;
34 }
35
36 public static List<OllamaChatMessageRole> getRoles() {
37 return new ArrayList<>(roles);
38 }
39
40 public static OllamaChatMessageRole getRole(String roleName) throws RoleNotFoundException {
41 for (OllamaChatMessageRole role : roles) {
42 if (role.roleName.equals(roleName)) {
43 return role;
44 }
45 }
46 throw new RoleNotFoundException("Invalid role name: " + roleName);
47 }
48
49 @Override
50 public String toString() {
51 return roleName;
52 }
53}
static OllamaChatMessageRole newCustomRole(String roleName)
static OllamaChatMessageRole getRole(String roleName)