From 405a08b330aed835c7f71ec7cb772ebbab051ddd Mon Sep 17 00:00:00 2001 From: Amith Koujalgi Date: Thu, 31 Oct 2024 16:25:05 +0530 Subject: [PATCH] Updated docs --- docs/docs/apis-generate/custom-roles.md | 62 +++++++++++++++++++ .../java/io/github/ollama4j/OllamaAPI.java | 18 +++++- 2 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 docs/docs/apis-generate/custom-roles.md diff --git a/docs/docs/apis-generate/custom-roles.md b/docs/docs/apis-generate/custom-roles.md new file mode 100644 index 0000000..7bf55f0 --- /dev/null +++ b/docs/docs/apis-generate/custom-roles.md @@ -0,0 +1,62 @@ +--- +sidebar_position: 8 +--- + +# Custom Roles + +Allows to manage custom roles (apart from the base roles) for chat interactions with the models. + +_Base roles are `SYSTEM`, `USER`, `ASSISTANT`, `TOOL`._ + +### Usage + +#### Add new role + +```java +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 + +```java +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 roles = ollamaAPI.listRoles(); + } +} +``` + +#### Get role + +```java +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 roles = ollamaAPI.getRole("custom-role"); + } +} +``` \ No newline at end of file diff --git a/src/main/java/io/github/ollama4j/OllamaAPI.java b/src/main/java/io/github/ollama4j/OllamaAPI.java index 3d3e05f..9b8d50b 100644 --- a/src/main/java/io/github/ollama4j/OllamaAPI.java +++ b/src/main/java/io/github/ollama4j/OllamaAPI.java @@ -635,24 +635,36 @@ public class OllamaAPI { } /** - * @param roleName - Custom role to be added - * @return OllamaChatMessageRole + * Adds a custom role. + * + * @param roleName the name of the custom role to be added + * @return the newly created OllamaChatMessageRole */ public OllamaChatMessageRole addCustomRole(String roleName) { return OllamaChatMessageRole.newCustomRole(roleName); } /** - * @return - available roles + * Lists all available roles. + * + * @return a list of available OllamaChatMessageRole objects */ public List listRoles() { return OllamaChatMessageRole.getRoles(); } + /** + * Retrieves a specific role by name. + * + * @param roleName the name of the role to retrieve + * @return the OllamaChatMessageRole associated with the given name + * @throws RoleNotFoundException if the role with the specified name does not exist + */ public OllamaChatMessageRole getRole(String roleName) throws RoleNotFoundException { return OllamaChatMessageRole.getRole(roleName); } + // technical private methods // private static String encodeFileToBase64(File file) throws IOException {