refactor: update CoreMemory to v2 and rename OllamaToolResponse
build / build (push) Has been cancelled

- Refactored `CoreMemory` to support versioning (v2) and dual-memory types: `MAPPED_MEMORY` (key-value) and `ARRAYED_MEMORY` (sequential).
- Added automatic migration logic for v1 memory files to v2.
- Introduced new memory tools: `AddArrayMemory`, `GetArrayMemory`, and `GetArrayedMemories`.
- Renamed `OllamaToolRespnce` to `OllamaToolResponse` and added `empty()` factory methods for better error handling.
- Updated multiple function tools (e.g., `GetMemoryFunction`, `GetMemoriesFunction`, `APITool`, `GetWikiPageText`) to use the new `OllamaToolResponse` and `Optional`-based memory retrieval.
- Improved null safety by adding `@NotNull` annotations to tool implementations.
This commit is contained in:
2026-05-27 21:10:15 +02:00
parent ac159c2498
commit 931c274cd3
27 changed files with 331 additions and 113 deletions
@@ -6,7 +6,7 @@ import me.zacharias.chat.api.payload.webhook.responce.APIToolResponse;
import me.zacharias.chat.ollama.OllamaFunctionArgument;
import me.zacharias.chat.ollama.OllamaFunctionTool;
import me.zacharias.chat.ollama.OllamaPerameter;
import me.zacharias.chat.ollama.OllamaToolRespnce;
import me.zacharias.chat.ollama.OllamaToolResponse;
import me.zacharias.chat.ollama.exceptions.OllamaToolErrorException;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NonNull;
@@ -66,7 +66,7 @@ public class APITool extends OllamaFunctionTool {
}
@Override
public OllamaToolRespnce function(OllamaFunctionArgument... args) {
public @NonNull OllamaToolResponse function(OllamaFunctionArgument... args) {
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(requestUrl);
for (OllamaFunctionArgument arg : args) {
builder.queryParam(arg.argument(), arg.value());
@@ -82,7 +82,7 @@ public class APITool extends OllamaFunctionTool {
if(response.getBody().getError() != null && !response.getBody().getError().isEmpty())
throw new OllamaToolErrorException(name, response.getBody().getError());
return new OllamaToolRespnce(name, response.getBody().getResponse());
return new OllamaToolResponse(name, response.getBody().getResponse());
}
else {
if(response.getBody() == null) {
@@ -3,7 +3,6 @@ package me.zacharias.chat.core;
import me.zacharias.chat.core.memory.*;
import me.zacharias.chat.ollama.*;
import me.zacharias.chat.ollama.exceptions.OllamaToolErrorException;
import me.zacharias.chat.plugin.Plugin;
import me.zacharias.chat.plugin.loader.Loader;
import me.zacharias.chat.plugin.exceptions.PluginLoadingException;
import org.intellij.lang.annotations.MagicConstant;
@@ -472,7 +471,7 @@ public class Core {
// TODO: Check so all arguments is the correct type, else error out in a safe mannet.
try {
OllamaToolRespnce function1 = func.function(argumentArrayList.toArray(new OllamaFunctionArgument[0]));
OllamaToolResponse function1 = func.function(argumentArrayList.toArray(new OllamaFunctionArgument[0]));
ollamaObject.addMessage(function1);
printMessageHandler.printMessage(function1);
writeLog("Successfully function call " + func.name() + " output: " + function1.getResponse());
@@ -4,7 +4,7 @@ import me.zacharias.chat.core.files.FileHandler;
import me.zacharias.chat.ollama.OllamaFunctionArgument;
import me.zacharias.chat.ollama.OllamaFunctionTool;
import me.zacharias.chat.ollama.OllamaPerameter;
import me.zacharias.chat.ollama.OllamaToolRespnce;
import me.zacharias.chat.ollama.OllamaToolResponse;
import me.zacharias.chat.ollama.exceptions.OllamaToolErrorException;
import org.jetbrains.annotations.NotNull;
@@ -31,7 +31,7 @@ public class ReadFileTool extends OllamaFunctionTool {
}
@Override
public OllamaToolRespnce function(OllamaFunctionArgument... args) {
public @NotNull OllamaToolResponse function(OllamaFunctionArgument... args) {
String orgPath = null;
for (OllamaFunctionArgument arg : args) {
if(arg.argument().equals("file_path")) {
@@ -73,6 +73,6 @@ public class ReadFileTool extends OllamaFunctionTool {
catch (IOException e) {
throw new OllamaToolErrorException(this.name(), "Error reading file: " + fs.path(file));
}
return new OllamaToolRespnce(this.name(), sb.toString());
return new OllamaToolResponse(this.name(), sb.toString());
}
}
@@ -3,7 +3,7 @@ package me.zacharias.chat.core.memory;
import me.zacharias.chat.ollama.OllamaFunctionArgument;
import me.zacharias.chat.ollama.OllamaFunctionTool;
import me.zacharias.chat.ollama.OllamaPerameter;
import me.zacharias.chat.ollama.OllamaToolRespnce;
import me.zacharias.chat.ollama.OllamaToolResponse;
import me.zacharias.chat.ollama.exceptions.OllamaToolErrorException;
import org.jetbrains.annotations.NotNull;
@@ -36,7 +36,7 @@ public class AddMemoryFunction extends OllamaFunctionTool {
}
@Override
public OllamaToolRespnce function(OllamaFunctionArgument... args) {
public @NotNull OllamaToolResponse function(OllamaFunctionArgument... args) {
if (args.length == 0) {
throw new OllamaToolErrorException(name(), "Missing memory argument");
}
@@ -59,6 +59,6 @@ public class AddMemoryFunction extends OllamaFunctionTool {
}
this.memory.addMemory(identity, memory);
return new OllamaToolRespnce(name(), "Added "+identity+" to the memory");
return new OllamaToolResponse(name(), "Added "+identity+" to the memory");
}
}
@@ -6,17 +6,29 @@ import org.json.JSONObject;
import java.io.*;
import java.util.ArrayList;
import java.util.Optional;
/**
* CoreMemory is a class that provides a way to store and retrieve strings from a file.<br>
* This is meant to be used as a way to store and retrieve strings from a file.
*/
public class CoreMemory {
public static final int VERSION = 2;
/**
* The singleton instance of CoreMemory.
*/
private static final CoreMemory instance = new CoreMemory(Core.DATA + "/CoreMemory.json");
/**
* Memory type identifier for key-value mapped memory storage.
*/
public static final String MAPPED_MEMORY = "mapped_memory";
/**
* Memory type identifier for sequential/array-based memory storage.
*/
public static final String ARRAYED_MEMORY = "arrayed_memory";
/**
* Gets the singleton instance of CoreMemory.
* @return The singleton instance of CoreMemory
@@ -30,6 +42,9 @@ public class CoreMemory {
* @param memoryFile The file to store the memory in
*/
public CoreMemory(String memoryFile) {
// Since version 2, version 1(un versiond) memory files are incompadible, and will be refectored
File f = new File(memoryFile);
if (f.exists()) {
try {
@@ -39,7 +54,18 @@ public class CoreMemory {
while ((buffer = br.readLine()) != null) {
data.append(buffer);
}
memory = new JSONObject(data.toString());
JSONObject tmpMemory = new JSONObject(data.toString());
if(tmpMemory.optInt("VERSION", 0) == 0)
{
memory = new JSONObject();
memory.put("VERSION", VERSION);
memory.put(MAPPED_MEMORY, tmpMemory);
memory.put(ARRAYED_MEMORY, new JSONArray());
}
else
{
memory = tmpMemory;
}
}catch (Exception e) {
e.printStackTrace();
}
@@ -82,11 +108,11 @@ public class CoreMemory {
* @return A list of memory identifies/names
*/
public String[] getMemoriesIdentity() {
return memory.keySet().toArray(new String[0]);
return memory.getJSONObject(MAPPED_MEMORY).keySet().toArray(new String[0]);
}
public String getMemory(String name) {
return memory.optString(name, null);
public Optional<String> getMemory(String name) {
return Optional.ofNullable(memory.getJSONObject(MAPPED_MEMORY).optString(name, null));
}
/**
@@ -95,7 +121,7 @@ public class CoreMemory {
* @param memory The memory
*/
public void addMemory(String name, String memory) {
this.memory.put(name, memory);
this.memory.getJSONObject(MAPPED_MEMORY).put(name, memory);
}
/**
@@ -103,14 +129,53 @@ public class CoreMemory {
* @param name The memory to remove
*/
public void removeMemory(String name) {
this.memory.remove(name);
this.memory.getJSONObject(MAPPED_MEMORY).remove(name);
}
/**
* Add an array-based memory
* @param memory The memory to remember
*/
public void addMemory(String memory)
{
this.memory.getJSONArray(ARRAYED_MEMORY).put(memory);
}
/**
* Add an array-based memory
* @param memory The memory to remember
* @param index The index to put it at
* @apiNote Prefer {@link #addMemory(String)} unless there is a reason to use this one.
*/
public void addMemory(String memory, int index)
{
this.memory.getJSONArray(ARRAYED_MEMORY).put(index, memory);
}
/**
* Get all array-stored memories
* @return An array of all array-based memories
*/
public JSONArray getArrayMemories()
{
return memory.getJSONArray(ARRAYED_MEMORY);
}
/**
* Get the array-based memory at index
* @param index The memory to retrieve
* @return The memory stored at index
*/
public Optional<String> getMemory(int index)
{
return Optional.ofNullable(memory.getJSONArray(ARRAYED_MEMORY).optString(index, null));
}
/**
* Gets all memories as a JSON string.
* @return A JSON string of all memories
*/
public String getMemories() {
public String getMappedMemories() {
ArrayList<String> memories = new ArrayList<>();
for (String key : memory.keySet()) {
memories.add(key + ": " + memory.getString(key));
@@ -3,7 +3,7 @@ package me.zacharias.chat.core.memory;
import me.zacharias.chat.ollama.OllamaFunctionArgument;
import me.zacharias.chat.ollama.OllamaFunctionTool;
import me.zacharias.chat.ollama.OllamaPerameter;
import me.zacharias.chat.ollama.OllamaToolRespnce;
import me.zacharias.chat.ollama.OllamaToolResponse;
import org.jetbrains.annotations.NotNull;
public class GetMemoriesFunction extends OllamaFunctionTool {
@@ -23,7 +23,7 @@ public class GetMemoriesFunction extends OllamaFunctionTool {
}
@Override
public OllamaToolRespnce function(OllamaFunctionArgument... args) {
return new OllamaToolRespnce(name(), CoreMemory.getInstance().getMemories());
public @NotNull OllamaToolResponse function(OllamaFunctionArgument... args) {
return new OllamaToolResponse(name(), CoreMemory.getInstance().getMappedMemories());
}
}
@@ -3,7 +3,7 @@ package me.zacharias.chat.core.memory;
import me.zacharias.chat.ollama.OllamaFunctionArgument;
import me.zacharias.chat.ollama.OllamaFunctionTool;
import me.zacharias.chat.ollama.OllamaPerameter;
import me.zacharias.chat.ollama.OllamaToolRespnce;
import me.zacharias.chat.ollama.OllamaToolResponse;
import org.jetbrains.annotations.NotNull;
/**
@@ -34,7 +34,9 @@ public class GetMemoryFunction extends OllamaFunctionTool {
}
@Override
public OllamaToolRespnce function(OllamaFunctionArgument... args) {
return new OllamaToolRespnce(name(), memory.getMemory((String) (args[0].value())));
public @NotNull OllamaToolResponse function(OllamaFunctionArgument... args) {
return memory.getMemory((String) (args[0].value()))
.map(value -> new OllamaToolResponse(name(), value))
.orElse(OllamaToolResponse.empty("No memory found for key: " + args[0].value()));
}
}
@@ -3,7 +3,7 @@ package me.zacharias.chat.core.memory;
import me.zacharias.chat.ollama.OllamaFunctionArgument;
import me.zacharias.chat.ollama.OllamaFunctionTool;
import me.zacharias.chat.ollama.OllamaPerameter;
import me.zacharias.chat.ollama.OllamaToolRespnce;
import me.zacharias.chat.ollama.OllamaToolResponse;
import org.jetbrains.annotations.NotNull;
import org.json.JSONArray;
@@ -26,7 +26,7 @@ public class GetMemoryIdentitiesFunction extends OllamaFunctionTool {
}
@Override
public OllamaToolRespnce function(OllamaFunctionArgument... args) {
return new OllamaToolRespnce(this.name(), new JSONArray(memory.getMemoriesIdentity()).toString());
public @NotNull OllamaToolResponse function(OllamaFunctionArgument... args) {
return new OllamaToolResponse(this.name(), new JSONArray(memory.getMemoriesIdentity()).toString());
}
}
@@ -3,7 +3,7 @@ package me.zacharias.chat.core.memory;
import me.zacharias.chat.ollama.OllamaFunctionArgument;
import me.zacharias.chat.ollama.OllamaFunctionTool;
import me.zacharias.chat.ollama.OllamaPerameter;
import me.zacharias.chat.ollama.OllamaToolRespnce;
import me.zacharias.chat.ollama.OllamaToolResponse;
import me.zacharias.chat.ollama.exceptions.OllamaToolErrorException;
import org.jetbrains.annotations.NotNull;
@@ -35,12 +35,12 @@ public class RemoveMemoryFunction extends OllamaFunctionTool {
}
@Override
public OllamaToolRespnce function(OllamaFunctionArgument... args) {
public @NotNull OllamaToolResponse function(OllamaFunctionArgument... args) {
if (args.length == 0) {
throw new OllamaToolErrorException(name(), "Missing memory argument");
}
String value = (String) args[0].value();
memory.removeMemory(value);
return new OllamaToolRespnce(name(), "Removed "+value+" to the memory");
return new OllamaToolResponse(name(), "Removed "+value+" to the memory");
}
}
@@ -0,0 +1,55 @@
package me.zacharias.chat.core.memory.array;
import me.zacharias.chat.core.memory.CoreMemory;
import me.zacharias.chat.ollama.OllamaFunctionArgument;
import me.zacharias.chat.ollama.OllamaFunctionTool;
import me.zacharias.chat.ollama.OllamaPerameter;
import me.zacharias.chat.ollama.OllamaPerameter.OllamaPerameterBuilder.Type;
import me.zacharias.chat.ollama.OllamaToolResponse;
import me.zacharias.chat.ollama.exceptions.OllamaToolErrorException;
import org.jetbrains.annotations.NotNull;
public class AddArrayMemory extends OllamaFunctionTool {
private CoreMemory memory = CoreMemory.getInstance();
@Override
public @NotNull String name() {
return "add_arrayed_memory";
}
@Override
public @NotNull OllamaPerameter parameters() {
return OllamaPerameter.builder()
.addProperty("memory", Type.STRING, "The memory to remember", true)
.addProperty("index", Type.INT, "The index to put it at. Should be avoided, unless overwriting", false)
.build();
}
@Override
public @NotNull OllamaToolResponse function(OllamaFunctionArgument... args) {
if (args.length > 1) {
String memory = null;
int index = -1;
for (OllamaFunctionArgument arg : args) {
if(arg.argument().equals("memory")) {
memory = (String) arg.value();
}
else if(arg.argument().equals("index")) {
index = (Integer) arg.value();
}
}
if (memory == null || index < 0) {
throw new OllamaToolErrorException(name(), "no memory or index provided");
}
this.memory.addMemory(memory, index);
}
else {
if(!args[0].argument().equals("memory")) {
throw new OllamaToolErrorException(name(), "no memory provided");
}
this.memory.addMemory(name(), args[0].argument());
}
return new OllamaToolResponse(name(), "Added arrayed memory");
}
}
@@ -0,0 +1,36 @@
package me.zacharias.chat.core.memory.array;
import me.zacharias.chat.core.memory.CoreMemory;
import me.zacharias.chat.ollama.OllamaFunctionArgument;
import me.zacharias.chat.ollama.OllamaFunctionTool;
import me.zacharias.chat.ollama.OllamaPerameter;
import me.zacharias.chat.ollama.OllamaToolResponse;
import me.zacharias.chat.ollama.OllamaPerameter.OllamaPerameterBuilder.Type;
import org.jetbrains.annotations.NotNull;
public class GetArrayMemory extends OllamaFunctionTool {
CoreMemory memory = CoreMemory.getInstance();
@Override
public @NotNull String name() {
return "get_array_memory";
}
@Override
public @NotNull OllamaPerameter parameters() {
return OllamaPerameter.builder()
.addProperty("index", Type.STRING, "The index to retrieve memory from", false)
.build();
}
@Override
public @NotNull OllamaToolResponse function(OllamaFunctionArgument... args) {
if (args.length != 1) {
return new OllamaToolResponse(name(), memory.getArrayMemories().toString());
}
return memory.getMemory((Integer) args[0].value())
.map(value -> new OllamaToolResponse(name(), value))
.orElse(OllamaToolResponse.empty("No memory found for key: " + args[0].value()));
}
}
@@ -0,0 +1,26 @@
package me.zacharias.chat.core.memory.array;
import me.zacharias.chat.core.memory.CoreMemory;
import me.zacharias.chat.ollama.OllamaFunctionArgument;
import me.zacharias.chat.ollama.OllamaFunctionTool;
import me.zacharias.chat.ollama.OllamaPerameter;
import me.zacharias.chat.ollama.OllamaToolResponse;
import org.jetbrains.annotations.NotNull;
public class GetArrayedMemories extends OllamaFunctionTool {
private CoreMemory memory = CoreMemory.getInstance();
@Override
public @NotNull String name() {
return "get_arrayed_memories";
}
@Override
public @NotNull OllamaPerameter parameters() {
return OllamaPerameter.empty();
}
@Override
public @NotNull OllamaToolResponse function(OllamaFunctionArgument... args) {
return new OllamaToolResponse(name(), memory.getArrayMemories().toString());
}
}
@@ -66,8 +66,8 @@ public abstract class OllamaFunctionTool implements OllamaTool {
* This is used by Ollama to call the tool.<br>
* Throw {@link OllamaToolErrorException} if the tool encounters an error instead of normal exceptions. The {@link OllamaToolErrorException} gets handled more gracefully by {@link Core#handleResponce(JSONObject)}
* @param args The arguments to pass to the tool, if any
* @return The response from the tool
* @return The response from the tool, if null return {@link OllamaToolResponse}
* @throws OllamaToolErrorException If the tool encounters an error
*/
abstract public OllamaToolRespnce function(OllamaFunctionArgument... args);
abstract public @NotNull OllamaToolResponse function(OllamaFunctionArgument... args);
}
@@ -65,6 +65,18 @@ public class OllamaPerameter {
public static OllamaPerameterBuilder builder() {
return new OllamaPerameterBuilder();
}
/**
* Creates an empty {@link OllamaPerameter}
* @return an empty {@link OllamaPerameter}
* @apiNote This is equvalent to
* <pre>{@code
* OllamaPerameter.builder().build();
* }</pre>
*/
public static OllamaPerameter empty() {
return builder().build();
}
/**
* Represents a builder for {@link OllamaPerameter}.
@@ -85,13 +97,10 @@ public class OllamaPerameter {
* @param type The type of the parameter
* @param description The description of the parameter
* @return The {@link OllamaPerameterBuilder}
* @apiNote Prefer {@link #addProperty(String, Type, String, boolean)} to be explicit about required state
*/
public OllamaPerameterBuilder addProperty(String name, Type type, String description) {
if(name == null || type == null || description == null) {
return this;
}
propertyMap.put(name, new Property(type.getType(), description));
return this;
return OllamaPerameterBuilder.this.addProperty(name, type, description, false);
}
/**
@@ -1,44 +0,0 @@
package me.zacharias.chat.ollama;
import org.json.JSONObject;
/**
* Represents a response from a tool.
*/
public class OllamaToolRespnce extends OllamaMessage {
/**
* The tool that responded.
*/
private final String tool;
/**
* The response from the tool.
*/
private final String response;
/**
* Creates a new instance of {@link OllamaToolRespnce}.
* @param tool The tool that responded
* @param response The response from the tool
*/
public OllamaToolRespnce(String tool, String response) {
super(OllamaMessageRole.TOOL, new JSONObject().put("tool", tool).put("result", response).toString());
this.tool = tool;
this.response = response;
}
/**
* Gets the tool that responded.
* @return The tool that responded
*/
public String getTool() {
return tool;
}
/**
* Gets the response from the tool.
* @return The response from the tool
*/
public String getResponse() {
return response;
}
}
@@ -0,0 +1,68 @@
package me.zacharias.chat.ollama;
import org.json.JSONObject;
/**
* Represents a response from a tool.
*/
public class OllamaToolResponse extends OllamaMessage {
/**
* Returns an empty tool response
* See {@link OllamaToolResponse#empty(String, String)} for a reasoned/described response
* @param tool The tool that responded
* @return an empty tool response
*/
public static OllamaToolResponse empty(String tool)
{
return empty(tool, "No reason provided");
}
/**
* Returns an empty tool response with a reason/description.
* See {@link OllamaToolResponse#empty(String)} for reason/description less response
* @param tool The tool that responded
* @param description A description for why this is empty
* @return an empty tool response with a reason
*/
public static OllamaToolResponse empty(String tool, String description)
{
return new OllamaToolResponse(tool, "Empty! reason: " + description);
}
/**
* The tool that responded.
*/
private final String tool;
/**
* The response from the tool.
*/
private final String response;
/**
* Creates a new instance of {@link OllamaToolResponse}.
* @param tool The tool that responded
* @param response The response from the tool
*/
public OllamaToolResponse(String tool, String response) {
super(OllamaMessageRole.TOOL, new JSONObject().put("tool", tool).put("result", response).toString());
this.tool = tool;
this.response = response;
}
/**
* Gets the tool that responded.
* @return The tool that responded
*/
public String getTool() {
return tool;
}
/**
* Gets the response from the tool.
* @return The response from the tool
*/
public String getResponse() {
return response;
}
}
@@ -41,7 +41,7 @@ public class Loader {
}
@Override
public OllamaToolRespnce function(OllamaFunctionArgument... args) {
public @NotNull OllamaToolResponse function(OllamaFunctionArgument... args) {
// Wrap OllamaFunctionArguments[] to ether ToolArgument[] or ToolArguments(current implementation)
try {
ToolResponse toolResponse = tool.callTool(null);
+4 -2
View File
@@ -1,9 +1,11 @@
package plugin;
//// This class is broken due to the current refactoring on the RPCP part of this project.
import me.zacharias.chat.ollama.OllamaFunctionArgument;
import me.zacharias.chat.ollama.OllamaFunctionTool;
import me.zacharias.chat.ollama.OllamaPerameter;
import me.zacharias.chat.ollama.OllamaToolRespnce;
import me.zacharias.chat.ollama.OllamaToolResponse;
import me.zacharias.chat.plugin.annotation.OllamaTool;
import me.zacharias.chat.plugin.annotation.injectons.InjectPlugin;
import org.jetbrains.annotations.NotNull;
@@ -29,7 +31,7 @@ public class Tool extends OllamaFunctionTool {
}
@Override
public OllamaToolRespnce function(OllamaFunctionArgument... args) {
public @NotNull OllamaToolResponse function(OllamaFunctionArgument... args) {
return null;
}
}
@@ -283,10 +283,10 @@ public class PythonRunner extends OllamaFunctionTool {
}
@Override
public OllamaToolRespnce function(OllamaFunctionArgument... args) {
public @NonNull OllamaToolResponse function(OllamaFunctionArgument... args) {
if(dockerClient == null)
{
return new OllamaToolRespnce(name(), "Docker is disabled");
return new OllamaToolResponse(name(), "Docker is disabled");
}
if(args.length == 0)
{
@@ -442,7 +442,7 @@ public class PythonRunner extends OllamaFunctionTool {
dockerClient.removeContainerCmd(containerId).exec();
return new OllamaToolRespnce(name(), output.isEmpty() ? "Code ran successfully with no output" : output);
return new OllamaToolResponse(name(), output.isEmpty() ? "Code ran successfully with no output" : output);
}
catch (Exception e) {
throw new OllamaToolErrorException(name(), "Docker unavailable");
@@ -3,7 +3,7 @@ package me.zacharias.chat.display;
import me.zacharias.chat.ollama.OllamaFunctionArgument;
import me.zacharias.chat.ollama.OllamaFunctionTool;
import me.zacharias.chat.ollama.OllamaPerameter;
import me.zacharias.chat.ollama.OllamaToolRespnce;
import me.zacharias.chat.ollama.OllamaToolResponse;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NonNull;
@@ -16,9 +16,9 @@ import java.util.Date;
public class TimeTool extends OllamaFunctionTool {
@Override
public OllamaToolRespnce function(OllamaFunctionArgument... arguments) {
public @NonNull OllamaToolResponse function(OllamaFunctionArgument... arguments) {
Date date = new Date();
return new OllamaToolRespnce(name(), date.toString());
return new OllamaToolResponse(name(), date.toString());
}
@Override
@@ -2,7 +2,7 @@ package me.zacharias.neuro.dock.genius.endpoints;
import me.zacharias.chat.ollama.OllamaFunctionArgument;
import me.zacharias.chat.ollama.OllamaPerameter;
import me.zacharias.chat.ollama.OllamaToolRespnce;
import me.zacharias.chat.ollama.OllamaToolResponse;
import me.zacharias.chat.ollama.exceptions.OllamaToolErrorException;
import me.zacharias.neuro.dock.genius.GeniusEndpoint;
import me.zacharias.neuro.dock.genius.GeniusEndpointTool;
@@ -39,7 +39,7 @@ public class FindSong extends GeniusEndpointTool {
}
@Override
public OllamaToolRespnce function(OllamaFunctionArgument... args) {
public @NotNull OllamaToolResponse function(OllamaFunctionArgument... args) {
String title = (String) args[0].value();
if (title == null || title.isEmpty()) {
throw new OllamaToolErrorException(this.name(), "Title cannot be null or empty.");
@@ -64,6 +64,6 @@ public class FindSong extends GeniusEndpointTool {
throw new OllamaToolErrorException(this.name(), "No songs found for the given title.");
}
return new OllamaToolRespnce(this.name(), responseData.toString());
return new OllamaToolResponse(this.name(), responseData.toString());
}
}
@@ -2,7 +2,7 @@ package me.zacharias.neuro.dock.genius.endpoints;
import me.zacharias.chat.ollama.OllamaFunctionArgument;
import me.zacharias.chat.ollama.OllamaPerameter;
import me.zacharias.chat.ollama.OllamaToolRespnce;
import me.zacharias.chat.ollama.OllamaToolResponse;
import me.zacharias.chat.ollama.exceptions.OllamaToolErrorException;
import me.zacharias.neuro.dock.genius.GeniusEndpoint;
import me.zacharias.neuro.dock.genius.GeniusEndpointTool;
@@ -56,7 +56,7 @@ public class GetLyrics extends GeniusEndpointTool {
}
@Override
public OllamaToolRespnce function(OllamaFunctionArgument... args) {
public @NotNull OllamaToolResponse function(OllamaFunctionArgument... args) {
if(!( args[0].value() instanceof Integer)) {
throw new OllamaToolErrorException(this.name(), "The song_id must be an integer.");
@@ -66,7 +66,7 @@ public class GetLyrics extends GeniusEndpointTool {
if(lyricsStr != null)
{
return new OllamaToolRespnce(this.name(), lyricsStr.trim());
return new OllamaToolResponse(this.name(), lyricsStr.trim());
}
JSONObject obj = geniusToolsInstance.getGeniusEndpoint("/songs/" + args[0].value(), null);
@@ -116,7 +116,7 @@ public class GetLyrics extends GeniusEndpointTool {
geniusToolsInstance.cacheLyrics((int) args[0].value(), lyrics.toString());
return new OllamaToolRespnce(this.name(), lyrics.toString().trim());
return new OllamaToolResponse(this.name(), lyrics.toString().trim());
}catch (Exception ex)
{
ex.printStackTrace();
@@ -5,7 +5,7 @@ import me.zacharias.chat.mal.api.MALEndpoint;
import me.zacharias.chat.mal.api.MALEndpointTool;
import me.zacharias.chat.ollama.OllamaFunctionArgument;
import me.zacharias.chat.ollama.OllamaPerameter;
import me.zacharias.chat.ollama.OllamaToolRespnce;
import me.zacharias.chat.ollama.OllamaToolResponse;
import me.zacharias.chat.ollama.exceptions.OllamaToolErrorException;
import org.jetbrains.annotations.NotNull;
import org.json.JSONArray;
@@ -38,7 +38,7 @@ public class GetAnimeDetails extends MALEndpointTool {
}
@Override
public OllamaToolRespnce function(OllamaFunctionArgument... args) {
public @NotNull OllamaToolResponse function(OllamaFunctionArgument... args) {
int id = -1;
String[] fields = null;
@@ -81,6 +81,6 @@ public class GetAnimeDetails extends MALEndpointTool {
JSONObject obj = MALAPIToolInstance.APIRequest("/anime/"+id, map);
return new OllamaToolRespnce(this.name(), obj.toString());
return new OllamaToolResponse(this.name(), obj.toString());
}
}
@@ -5,7 +5,7 @@ import me.zacharias.chat.mal.api.MALEndpoint;
import me.zacharias.chat.mal.api.MALEndpointTool;
import me.zacharias.chat.ollama.OllamaFunctionArgument;
import me.zacharias.chat.ollama.OllamaPerameter;
import me.zacharias.chat.ollama.OllamaToolRespnce;
import me.zacharias.chat.ollama.OllamaToolResponse;
import me.zacharias.chat.ollama.exceptions.OllamaToolErrorException;
import org.jetbrains.annotations.NotNull;
import org.json.JSONArray;
@@ -39,7 +39,7 @@ public class GetAnimeList extends MALEndpointTool {
}
@Override
public OllamaToolRespnce function(OllamaFunctionArgument... args) {
public @NotNull OllamaToolResponse function(OllamaFunctionArgument... args) {
String query = "";
int offset = 0;
String[] fields = null;
@@ -83,6 +83,6 @@ public class GetAnimeList extends MALEndpointTool {
JSONObject response = MALAPIToolInstance.APIRequest("/anime", params);
return new OllamaToolRespnce(this.name(), response.toString());
return new OllamaToolResponse(this.name(), response.toString());
}
}
@@ -5,7 +5,7 @@ import me.zacharias.chat.mal.api.MALEndpoint;
import me.zacharias.chat.mal.api.MALEndpointTool;
import me.zacharias.chat.ollama.OllamaFunctionArgument;
import me.zacharias.chat.ollama.OllamaPerameter;
import me.zacharias.chat.ollama.OllamaToolRespnce;
import me.zacharias.chat.ollama.OllamaToolResponse;
import me.zacharias.chat.ollama.exceptions.OllamaToolErrorException;
import org.jetbrains.annotations.NotNull;
import org.json.JSONArray;
@@ -38,7 +38,7 @@ public class GetManagDetails extends MALEndpointTool {
}
@Override
public OllamaToolRespnce function(OllamaFunctionArgument... args) {
public @NotNull OllamaToolResponse function(OllamaFunctionArgument... args) {
int id = -1;
String[] fields = null;
@@ -81,6 +81,6 @@ public class GetManagDetails extends MALEndpointTool {
JSONObject obj = MALAPIToolInstance.APIRequest("/manga/"+id, map);
return new OllamaToolRespnce(this.name(), obj.toString());
return new OllamaToolResponse(this.name(), obj.toString());
}
}
@@ -5,7 +5,7 @@ import me.zacharias.chat.mal.api.MALEndpoint;
import me.zacharias.chat.mal.api.MALEndpointTool;
import me.zacharias.chat.ollama.OllamaFunctionArgument;
import me.zacharias.chat.ollama.OllamaPerameter;
import me.zacharias.chat.ollama.OllamaToolRespnce;
import me.zacharias.chat.ollama.OllamaToolResponse;
import me.zacharias.chat.ollama.exceptions.OllamaToolErrorException;
import org.jetbrains.annotations.NotNull;
import org.json.JSONArray;
@@ -39,7 +39,7 @@ public class GetMangaList extends MALEndpointTool {
}
@Override
public OllamaToolRespnce function(OllamaFunctionArgument... args) {
public @NotNull OllamaToolResponse function(OllamaFunctionArgument... args) {
String query = "";
int offset = 0;
String[] fields = null;
@@ -83,6 +83,6 @@ public class GetMangaList extends MALEndpointTool {
JSONObject response = MALAPIToolInstance.APIRequest("/manga", params);
return new OllamaToolRespnce(this.name(), response.toString());
return new OllamaToolResponse(this.name(), response.toString());
}
}
@@ -4,7 +4,7 @@ import io.github.fastily.jwiki.core.Wiki;
import me.zacharias.chat.ollama.OllamaFunctionArgument;
import me.zacharias.chat.ollama.OllamaFunctionTool;
import me.zacharias.chat.ollama.OllamaPerameter;
import me.zacharias.chat.ollama.OllamaToolRespnce;
import me.zacharias.chat.ollama.OllamaToolResponse;
import org.jetbrains.annotations.NotNull;
public class GetWikiPageText extends OllamaFunctionTool {
@@ -28,7 +28,7 @@ public class GetWikiPageText extends OllamaFunctionTool {
}
@Override
public OllamaToolRespnce function(OllamaFunctionArgument... args) {
return new OllamaToolRespnce(name(), wiki.getPageText((String) args[0].value()));
public @NotNull OllamaToolResponse function(OllamaFunctionArgument... args) {
return new OllamaToolResponse(name(), wiki.getPageText((String) args[0].value()));
}
}