enumClass, String description) {
+ return addEnumProperty(enumClass.getSimpleName(), enumClass, description, false);
+ }
+
/**
* Makes a previusly optinal perameter required for this {@link OllamaPerameterBuilder}
* @param name The name of the parameter
@@ -131,7 +160,7 @@ public class OllamaPerameter {
required.add(name);
return this;
}
-
+
/**
* Removes a property from the parameters.
* @param name The name of the property to remove
@@ -142,7 +171,23 @@ public class OllamaPerameter {
required.remove(name);
return this;
}
-
+
+ /**
+ * Coverts a RPCP Tool Perameter to a CTP Ollama Peameter
+ * @param parameters
+ * @return
+ */
+ public OllamaPerameterBuilder of(ToolParameters parameters) {
+ required.addAll(Arrays.asList(parameters.getRequired()));
+ for(String key : parameters.getProperties().keySet())
+ {
+ Property property = new Property(parameters.getProperties().getJSONObject(key).getString("type"),
+ parameters.getProperties().getJSONObject(key).getString("description"));
+ propertyMap.put(key, property);
+ }
+ return this;
+ }
+
/**
* Builds the {@link OllamaPerameter}
* @return The {@link OllamaPerameter}
@@ -154,7 +199,7 @@ public class OllamaPerameter {
}
return new OllamaPerameter(properties, required.toArray(new String[0]));
}
-
+
/**
* Represents a property of a parameter.
*/
@@ -167,7 +212,7 @@ public class OllamaPerameter {
* The description of the property.
*/
String description;
-
+
/**
* Creates a new instance of {@link Property}.
* @param type The type of the property
@@ -188,7 +233,7 @@ public class OllamaPerameter {
return json.toString();
}
}
-
+
/**
* Represents the type of parameter.
*/
@@ -222,7 +267,7 @@ public class OllamaPerameter {
* The type of the parameter.
*/
private final String type;
-
+
/**
* Gets the type of the parameter.
* @return The type of the parameter
@@ -230,7 +275,7 @@ public class OllamaPerameter {
public String getType() {
return type;
}
-
+
/**
* Creates a new instance of {@link Type}.
* @param type The type of the parameter
@@ -238,6 +283,19 @@ public class OllamaPerameter {
Type(String type) {
this.type = type;
}
+
+ Type of(String type)
+ {
+ return switch (type) {
+ case "string" -> STRING;
+ case "int" -> INT;
+ case "boolean" -> BOOLEAN;
+ case "enum" -> ENUM;
+ case "array" -> ARRAY;
+ case "object" -> OBJECT;
+ default -> throw new IllegalArgumentException("Unknown type " + type);
+ };
+ }
}
}
}
diff --git a/Core/src/main/java/me/neurodock/plugin/loader/Loader.java b/Core/src/main/java/me/neurodock/plugin/loader/Loader.java
index e5c5eb1..8e58271 100644
--- a/Core/src/main/java/me/neurodock/plugin/loader/Loader.java
+++ b/Core/src/main/java/me/neurodock/plugin/loader/Loader.java
@@ -48,7 +48,7 @@ public class Loader {
tools.add(new OllamaFunctionTool() {
@Override
public @NotNull String name() {
- return tool.name();
+ return tool.name() + "_" + plugin.getMetadata().getName();
}
@Override
@@ -58,8 +58,7 @@ public class Loader {
@Override
public @NotNull OllamaPerameter parameters() {
- // TODO: make a wrapper around ToolPerameters to OllamaPeramer
- throw new RuntimeException(new ExecutionControl.NotImplementedException("To be Implemented"));
+ return OllamaPerameter.builder().of(tool.parameters()).build();
}
@Override
@@ -98,7 +97,7 @@ public class Loader {
throw new PluginLoadingException("Malformed plugin json", UNKNOWN_PLUGIN);
if(!pluginJson.has("entryPoint") || !(pluginJson.get("entryPoint") instanceof String pluginEntryPoint))
throw new PluginLoadingException("Malformed plugin json", pluginName);
- JarEntry entry = jar.getJarEntry(pluginEntryPoint.replaceAll("\\.", "/"));
+ JarEntry entry = jar.getJarEntry(pluginEntryPoint.replaceAll("\\.", "/")+".class");
if(entry == null) throw new PluginLoadingException("Missing plugin entrypoint", pluginName);
Plugin plugin = null;
@@ -146,6 +145,6 @@ public class Loader {
);
}
- return new LoadedPlugin(plugin, classLoader, null/*TODO: MUST BE REPLACED WITH ACTUAL PLUGIN METADATA! this is read from the PluginEntyPoint*/);
+ return new LoadedPlugin(plugin, classLoader, plugin.getMetadata()/*TODO: MUST BE REPLACED WITH ACTUAL PLUGIN METADATA! this is read from the PluginEntyPoint*/);
}
}
diff --git a/Display/src/main/java/me/neurodock/display/PythonRunner.java b/Display/src/main/java/me/neurodock/display/PythonRunner.java
index 8fb6ed3..7c5f214 100644
--- a/Display/src/main/java/me/neurodock/display/PythonRunner.java
+++ b/Display/src/main/java/me/neurodock/display/PythonRunner.java
@@ -32,6 +32,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
+import static me.neurodock.core.Core.ensureDir;
import static me.neurodock.core.Core.writeLog;
/**
@@ -71,6 +72,8 @@ public class PythonRunner extends OllamaFunctionTool {
public PythonRunner(Core core) {
this.core = core;
+ ensureDir("./pythonFiles/");
+
try {
serverSocket = new ServerSocket(6050);
Thread thread = new Thread(() -> {
diff --git a/Plugin-API/build.gradle b/Plugin-API/build.gradle
index 6d3239f..aadf409 100644
--- a/Plugin-API/build.gradle
+++ b/Plugin-API/build.gradle
@@ -2,7 +2,7 @@ plugins {
id 'java-library'
}
-version = '0.1.2'
+version = '0.1.4.1'
repositories {
mavenCentral()
diff --git a/Plugin-API/src/main/java/me/neurodock/plugin/tool/Tool.java b/Plugin-API/src/main/java/me/neurodock/plugin/tool/Tool.java
index e93b200..108aa10 100644
--- a/Plugin-API/src/main/java/me/neurodock/plugin/tool/Tool.java
+++ b/Plugin-API/src/main/java/me/neurodock/plugin/tool/Tool.java
@@ -38,7 +38,7 @@ public abstract class Tool {
if(description() != null) {
function.put("description", description());
}
- function.put("parameters", (parameters() == null? new JSONObject() : new JSONObject(parameters().toString())));
+ function.put("parameters", (parameters() == null? new JSONObject() : new JSONObject(parameters().getJSON())));
ret.put("function", function);
diff --git a/Plugin-API/src/main/java/me/neurodock/plugin/tool/ToolParameters.java b/Plugin-API/src/main/java/me/neurodock/plugin/tool/ToolParameters.java
index 9a1fed6..c9f315a 100644
--- a/Plugin-API/src/main/java/me/neurodock/plugin/tool/ToolParameters.java
+++ b/Plugin-API/src/main/java/me/neurodock/plugin/tool/ToolParameters.java
@@ -1,12 +1,242 @@
package me.neurodock.plugin.tool;
+import org.json.JSONObject;
+
+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 ToolParameters {
+
/**
- * An empty {@link ToolParameters} for when a tool dosent need any perameters
- * @return the default {@link ToolParameters}
+ * Creates a new instance of {@link ToolParameters}.
+ * @param properties The properties of the parameters
+ * @param required The required parameters
*/
- public static ToolParameters empty() {
- return new ToolParameters();
+ private ToolParameters(JSONObject properties, String[] required) {
+ this.properties = properties;
+ this.required = required;
+ };
+
+ public JSONObject getJSON() {
+ JSONObject json = new JSONObject();
+
+ json.put("type", "object");
+ json.put("properties", properties);
+ json.put("required", required);
+
+ return json;
}
+ /**
+ * the properties of the parameters
+ */
+ JSONObject properties;
+ /**
+ * the required parameters
+ */
+ String[] required;
+
+ /**
+ * Gets the properties of the {@link ToolParameters}
+ * @return The properties of the {@link ToolParameters}
+ */
+ public JSONObject getProperties() {
+ return properties;
+ }
+
+ /**
+ * Gets the required parameters of the {@link ToolParameters}
+ * @return The required parameters of the {@link ToolParameters}
+ */
+ public String[] getRequired() {
+ return required;
+ }
+
+ /**
+ * Creates a new instance of {@link ToolParametersBuilder}.
+ * @return The {@link ToolParametersBuilder}
+ */
+ public static ToolParametersBuilder builder() {
+ return new ToolParametersBuilder();
+ }
+
+ /**
+ * Creates an empty {@link ToolParameters}
+ * @return an empty {@link ToolParameters}
+ * @apiNote This is equvalent to
+ * {@code
+ * ToolParameters.builder().build();
+ * }
+ */
+ public static ToolParameters empty() {
+ return builder().build();
+ }
+
+ /**
+ * Represents a builder for {@link ToolParameters}.
+ */
+ public static class ToolParametersBuilder {
+ /**
+ * The properties of the parameters.
+ */
+ Map propertyMap = new HashMap<>();
+ /**
+ * The required parameters.
+ */
+ ArrayList required = new ArrayList<>();
+
+ /**
+ * Add an optinal perameter to this {@link ToolParametersBuilder}
+ * @param name The name of the parameter
+ * @param type The type of the parameter
+ * @param description The description of the parameter
+ * @return The {@link ToolParametersBuilder}
+ * @apiNote Prefer {@link #addProperty(String, Type, String, boolean)} to be explicit about required state
+ */
+ public ToolParametersBuilder addProperty(String name, Type type, String description) {
+ return ToolParametersBuilder.this.addProperty(name, type, description, false);
+ }
+
+ /**
+ * Add a potentialy required peremeter to this {@link ToolParametersBuilder}.
+ * @param name The name of the parameter
+ * @param type The type of the parameter
+ * @param description The description of the parameter
+ * @param required The required state of the parameter
+ * @return The {@link ToolParametersBuilder}
+ */
+ public ToolParametersBuilder addProperty(String name, Type type, String description, boolean required) {
+ if(name == null || type == null || description == null) {
+ return this;
+ }
+ propertyMap.put(name, new Property(type.getType(), description));
+ if(required) {
+ this.required.add(name);
+ }
+ return this;
+ }
+
+ /**
+ * Makes a previusly optinal perameter required for this {@link ToolParametersBuilder}
+ * @param name The name of the parameter
+ * @return The {@link ToolParametersBuilder}
+ */
+ public ToolParametersBuilder required(String name) {
+ required.add(name);
+ return this;
+ }
+
+ /**
+ * Removes a property from the parameters.
+ * @param name The name of the property to remove
+ * @return The {@link ToolParametersBuilder}
+ */
+ public ToolParametersBuilder removeProperty(String name) {
+ propertyMap.remove(name);
+ required.remove(name);
+ return this;
+ }
+
+ /**
+ * Builds the {@link ToolParameters}
+ * @return The {@link ToolParameters}
+ */
+ public ToolParameters build() {
+ JSONObject properties = new JSONObject();
+ for(String name : propertyMap.keySet()) {
+ properties.put(name, new JSONObject(propertyMap.get(name).toString()));
+ }
+ return new ToolParameters(properties, required.toArray(new String[0]));
+ }
+
+ /**
+ * Represents a property of a parameter.
+ */
+ private static class Property {
+ /**
+ * The type of the property.
+ */
+ String type;
+ /**
+ * The description of the property.
+ */
+ String description;
+
+ /**
+ * Creates a new instance of {@link Property}.
+ * @param type The type of the property
+ * @param description The description of the property
+ */
+ public Property(String type, String description) {
+ this.type = type;
+ this.description = description;
+ }
+
+ @Override
+ public String toString() {
+ JSONObject json = new JSONObject();
+
+ json.put("type", type);
+ json.put("description", description);
+
+ return json.toString();
+ }
+ }
+
+ /**
+ * Represents the type of parameter.
+ */
+ public enum Type {
+ /**
+ * Represents a string parameter.
+ */
+ STRING("string"),
+ /**
+ * Represents an integer parameter.
+ */
+ INT("int"),
+ /**
+ * Represents a boolean parameter.
+ */
+ BOOLEAN("boolean"),
+ /**
+ * Represents a enum parameter.
+ */
+ ENUM("enum"),
+ /**
+ * Represents a array parameter.
+ */
+ ARRAY("array"),
+ /**
+ * Represents a object parameter.
+ */
+ OBJECT("object");
+
+ /**
+ * The type of the parameter.
+ */
+ private final String type;
+
+ /**
+ * Gets the type of the parameter.
+ * @return The type of the parameter
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * Creates a new instance of {@link Type}.
+ * @param type The type of the parameter
+ */
+ Type(String type) {
+ this.type = type;
+ }
+ }
+ }
}
diff --git a/build.gradle b/build.gradle
index 5e723ba..1237f2e 100644
--- a/build.gradle
+++ b/build.gradle
@@ -70,7 +70,7 @@ subprojects {
if (tasks.findByName('javadocJar')) artifact tasks.javadocJar
pom {
name = proj.name
- description = "${proj.name} module of AI-test"
+ description = "${proj.name} module of NeuroDock"
}
}
}
@@ -98,4 +98,6 @@ subprojects {
}
}
}
+
+ java.toolchain.languageVersion = JavaLanguageVersion.of(25)
}
\ No newline at end of file