mirror of
https://github.com/amithkoujalgi/ollama4j.git
synced 2025-05-14 19:37:11 +02:00
Updated docs
This commit is contained in:
parent
921f745435
commit
405a08b330
62
docs/docs/apis-generate/custom-roles.md
Normal file
62
docs/docs/apis-generate/custom-roles.md
Normal file
@ -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<OllamaChatMessageRole> 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<OllamaChatMessageRole> roles = ollamaAPI.getRole("custom-role");
|
||||
}
|
||||
}
|
||||
```
|
@ -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<OllamaChatMessageRole> 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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user