Shit has happend, among the "shit" is working on the files stuff and refactoring Core.Source to reflect on the new names for the difrent types of tool sources
build / build (push) Has been cancelled

This commit is contained in:
2026-06-15 00:20:07 +02:00
parent b3cb4d86b6
commit ff0496eb61
11 changed files with 130 additions and 62 deletions
+46 -47
View File
@@ -74,6 +74,36 @@ public class Core {
public static File PLUGIN_DIRECTORY;
public static File CACHE_DIRECTORY;
/**
* Creates a new instance of Core with the provided PrintMessageHandler,
* defaulting the Ollama backend to {@code localhost}.
*
* @param printMessageHandler The PrintMessageHandler to use as the default output
*/
public Core(@NotNull PrintAdvanceMessageHandler printMessageHandler) {
this(printMessageHandler, "localhost");
}
/**
* Creates a new instance of Core with the provided PrintMessageHandler
* and a specific Ollama backend address.
*
* @param printMessageHandler The PrintMessageHandler to use as the default output
* @param ollamaIP The IP or hostname of the Ollama backend
*/
public Core(@NotNull PrintAdvanceMessageHandler printMessageHandler, @NotNull String ollamaIP)
{
this.printMessageHandler = printMessageHandler;
this.ollamaIP = ollamaIP;
initDirectories();
initOllamaUrl();
confirmOllama();
initLogWriter();
initScheduler();
initShutdownHook();
}
static {
// This should not be enforced like this, instead this should read a data field, or wait for an init to be called....
// Unsure of how to properly do this at this time, however.
@@ -407,6 +437,7 @@ public class Core {
private void confirmOllama()
{
try {
URL url = new URL("http://" + ollamaIP + ":" + ollamaPort + "/api/version");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Content-Type", "application/json");
@@ -427,36 +458,6 @@ public class Core {
}
}
/**
* Creates a new instance of Core with the provided PrintMessageHandler,
* defaulting the Ollama backend to {@code localhost}.
*
* @param printMessageHandler The PrintMessageHandler to use as the default output
*/
public Core(@NotNull PrintAdvanceMessageHandler printMessageHandler) {
this(printMessageHandler, "localhost");
}
/**
* Creates a new instance of Core with the provided PrintMessageHandler
* and a specific Ollama backend address.
*
* @param printMessageHandler The PrintMessageHandler to use as the default output
* @param ollamaIP The IP or hostname of the Ollama backend
*/
public Core(@NotNull PrintAdvanceMessageHandler printMessageHandler, @NotNull String ollamaIP)
{
this.printMessageHandler = printMessageHandler;
this.ollamaIP = ollamaIP;
initDirectories();
initOllamaUrl();
confirmOllama();
initLogWriter();
initScheduler();
initShutdownHook();
}
/**
* Sets the {@link #ollamaObject} object to the provided argument,
* Also adds the memory base system. See {@link Core#setOllamaObjectNoMemory} if you don't want to add memory functions
@@ -768,31 +769,29 @@ public class Core {
* Represents the source of a tool.
* <p>
* This is intended for use with {@link Core#addTool(OllamaFunctionTool, String)}
* to indicate the module from which a tool originates.
* to indicate the category 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.
* Tools boundeld with the Core runtime (memory, file access, etc.)
* DO NOT USE THIS unless you are poking at core stuff :).
*/
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.
* Compile-Time Plugins: boundeld at build time as part of the application.
* Examples: MALAPITool, GeniusAPI, WikipediaTool.
*/
public static final String API = "Api";
public static final String CTP = "CTP";
/**
* 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.
* Runtime Pre-Compiled Plugins: external plugins loaded at runtime via Plugin-API.
*/
public static final String INTERNAL = "Internal";
public static final String RPCP = "RPCP";
/**
* Tools defined via the RESt API interface dynamically.
*/
public static final String API = "API";
}
}
@@ -54,7 +54,7 @@ public class FileHandler {
public static ArrayList<Pair<? extends OllamaTool, String>> getTools() {
ArrayList<Pair<? extends OllamaTool, String>> tools = new ArrayList<>();
tools.add(new Pair<>(new ReadFileTool(), Core.Source.INTERNAL));
tools.add(new Pair<>(new ReadFileTool(), Core.Source.CORE));
return tools;
}
@@ -26,7 +26,7 @@ public class ReadFileTool extends OllamaFunctionTool {
@Override
public @NotNull OllamaPerameter parameters() {
return OllamaPerameter.builder()
.addProperty("file_path", OllamaPerameter.OllamaPerameterBuilder.Type.STRING, "The path to the file to be read")
.addProperty("file_path", OllamaPerameter.OllamaPerameterBuilder.Type.STRING, "The path to the file to be read", true)
.build();
}
@@ -70,6 +70,10 @@ public class CoreMemory {
e.printStackTrace();
}
}
else {
memory.put(MAPPED_MEMORY, new JSONObject());
memory.put(ARRAYED_MEMORY, new JSONArray());
}
this.memoryFile = memoryFile;
@@ -53,7 +53,7 @@ public class OllamaFunctionTools implements Iterable<Pair<OllamaFunctionTool, St
}
for (String s : source) {
if (s.equals(Core.Source.INTERNAL)) {
if (s.equals(Core.Source.CTP)) {
this.source.add(s);
}
}
@@ -69,6 +69,32 @@ public class OllamaObject {
private OllamaObject(String model, ArrayList<OllamaMessage> messages, ArrayList<Pair<OllamaTool, String>> tools, JSONObject format, Map<String, Object> options, boolean stream, String keep_alive) {
this.model = model;
this.messages = messages;
// Reflecting the reflection injection for ALL tools that was added in the OllamaObjectBuilder, etc, etc comment.. its past midnignt and i'm tired.
for(Pair<OllamaTool, String> tool : tools)
{
Class<?> clazz = tool.getKey().getClass();
Field field = null;
while(!clazz.equals(Object.class)) {
try {
field = clazz.getDeclaredField("source");
if (field != null) {
break;
}
}
catch (NoSuchFieldException ignore){}
clazz = clazz.getSuperclass();
}
if (field != null) {
field.setAccessible(true);
try {
field.set(tool.getKey(), tool.getValue());
} catch (IllegalAccessException e) {
Core.writeLog("ERROR: "+e.getMessage());
}
}
}
this.tools = tools;
this.format = format;
this.options = options;
@@ -139,7 +165,7 @@ public class OllamaObject {
*/
public void addTool(OllamaTool tool, @MagicConstant(valuesFromClass = Core.Source.class) String source) {
// We inject the source into the tool's source field if it exists, This is to not cause issues with duplicate tools
Class<? extends Object> clazz = tool.getClass();
Class<?> clazz = tool.getClass();
Field field = null;
while(!clazz.equals(Object.class)) {
try {
@@ -351,7 +377,7 @@ public class OllamaObject {
* @return The {@link OllamaObjectBuilder}
*/
public OllamaObjectBuilder addTool(OllamaTool tool) {
this.tools.add(new Pair<>(tool, Core.Source.EXTERNAL));
this.tools.add(new Pair<>(tool, Core.Source.CTP));
return this;
}
@@ -374,7 +400,7 @@ public class OllamaObject {
*/
public OllamaObjectBuilder addToolsExternal(ArrayList<? extends OllamaTool> tools) {
for (OllamaTool tool : tools) {
this.tools.add(new Pair<>(tool, Core.Source.EXTERNAL));
this.tools.add(new Pair<>(tool, Core.Source.CTP));
}
return this;
}
@@ -400,7 +426,7 @@ public class OllamaObject {
*/
public OllamaObjectBuilder addTools(OllamaTool... tools) {
for(OllamaTool tool : tools) {
this.tools.add(new Pair<>(tool, Core.Source.EXTERNAL));
this.tools.add(new Pair<>(tool, Core.Source.CTP));
}
return this;
}