Ollama4j
A Java library (wrapper/binding) for Ollama server.
Loading...
Searching...
No Matches
OllamaChatMessageRole.java
Go to the documentation of this file.
1/*
2 * Ollama4j - Java library for interacting with Ollama server.
3 * Copyright (c) 2025 Amith Koujalgi and contributors.
4 *
5 * Licensed under the MIT License (the "License");
6 * you may not use this file except in compliance with the License.
7 *
8*/
9package io.github.ollama4j.models.chat;
10
11import com.fasterxml.jackson.annotation.JsonValue;
12import io.github.ollama4j.exceptions.RoleNotFoundException;
13import java.util.ArrayList;
14import java.util.List;
15import lombok.Getter;
16
20@Getter
22 private static final List<OllamaChatMessageRole> roles = new ArrayList<>();
23
24 public static final OllamaChatMessageRole SYSTEM = new OllamaChatMessageRole("system");
25 public static final OllamaChatMessageRole USER = new OllamaChatMessageRole("user");
26 public static final OllamaChatMessageRole ASSISTANT = new OllamaChatMessageRole("assistant");
27 public static final OllamaChatMessageRole TOOL = new OllamaChatMessageRole("tool");
28
29 @JsonValue private final String roleName;
30
31 private OllamaChatMessageRole(String roleName) {
32 this.roleName = roleName;
33 roles.add(this);
34 }
35
36 public static OllamaChatMessageRole newCustomRole(String roleName) {
37 return new OllamaChatMessageRole(roleName);
38 }
39
40 public static List<OllamaChatMessageRole> getRoles() {
41 return new ArrayList<>(roles);
42 }
43
44 public static OllamaChatMessageRole getRole(String roleName) throws RoleNotFoundException {
45 for (OllamaChatMessageRole role : roles) {
46 if (role.roleName.equals(roleName)) {
47 return role;
48 }
49 }
50 throw new RoleNotFoundException("Invalid role name: " + roleName);
51 }
52
53 @Override
54 public String toString() {
55 return roleName;
56 }
57}
static OllamaChatMessageRole newCustomRole(String roleName)
static OllamaChatMessageRole getRole(String roleName)