forked from neurodock/NeuroDock
refactor: me.zacharias.chat → me.neurodock, org rename cleanup
- Renamed package from me.zacharias.chat to me.neurodock across all 8 modules - Updated Gradle group from me.zacharias.neurodock to me.neurodock - Updated README and other files to reflect new Gitea org URL (Chat_things → neurodock) Dev note: 95 files touched. The Great Refactor is complete, long may it rest.
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
package me.neurodock.plugin.tool;
|
||||
|
||||
import me.neurodock.plugin.Plugin;
|
||||
import me.neurodock.plugin.exceptions.ToolRuntimeException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public abstract class Tool {
|
||||
|
||||
/**
|
||||
* The parent plugin of this tool, used by {@link Tool#getToolJSON()}.
|
||||
*/
|
||||
protected final Plugin PLUGIN;
|
||||
|
||||
/**
|
||||
* A base contructor, as the {@link Plugin} is used within this class
|
||||
* @param plugin The plugin that owns this tool
|
||||
*/
|
||||
public Tool(Plugin plugin) {
|
||||
this.PLUGIN = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* The core uses this method when generating the list of available functions to the LLM
|
||||
* @return a string formated JSON containing the representation of the tool definitions
|
||||
*/
|
||||
public final String getToolJSON() {
|
||||
JSONObject ret = new JSONObject();
|
||||
ret.put("type", "function");
|
||||
|
||||
JSONObject function = new JSONObject();
|
||||
function.put("name", String.format("%s_%s_RPCP", name(), PLUGIN.getMetadata().getName()).replaceAll(" ", "_"));
|
||||
if(description() != null) {
|
||||
function.put("description", description());
|
||||
}
|
||||
function.put("parameters", (parameters() == null? new JSONObject() : new JSONObject(parameters().toString())));
|
||||
|
||||
ret.put("function", function);
|
||||
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Name of the tool.</p>
|
||||
* @apiNote This is a lower snake_case formated string.
|
||||
* <p>Example: {@code "get_clock"}</p>
|
||||
* @return returns the name of this tool
|
||||
*/
|
||||
@NotNull
|
||||
abstract public String name();
|
||||
|
||||
/**
|
||||
* Description for the LLM on what this tool does
|
||||
* @return Short description defining the scope of this tool
|
||||
*/
|
||||
public String description() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The parameters this tool allows
|
||||
* @apiNote Can return {@link ToolParameters#empty()} if no arguments are needed
|
||||
* @return A {@link ToolParameters} object defining what this tool expects when being called
|
||||
*/
|
||||
@NotNull
|
||||
abstract public ToolParameters parameters();
|
||||
|
||||
/**
|
||||
* This is the main course of the tool. The LLM will call this on request of using your tool
|
||||
* @param arguments A collective of your {@link ToolParameters} from {@link Tool#parameters()}
|
||||
* @return The expected results, or {@link ToolResponse#empty(Tool)} if this is a "void" function
|
||||
* @throws ToolRuntimeException This indicates that an {@link Exception} is not fatal, any other exceptions thrown from this tool will be treated as fatal, and will result in this tool, or it's plugin being disabled
|
||||
*/
|
||||
abstract public ToolResponse callTool(ToolArguments arguments) throws ToolRuntimeException;
|
||||
}
|
||||
Reference in New Issue
Block a user