+ * This is intended for use with {@link Core#addTool(OllamaFunctionTool, String)}
+ * to indicate the module from which a tool originates.
+ */
+ public static class Source {
+ /**
+ * Represents an external tool that is not derived from the Core.
+ * Instead, it belongs to an internally defined system or module within the project/program.
+ */
+ public static final String EXTERNAL = "External";
+
+ /**
+ * Represents an internally defined tool that is part of the Core system.
+ * This is meant for tools that are strictly part of the Core and should not be used for definitions outside of it.
+ */
+ public static final String CORE = "Core";
+
+ /**
+ * Represents a tool defined through an API system.
+ * These tools are more dynamic, as they originate from fully external sources using the API.
+ */
+ public static final String API = "Api";
+
+ /**
+ * Represents an internally defined tool that is derived from Core Components but not the Core itself.
+ * This is used for tools that are part of the Core Components, such as internal modules, but do not belong directly to the Core.
+ */
+ public static final String INTERNAL = "Internal";
+ }
}
diff --git a/Core/src/main/java/me/zacharias/chat/core/LaunchOptions.java b/Core/src/main/java/me/zacharias/chat/core/LaunchOptions.java
index 4cba05e..9ca20f1 100644
--- a/Core/src/main/java/me/zacharias/chat/core/LaunchOptions.java
+++ b/Core/src/main/java/me/zacharias/chat/core/LaunchOptions.java
@@ -1,8 +1,16 @@
package me.zacharias.chat.core;
+/**
+ * The Configuration class, where arguments are stored and retrieved. This is used to configure the running of the program from the Launcher.
+ */
public class LaunchOptions {
private static LaunchOptions instance = new LaunchOptions();
-
+
+ /**
+ * Gets the singleton instance of the LaunchOptions class.
+ * Meant to be used to get or set ant option.
+ * @return The singleton instance of the LaunchOptions class.
+ */
public static LaunchOptions getInstance() {
return instance;
}
@@ -12,47 +20,92 @@ public class LaunchOptions {
private boolean serverMode;
private int port = 39075;
private String redirectOutput;
-
+
+ /**
+ * Sets the singleton instance of the LaunchOptions class.
+ * Used to reset the LaunchOptions to their default values.
+ * @param instance The instance to set.
+ */
public static void setInstance(LaunchOptions instance) {
LaunchOptions.instance = instance;
}
-
+
+ /**
+ * Retries if old messages should be loaded.
+ * @return a boolean indicating if old messages should be loaded.
+ */
public boolean isLoadOld() {
return loadOld;
}
-
+
+ /**
+ * Sets if old messages should be loaded.
+ * @param loadOld a boolean indicating if old messages should be loaded.
+ */
public void setLoadOld(boolean loadOld) {
this.loadOld = loadOld;
}
-
+
+ /**
+ * Gets if the program should automatically accept prompts.
+ * @return a boolean indicating if the program should automatically accept prompts.
+ */
public boolean isAutoAccept() {
return autoAccept;
}
-
+
+ /**
+ * Sets if the program should automatically accept prompts.
+ * @param autoAccept a boolean indicating if the program should automatically accept prompts.
+ */
public void setAutoAccept(boolean autoAccept) {
this.autoAccept = autoAccept;
}
-
+
+ /**
+ * Gets the port number that the API server should use.
+ * @return the port number that the API server should use.
+ */
public int getPort() {
return port;
}
-
+
+ /**
+ * Sets the port number that the API server should use.
+ * @param port the port number that the API server should use.
+ */
public void setPort(int port) {
this.port = port;
}
-
+
+ /**
+ * Gets the file path that the program should redirect output to.
+ * @return the file path that the program should redirect output to.
+ */
public String getRedirectOutput() {
return redirectOutput;
}
-
+
+ /**
+ * Sets the file path that the program should redirect output to.
+ * @param redirectOutput the file path that the program should redirect output to.
+ */
public void setRedirectOutput(String redirectOutput) {
this.redirectOutput = redirectOutput;
}
-
+
+ /**
+ * Gets if the program is running in API server mode.
+ * @return a boolean indicating if the program is running in API server mode.
+ */
public boolean isServerMode() {
return serverMode;
}
-
+
+ /**
+ * Sets if the program is running in API server mode.
+ * @param serverMode a boolean indicating if the program is running in API server mode.
+ */
public void setServerMode(boolean serverMode) {
this.serverMode = serverMode;
}
diff --git a/Core/src/main/java/me/zacharias/chat/core/Pair.java b/Core/src/main/java/me/zacharias/chat/core/Pair.java
index bce5b34..e6b222d 100644
--- a/Core/src/main/java/me/zacharias/chat/core/Pair.java
+++ b/Core/src/main/java/me/zacharias/chat/core/Pair.java
@@ -1,26 +1,58 @@
package me.zacharias.chat.core;
+/**
+ * A simple Pair class.
+ * @param
+ * This function adds a string to the memory.
+ */
+public class AddMemoryFunction extends OllamaFunctionTool {
+ /**
+ * The CoreMemory instance.
+ */
CoreMemory memory = CoreMemory.getInstance();
@Override
@@ -32,7 +38,7 @@ public class AddMemoryFunction extends OllamaFuntionTool {
if (args.length == 0) {
throw new OllamaToolErrorException(name(), "Missing memory argument");
}
- String value = (String) args[0].getValue();
+ String value = (String) args[0].value();
memory.addMemory(value);
return new OllamaToolRespnce(name(), "Added "+value+" to the memory");
}
diff --git a/Core/src/main/java/me/zacharias/chat/core/memory/CoreMemory.java b/Core/src/main/java/me/zacharias/chat/core/memory/CoreMemory.java
index d628bc3..0cfd809 100644
--- a/Core/src/main/java/me/zacharias/chat/core/memory/CoreMemory.java
+++ b/Core/src/main/java/me/zacharias/chat/core/memory/CoreMemory.java
@@ -6,13 +6,28 @@ import org.json.JSONObject;
import java.io.*;
import java.util.ArrayList;
+/**
+ * CoreMemory is a class that provides a way to store and retrieve strings from a file.
+ * This is meant to be used as a way to store and retrieve strings from a file.
+ */
public class CoreMemory {
+ /**
+ * The singleton instance of CoreMemory.
+ */
private static CoreMemory instance = new CoreMemory("./cache/CoreMemory.json");
-
+
+ /**
+ * Gets the singleton instance of CoreMemory.
+ * @return The singleton instance of CoreMemory
+ */
public static CoreMemory getInstance() {
return instance;
}
-
+
+ /**
+ * Creates a new instance of CoreMemory.
+ * @param memoryFile The file to store the memory in
+ */
public CoreMemory(String memoryFile) {
File f = new File(memoryFile);
if (f.exists()) {
@@ -64,18 +79,36 @@ public class CoreMemory {
}
});
}
-
+
+ /**
+ * The memory.
+ */
private ArrayList
+ * This function retrives all the memory.
+ */
+public class GetMemoryFunction extends OllamaFunctionTool {
+ /**
+ * The CoreMemory instance.
+ */
CoreMemory memory = CoreMemory.getInstance();
@Override
diff --git a/Core/src/main/java/me/zacharias/chat/core/memory/RemoveMemoryFunction.java b/Core/src/main/java/me/zacharias/chat/core/memory/RemoveMemoryFunction.java
index 4fe9b1b..42dac7a 100644
--- a/Core/src/main/java/me/zacharias/chat/core/memory/RemoveMemoryFunction.java
+++ b/Core/src/main/java/me/zacharias/chat/core/memory/RemoveMemoryFunction.java
@@ -1,12 +1,19 @@
package me.zacharias.chat.core.memory;
import me.zacharias.chat.ollama.OllamaFunctionArgument;
-import me.zacharias.chat.ollama.OllamaFuntionTool;
+import me.zacharias.chat.ollama.OllamaFunctionTool;
import me.zacharias.chat.ollama.OllamaPerameter;
import me.zacharias.chat.ollama.OllamaToolRespnce;
import me.zacharias.chat.ollama.exceptions.OllamaToolErrorException;
-public class RemoveMemoryFunction extends OllamaFuntionTool {
+/**
+ * Provides the remove_memory function.
+ * This function removes a value from the memory.
+ */
+public class RemoveMemoryFunction extends OllamaFunctionTool {
+ /**
+ * The CoreMemory instance.
+ */
CoreMemory memory = CoreMemory.getInstance();
@Override
@@ -31,7 +38,7 @@ public class RemoveMemoryFunction extends OllamaFuntionTool {
if (args.length == 0) {
throw new OllamaToolErrorException(name(), "Missing memory argument");
}
- String value = (String) args[0].getValue();
+ String value = (String) args[0].value();
memory.removeMemory(value);
return new OllamaToolRespnce(name(), "Removed "+value+" to the memory");
}
diff --git a/Core/src/main/java/me/zacharias/chat/ollama/OllamaFunctionArgument.java b/Core/src/main/java/me/zacharias/chat/ollama/OllamaFunctionArgument.java
index 5b852a6..add4a05 100644
--- a/Core/src/main/java/me/zacharias/chat/ollama/OllamaFunctionArgument.java
+++ b/Core/src/main/java/me/zacharias/chat/ollama/OllamaFunctionArgument.java
@@ -1,19 +1,40 @@
package me.zacharias.chat.ollama;
-public class OllamaFunctionArgument {
- private final String argument;
- private final Object value;
-
- public OllamaFunctionArgument(String argument, Object value) {
- this.argument = argument;
- this.value = value;
+/**
+ * Represents an argument passed to a tool.
+ *
+ * @param argument The argument name
+ * @param value The argument value
+ */
+public record OllamaFunctionArgument(String argument, Object value) {
+ /**
+ * Creates a new instance of OllamaFunctionArgument.
+ * This is used by Ollama to pass arguments to a tool.
+ *
+ * @param argument The argument name
+ * @param value The argument value
+ */
+ public OllamaFunctionArgument {
}
-
- public String getArgument() {
+
+ /**
+ * Gets the argument name
+ *
+ * @return The argument name
+ */
+ @Override
+ public String argument() {
return argument;
}
-
- public Object getValue() {
+
+ /**
+ * Gets the argument value.
+ * This needs to be cast to the correct type by the tool itself
+ *
+ * @return The argument value
+ */
+ @Override
+ public Object value() {
return value;
}
}
diff --git a/Core/src/main/java/me/zacharias/chat/ollama/OllamaFunctionTool.java b/Core/src/main/java/me/zacharias/chat/ollama/OllamaFunctionTool.java
new file mode 100644
index 0000000..147f424
--- /dev/null
+++ b/Core/src/main/java/me/zacharias/chat/ollama/OllamaFunctionTool.java
@@ -0,0 +1,59 @@
+package me.zacharias.chat.ollama;
+
+import me.zacharias.chat.core.Core;
+import me.zacharias.chat.ollama.exceptions.OllamaToolErrorException;
+import org.json.JSONObject;
+
+/**
+ * Represents a tool that can be called by Ollama.
+ */
+public abstract class OllamaFunctionTool implements OllamaTool {
+
+ @Override
+ public String toString() {
+ JSONObject ret = new JSONObject();
+ ret.put("tool", "function");
+
+ JSONObject function = new JSONObject();
+ function.put("name", name());
+ function.put("description", description());
+ function.put("parameters", (parameters() == null?
+ new JSONObject() : new JSONObject(parameters().toString())));
+
+ ret.put("function", function);
+
+ return ret.toString();
+ }
+
+ /**
+ * The name of the tool
+ * This is used by Ollama to know what the tool is
+ * @return The name of the tool
+ */
+ abstract public String name();
+
+ /**
+ * The description of the tool
+ * This is used by Ollama to know what the tool does
+ * @return The description of the tool
+ */
+ abstract public String description();
+
+ /**
+ * The parameters of the tool
+ * This is used by Ollama to know what parameters the tool takes
+ * If null, the tool does not take any parameters
+ * @return The parameters of the tool or null if the tool does not take any parameters
+ */
+ abstract public OllamaPerameter parameters();
+
+ /**
+ * The function of the tool.
+ * This is used by Ollama to call the tool.
+ * 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
+ * @throws OllamaToolErrorException If the tool encounters an error
+ */
+ abstract public OllamaToolRespnce function(OllamaFunctionArgument... args);
+}
diff --git a/Core/src/main/java/me/zacharias/chat/ollama/OllamaFuntionTool.java b/Core/src/main/java/me/zacharias/chat/ollama/OllamaFuntionTool.java
deleted file mode 100644
index 6675034..0000000
--- a/Core/src/main/java/me/zacharias/chat/ollama/OllamaFuntionTool.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package me.zacharias.chat.ollama;
-
-import org.json.JSONObject;
-
-public abstract class OllamaFuntionTool implements OllamaTool {
-
- @Override
- public String toString() {
- JSONObject ret = new JSONObject();
- ret.put("tool", "function");
-
- JSONObject function = new JSONObject();
- function.put("name", name());
- function.put("description", description());
- function.put("parameters", (parameters() == null?
- new JSONObject() : new JSONObject(parameters().toString())));
-
- ret.put("function", function);
-
- return ret.toString();
- }
-
- abstract public String name();
- abstract public String description();
- abstract public OllamaPerameter parameters();
-
- abstract public OllamaToolRespnce function(OllamaFunctionArgument... args);
-}
diff --git a/Core/src/main/java/me/zacharias/chat/ollama/OllamaMessage.java b/Core/src/main/java/me/zacharias/chat/ollama/OllamaMessage.java
index d48ecbd..959d41e 100644
--- a/Core/src/main/java/me/zacharias/chat/ollama/OllamaMessage.java
+++ b/Core/src/main/java/me/zacharias/chat/ollama/OllamaMessage.java
@@ -2,10 +2,24 @@ package me.zacharias.chat.ollama;
import org.json.JSONObject;
+/**
+ * Represents a message sent by a Tool, Assistant(Ollama), or User.
+ */
public class OllamaMessage {
+ /**
+ * The role of the message.
+ */
OllamaMessageRole role;
+ /**
+ * The content of the message.
+ */
String content;
-
+
+ /**
+ * Creates a new instance of OllamaMessage.
+ * @param role The role of the message
+ * @param content The content of the message
+ */
public OllamaMessage(OllamaMessageRole role, String content) {
this.role = role;
this.content = content;
diff --git a/Core/src/main/java/me/zacharias/chat/ollama/OllamaMessageRole.java b/Core/src/main/java/me/zacharias/chat/ollama/OllamaMessageRole.java
index c24109f..b4be62c 100644
--- a/Core/src/main/java/me/zacharias/chat/ollama/OllamaMessageRole.java
+++ b/Core/src/main/java/me/zacharias/chat/ollama/OllamaMessageRole.java
@@ -1,21 +1,53 @@
package me.zacharias.chat.ollama;
+/**
+ * Represents the role of a message.
+ * This is used by Ollama to determine the role of a message.
+ */
public enum OllamaMessageRole {
+ /**
+ * Represents a user message.
+ */
USER("user"),
+ /**
+ * Represents an assistant message.
+ */
ASSISTANT("assistant"),
+ /**
+ * Represents a tool message
+ */
TOOL("tool"),
+ /**
+ * Represents a system message.
+ */
SYSTEM("system");
-
+
+ /**
+ * The role of the message.
+ */
private String role;
-
+
+ /**
+ * Creates a new instance of OllamaMessageRole.
+ * @param role The role of the message
+ */
OllamaMessageRole(String role) {
this.role = role;
}
-
+
+ /**
+ * Gets the role of the message.
+ * @return The role of the message
+ */
public String getRole() {
return role;
}
-
+
+ /**
+ * Gets the role of the message from a string.
+ * @param role The role of the message as a string
+ * @return The role of the message
+ */
public static OllamaMessageRole fromRole(String role) {
for(OllamaMessageRole roleRole : values()) {
if(roleRole.role.equals(role.toLowerCase()))
diff --git a/Core/src/main/java/me/zacharias/chat/ollama/OllamaMessageToolCall.java b/Core/src/main/java/me/zacharias/chat/ollama/OllamaMessageToolCall.java
index 6165dac..b75e9af 100644
--- a/Core/src/main/java/me/zacharias/chat/ollama/OllamaMessageToolCall.java
+++ b/Core/src/main/java/me/zacharias/chat/ollama/OllamaMessageToolCall.java
@@ -3,10 +3,22 @@ package me.zacharias.chat.ollama;
import org.json.JSONArray;
import org.json.JSONObject;
+/**
+ * Represents a message sent by a Tool.
+ */
public class OllamaMessageToolCall extends OllamaMessage{
-
+
+ /**
+ * The tool calls in the message
+ */
private JSONArray tool_calls;
-
+
+ /**
+ * Creates a new instance of OllamaMessage
+ * @param role The role of the message
+ * @param content The content of the message
+ * @param tool_calls The tool calls in the message
+ */
public OllamaMessageToolCall(OllamaMessageRole role, String content, JSONArray tool_calls) {
super(role, content);
this.tool_calls = tool_calls;
diff --git a/Core/src/main/java/me/zacharias/chat/ollama/OllamaObject.java b/Core/src/main/java/me/zacharias/chat/ollama/OllamaObject.java
index 061f0cf..8d54531 100644
--- a/Core/src/main/java/me/zacharias/chat/ollama/OllamaObject.java
+++ b/Core/src/main/java/me/zacharias/chat/ollama/OllamaObject.java
@@ -1,5 +1,6 @@
package me.zacharias.chat.ollama;
+import me.zacharias.chat.core.Core;
import me.zacharias.chat.core.LaunchOptions;
import org.json.JSONArray;
import org.json.JSONObject;
@@ -12,15 +13,53 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+/**
+ * Represents an Ollama Object.
+ * This is used to represent the state of the Ollama Object.
+ * This is used by the Core to store the state of the Ollama Object.
+ * This is used by the API to send the state of the Ollama Object to the client.
+ * @see Core#setOllamaObject(OllamaObject)
+ */
public class OllamaObject {
+ /**
+ * The model of the Ollama Object.
+ */
String model;
+ /**
+ * The messages of the Ollama Object.
+ */
ArrayList
+ * This is a string formated as "minutes"m or "hours"h or "days"d
+ * @param keep_alive The keep alive of the Ollama Object
+ * @return The {@link OllamaObjectBuilder}
+ */
public OllamaObjectBuilder keep_alive(String keep_alive) {
this.keep_alive = keep_alive;
return this;
}
-
+
+ /**
+ * Sets the keep alive of the Ollama Object.
+ * @param minutes The keep alive of the Ollama Object in minutes
+ * @return The {@link OllamaObjectBuilder}
+ */
public OllamaObjectBuilder keep_alive(int minutes) {
this.keep_alive = minutes+"m";
return this;
}
-
- public OllamaObjectBuilder addTool(OllamaTool tools) {
- this.tools.add(tools);
+
+ /**
+ * Adds a tool to the Ollama Object
+ * @param tool The tool to add
+ * @return The {@link OllamaObjectBuilder}
+ */
+ public OllamaObjectBuilder addTool(OllamaTool tool) {
+ this.tools.add(tool);
return this;
}
-
+
+ /**
+ * Adds tools to the Ollama Object
+ * @param tools The tools to add
+ * @return The {@link OllamaObjectBuilder}
+ */
public OllamaObjectBuilder addTools(ArrayList extends OllamaTool> tools) {
this.tools.addAll(tools);
return this;
}
-
+
+ /**
+ * Adds tools to the Ollama Object
+ * @param tools The tools to add
+ * @return The {@link OllamaObjectBuilder}
+ */
public OllamaObjectBuilder addTools(OllamaTool... tools) {
this.tools.addAll(List.of(tools));
return this;
}
-
+
+ /**
+ * Adds messages to the Ollama Object
+ * @param messages The messages to add
+ * @return The {@link OllamaObjectBuilder}
+ */
public OllamaObjectBuilder addMessages(OllamaMessage... messages) {
this.messages.addAll(List.of(messages));
return this;
}
-
+
+ /**
+ * Adds a message to the Ollama Object
+ * @param messages The message to add
+ * @return The {@link OllamaObjectBuilder}
+ */
public OllamaObjectBuilder addMessage(OllamaMessage messages) {
this.messages.add(messages);
return this;
}
-
+
+ /**
+ * Sets the model of the Ollama Object
+ * @param model The model of the Ollama Object
+ * @return The {@link OllamaObjectBuilder}
+ */
public OllamaObjectBuilder setModel(String model) {
this.model = model;
return this;
}
-
+
+ /**
+ * Builds the {@link OllamaObject}
+ * @return The {@link OllamaObject}
+ */
public OllamaObject build() {
return new OllamaObject(model, messages, tools, format, options, stream, keep_alive);
}
diff --git a/Core/src/main/java/me/zacharias/chat/ollama/OllamaPerameter.java b/Core/src/main/java/me/zacharias/chat/ollama/OllamaPerameter.java
index 9d10a03..c560cf4 100644
--- a/Core/src/main/java/me/zacharias/chat/ollama/OllamaPerameter.java
+++ b/Core/src/main/java/me/zacharias/chat/ollama/OllamaPerameter.java
@@ -6,12 +6,22 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
+/**
+ * Represents the parameters of a tool.
+ * This is used by Ollama to determine the parameters of a tool.
+ */
public class OllamaPerameter {
-
+
+ /**
+ * Creates a new instance of {@link OllamaPerameter}.
+ * @param properties The properties of the parameters
+ * @param required The required parameters
+ */
private OllamaPerameter(JSONObject properties, String[] required) {
this.properties = properties;
this.required = required;
};
+
@Override
public String toString() {
JSONObject json = new JSONObject();
@@ -22,26 +32,60 @@ public class OllamaPerameter {
return json.toString();
}
-
+
+ /**
+ * the properties of the parameters
+ */
JSONObject properties;
+ /**
+ * the required parameters
+ */
String[] required;
-
+
+ /**
+ * Gets the properties of the {@link OllamaPerameter}
+ * @return The properties of the {@link OllamaPerameter}
+ */
public JSONObject getProperties() {
return properties;
}
-
+
+ /**
+ * Gets the required parameters of the {@link OllamaPerameter}
+ * @return The required parameters of the {@link OllamaPerameter}
+ */
public String[] getRequired() {
return required;
}
-
+
+ /**
+ * Creates a new instance of {@link OllamaPerameterBuilder}.
+ * @return The {@link OllamaPerameterBuilder}
+ */
public static OllamaPerameterBuilder builder() {
return new OllamaPerameterBuilder();
}
-
+
+ /**
+ * Represents a builder for {@link OllamaPerameter}.
+ */
public static class OllamaPerameterBuilder {
+ /**
+ * The properties of the parameters.
+ */
Map
+ * This is used by a tool to indicate to Ollama that an error occurred.
+ */
public class OllamaToolError extends OllamaMessage {
+ /**
+ * The error from the tool.
+ */
String error;
+
+ /**
+ * Creates a new instance of OllamaToolError.
+ * @param error The error from the tool
+ */
public OllamaToolError(String error) {
super(OllamaMessageRole.TOOL, new JSONObject().put("error", error).toString());
this.error = error;
}
-
+
+ /**
+ * Gets the error from the tool.
+ * @return The error from the tool
+ */
public String getError() {
return error;
}
diff --git a/Core/src/main/java/me/zacharias/chat/ollama/OllamaToolRespnce.java b/Core/src/main/java/me/zacharias/chat/ollama/OllamaToolRespnce.java
index bd79568..8e4afef 100644
--- a/Core/src/main/java/me/zacharias/chat/ollama/OllamaToolRespnce.java
+++ b/Core/src/main/java/me/zacharias/chat/ollama/OllamaToolRespnce.java
@@ -2,19 +2,42 @@ 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;
}
diff --git a/Core/src/main/java/me/zacharias/chat/ollama/exceptions/OllamaToolErrorException.java b/Core/src/main/java/me/zacharias/chat/ollama/exceptions/OllamaToolErrorException.java
index 9a1fe0d..d90e470 100644
--- a/Core/src/main/java/me/zacharias/chat/ollama/exceptions/OllamaToolErrorException.java
+++ b/Core/src/main/java/me/zacharias/chat/ollama/exceptions/OllamaToolErrorException.java
@@ -1,18 +1,45 @@
package me.zacharias.chat.ollama.exceptions;
+import me.zacharias.chat.core.Core;
+import org.json.JSONObject;
+
+/**
+ * Represents an error from a tool.
+ * This is used internally by tools instead of {@link Exception}, to then be handled gracefully by {@link Core#handleResponce(JSONObject)}
+ */
public class OllamaToolErrorException extends RuntimeException {
+ /**
+ * The tool that caused the error.
+ */
private final String tool;
+ /**
+ * The error from the tool.
+ */
private final String error;
+
+ /**
+ * Creates a new instance of OllamaToolErrorException.
+ * @param tool The tool that caused the error
+ * @param error The error from the tool
+ */
public OllamaToolErrorException(String tool, String error) {
super(tool + ": " + error);
this.tool = tool;
this.error = error;
}
-
+
+ /**
+ * Gets the tool that caused the error.
+ * @return The tool that caused the error
+ */
public String getTool() {
return tool;
}
-
+
+ /**
+ * Gets the error from the tool.
+ * @return The error from the tool
+ */
public String getError() {
return error;
}
diff --git a/Display/src/main/java/me/zacharias/chat/display/Display.java b/Display/src/main/java/me/zacharias/chat/display/Display.java
index 3b852c0..f57ccb0 100644
--- a/Display/src/main/java/me/zacharias/chat/display/Display.java
+++ b/Display/src/main/java/me/zacharias/chat/display/Display.java
@@ -11,8 +11,16 @@ import java.util.*;
import static me.zacharias.chat.core.Core.writeLog;
+/**
+ * The main class of the Display.
+ * This is the main class for running as a Terminal application.
+ * Somewhat meant to be used as a Debug tool for testing your API.
+ */
public class Display {
-
+
+ /**
+ * The Core instance.
+ */
Core core = new Core(new PrintMessageHandler() {
@Override
public void printMessage(String message) {
@@ -24,25 +32,29 @@ public class Display {
return true;
}
});
-
+
+ /**
+ * Creates a new instance of Display.
+ * This Creates the OllamaObject and adds the tools to it. as well as handles the display of the messages. and the input from the user.
+ */
public Display()
{
core.setOllamaObject(OllamaObject.builder()
.setModel("llama3-AI")
.keep_alive(10)
- .stream(false)
+ //.stream(false)
.build());
- core.addTool(new TimeTool(), "Internal");
- core.addTool(new PythonRunner(core), "Internal");
+ core.addTool(new TimeTool(), Core.Source.EXTERNAL);
+ core.addTool(new PythonRunner(core), Core.Source.INTERNAL);
writeLog("Creating base OllamaObject with model: "+core.getOllamaObject().getModel());
System.out.println("Installed tools");
writeLog("Tools installed in this instance");
- for(Pair
+ * This is meant to provide the python code with all ExternalTools defined in the OllamaObject.
+ * @return The generated external_tools.py file
+ */
private String generateExternalTools() {
StringBuilder code = new StringBuilder();
@@ -243,9 +266,9 @@ public class PythonRunner extends OllamaFuntionTool {
""");
- for(Pair
+ * This is the main class of the application and is responsible for handling the command line arguments.
+ */
public class Launcher {
+ /**
+ * The Entry point of the application.
+ * This is the main method of the application and is responsible for handling the command line arguments.
+ * and adding them to the LaunchOptions instance.
+ * @param args The command line arguments passed from JVM
+ */
public static void main(String[] args) {
LaunchOptions options = LaunchOptions.getInstance();
@@ -42,10 +52,10 @@ public class Launcher {
Launch options for AI_chat
-h --help Provides this help message
-s --server Starts the application as API server
- -p --port Provides the port number that the API server shuld use, defaults to 39075
+ -p --port Provides the port number that the API server should use, defaults to 39075
-o --output Redirects the API Server output to another file
-y Auto accepts to prompts, used for a seamless run. Not recomended when running as Display
- -d --dontloadOld Don't load old messages
+ -d --dontLoadOld Don't load old messages
--api Provides API docs
""");
return;