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
build / build (push) Has been cancelled
This commit is contained in:
Generated
+39
@@ -7,6 +7,45 @@
|
||||
<component name="FrameworkDetectionExcludesConfiguration">
|
||||
<file type="web" url="file://$PROJECT_DIR$" />
|
||||
</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">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -56,12 +56,12 @@ public class Display {
|
||||
|
||||
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
|
||||
core.addTool(new PythonRunner(core), Core.Source.INTERNAL);
|
||||
core.addTools(new MALAPITool().getOllamaTools());
|
||||
core.addTools(new GeniusTools().getGeniusTools());
|
||||
core.addTools(new WikipediaTool().getWikipediaToolsInstance());
|
||||
core.addTool(new PythonRunner(core), Core.Source.CTP);
|
||||
//core.addTools(new MALAPITool().getOllamaTools());
|
||||
//core.addTools(new GeniusTools().getGeniusTools());
|
||||
//core.addTools(new WikipediaTool().getWikipediaToolsInstance());
|
||||
|
||||
//APIApplication.start();
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ public class GeniusTools {
|
||||
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()));
|
||||
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) {
|
||||
|
||||
@@ -46,7 +46,7 @@ public class MALAPITool {
|
||||
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()));
|
||||
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) {
|
||||
|
||||
@@ -13,7 +13,7 @@ public class WikipediaTool {
|
||||
|
||||
public WikipediaTool() {
|
||||
this.wikipediaToolsInstance = OllamaFunctionTools.builder()
|
||||
.addTool(new GetWikiPageText(), Core.Source.INTERNAL)
|
||||
.addTool(new GetWikiPageText(), Core.Source.CTP)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user