Files
ollama4j/docs/docs/apis-generate/custom-roles.md
Amith Koujalgi 3fc7e9423c Updated docs
2024-10-31 17:57:02 +05:30

1.4 KiB

sidebar_position
sidebar_position
8

Custom Roles

Allows to manage custom roles (apart from the base roles) for chat interactions with the models.

Particularly helpful when you would need to use different roles that the newer models support other than the base roles.

Base roles are SYSTEM, USER, ASSISTANT, TOOL.

Usage

Add new role

import io.github.ollama4j.OllamaAPI;
import io.github.ollama4j.models.chat.OllamaChatMessageRole;

public class Main {

    public static void main(String[] args) {
        String host = "http://localhost:11434/";
        OllamaAPI ollamaAPI = new OllamaAPI(host);

        OllamaChatMessageRole customRole = ollamaAPI.addCustomRole("custom-role");
    }
}

List roles

import io.github.ollama4j.OllamaAPI;
import io.github.ollama4j.models.chat.OllamaChatMessageRole;

public class Main {

    public static void main(String[] args) {
        String host = "http://localhost:11434/";
        OllamaAPI ollamaAPI = new OllamaAPI(host);

        List<OllamaChatMessageRole> roles = ollamaAPI.listRoles();
    }
}

Get role

import io.github.ollama4j.OllamaAPI;
import io.github.ollama4j.models.chat.OllamaChatMessageRole;

public class Main {

    public static void main(String[] args) {
        String host = "http://localhost:11434/";
        OllamaAPI ollamaAPI = new OllamaAPI(host);

        List<OllamaChatMessageRole> roles = ollamaAPI.getRole("custom-role");
    }
}