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
+39
View File
@@ -7,6 +7,45 @@
<component name="FrameworkDetectionExcludesConfiguration"> <component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" /> <file type="web" url="file://$PROJECT_DIR$" />
</component> </component>
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="org.jetbrains.annotations.Nullable" />
<option name="myDefaultNotNull" value="org.jetbrains.annotations.NotNull" />
<option name="myOrdered" value="false" />
<option name="myNullables">
<value>
<list size="11">
<item index="0" class="java.lang.String" itemvalue="org.jspecify.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="2" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.Nullable" />
<item index="3" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" />
<item index="4" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" />
<item index="5" class="java.lang.String" itemvalue="org.eclipse.jdt.annotation.Nullable" />
<item index="6" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="7" class="java.lang.String" itemvalue="jakarta.annotation.Nullable" />
<item index="8" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="9" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
<item index="10" class="java.lang.String" itemvalue="org.springframework.lang.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="11">
<item index="0" class="java.lang.String" itemvalue="org.jspecify.annotations.NonNull" />
<item index="1" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="2" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.NonNull" />
<item index="3" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" />
<item index="4" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" />
<item index="5" class="java.lang.String" itemvalue="org.eclipse.jdt.annotation.NonNull" />
<item index="6" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="7" class="java.lang.String" itemvalue="jakarta.annotation.Nonnull" />
<item index="8" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="9" class="java.lang.String" itemvalue="lombok.NonNull" />
<item index="10" class="java.lang.String" itemvalue="org.springframework.lang.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_26" default="true" project-jdk-name="26" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_26" default="true" project-jdk-name="26" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
+46 -47
View File
@@ -74,6 +74,36 @@ public class Core {
public static File PLUGIN_DIRECTORY; public static File PLUGIN_DIRECTORY;
public static File CACHE_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 { static {
// This should not be enforced like this, instead this should read a data field, or wait for an init to be called.... // 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. // Unsure of how to properly do this at this time, however.
@@ -407,6 +437,7 @@ public class Core {
private void confirmOllama() private void confirmOllama()
{ {
try { try {
URL url = new URL("http://" + ollamaIP + ":" + ollamaPort + "/api/version");
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET"); connection.setRequestMethod("GET");
connection.setRequestProperty("Content-Type", "application/json"); 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, * 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 * 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. * Represents the source of a tool.
* <p> * <p>
* This is intended for use with {@link Core#addTool(OllamaFunctionTool, String)} * 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 { public static class Source {
/** /**
* Represents an external tool that is not derived from the Core. * Tools boundeld with the Core runtime (memory, file access, etc.)
* Instead, it belongs to an internally defined system or module within the project/program. * DO NOT USE THIS unless you are poking at core stuff :).
*/
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"; public static final String CORE = "Core";
/** /**
* Represents a tool defined through an API system. * Compile-Time Plugins: boundeld at build time as part of the application.
* These tools are more dynamic, as they originate from fully external sources using the API. * 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. * Runtime Pre-Compiled Plugins: external plugins loaded at runtime via Plugin-API.
* 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"; 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() { public static ArrayList<Pair<? extends OllamaTool, String>> getTools() {
ArrayList<Pair<? extends OllamaTool, String>> tools = new ArrayList<>(); 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; return tools;
} }
@@ -26,7 +26,7 @@ public class ReadFileTool extends OllamaFunctionTool {
@Override @Override
public @NotNull OllamaPerameter parameters() { public @NotNull OllamaPerameter parameters() {
return OllamaPerameter.builder() 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(); .build();
} }
@@ -70,6 +70,10 @@ public class CoreMemory {
e.printStackTrace(); e.printStackTrace();
} }
} }
else {
memory.put(MAPPED_MEMORY, new JSONObject());
memory.put(ARRAYED_MEMORY, new JSONArray());
}
this.memoryFile = memoryFile; this.memoryFile = memoryFile;
@@ -53,7 +53,7 @@ public class OllamaFunctionTools implements Iterable<Pair<OllamaFunctionTool, St
} }
for (String s : source) { for (String s : source) {
if (s.equals(Core.Source.INTERNAL)) { if (s.equals(Core.Source.CTP)) {
this.source.add(s); 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) { 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.model = model;
this.messages = messages; 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.tools = tools;
this.format = format; this.format = format;
this.options = options; this.options = options;
@@ -139,7 +165,7 @@ public class OllamaObject {
*/ */
public void addTool(OllamaTool tool, @MagicConstant(valuesFromClass = Core.Source.class) String source) { 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 // 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; Field field = null;
while(!clazz.equals(Object.class)) { while(!clazz.equals(Object.class)) {
try { try {
@@ -351,7 +377,7 @@ public class OllamaObject {
* @return The {@link OllamaObjectBuilder} * @return The {@link OllamaObjectBuilder}
*/ */
public OllamaObjectBuilder addTool(OllamaTool tool) { 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; return this;
} }
@@ -374,7 +400,7 @@ public class OllamaObject {
*/ */
public OllamaObjectBuilder addToolsExternal(ArrayList<? extends OllamaTool> tools) { public OllamaObjectBuilder addToolsExternal(ArrayList<? extends OllamaTool> tools) {
for (OllamaTool tool : 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; return this;
} }
@@ -400,7 +426,7 @@ public class OllamaObject {
*/ */
public OllamaObjectBuilder addTools(OllamaTool... tools) { public OllamaObjectBuilder addTools(OllamaTool... tools) {
for(OllamaTool tool : 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; return this;
} }
@@ -56,12 +56,12 @@ public class Display {
core.enablePlugins(Core.PLUGIN_DIRECTORY); core.enablePlugins(Core.PLUGIN_DIRECTORY);
core.addTool(new TimeTool(), Core.Source.INTERNAL); core.addTool(new TimeTool(), Core.Source.CTP);
// TODO: Well Docker failes when luanched.... Fuck // TODO: Well Docker failes when luanched.... Fuck
core.addTool(new PythonRunner(core), Core.Source.INTERNAL); core.addTool(new PythonRunner(core), Core.Source.CTP);
core.addTools(new MALAPITool().getOllamaTools()); //core.addTools(new MALAPITool().getOllamaTools());
core.addTools(new GeniusTools().getGeniusTools()); //core.addTools(new GeniusTools().getGeniusTools());
core.addTools(new WikipediaTool().getWikipediaToolsInstance()); //core.addTools(new WikipediaTool().getWikipediaToolsInstance());
//APIApplication.start(); //APIApplication.start();
@@ -73,7 +73,7 @@ public class GeniusTools {
if (OllamaFunctionTool.class.isAssignableFrom(clazz)) { if (OllamaFunctionTool.class.isAssignableFrom(clazz)) {
//System.out.println("Found endpoint: " + clazz.getName() + " With constructor: " + clazz.getDeclaredConstructors().f.getName() + " and arguments: " + Arrays.toString(clazz.getDeclaredConstructor().getParameterTypes())); //System.out.println("Found endpoint: " + clazz.getName() + " With constructor: " + clazz.getDeclaredConstructors().f.getName() + " and arguments: " + Arrays.toString(clazz.getDeclaredConstructor().getParameterTypes()));
GeniusEndpointTool tool = (GeniusEndpointTool) clazz.getDeclaredConstructor(GeniusTools.class).newInstance(this); GeniusEndpointTool tool = (GeniusEndpointTool) clazz.getDeclaredConstructor(GeniusTools.class).newInstance(this);
builder.addTool(tool, Core.Source.INTERNAL); builder.addTool(tool, Core.Source.CTP);
} }
} }
} catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) { } catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) {
@@ -46,7 +46,7 @@ public class MALAPITool {
if (OllamaFunctionTool.class.isAssignableFrom(clazz)) { if (OllamaFunctionTool.class.isAssignableFrom(clazz)) {
//System.out.println("Found endpoint: " + clazz.getName() + " With constructor: " + clazz.getDeclaredConstructors().f.getName() + " and arguments: " + Arrays.toString(clazz.getDeclaredConstructor().getParameterTypes())); //System.out.println("Found endpoint: " + clazz.getName() + " With constructor: " + clazz.getDeclaredConstructors().f.getName() + " and arguments: " + Arrays.toString(clazz.getDeclaredConstructor().getParameterTypes()));
MALEndpointTool tool = (MALEndpointTool) clazz.getDeclaredConstructor(MALAPITool.class).newInstance(MALAPITool.this); MALEndpointTool tool = (MALEndpointTool) clazz.getDeclaredConstructor(MALAPITool.class).newInstance(MALAPITool.this);
builder.addTool(tool, Core.Source.INTERNAL); builder.addTool(tool, Core.Source.CTP);
} }
} }
} catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) { } catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) {
@@ -13,7 +13,7 @@ public class WikipediaTool {
public WikipediaTool() { public WikipediaTool() {
this.wikipediaToolsInstance = OllamaFunctionTools.builder() this.wikipediaToolsInstance = OllamaFunctionTools.builder()
.addTool(new GetWikiPageText(), Core.Source.INTERNAL) .addTool(new GetWikiPageText(), Core.Source.CTP)
.build(); .build();
} }