Switching out toString returing a string JSON to toJSON that returns a JSONObject instead... and toString is not ment for this purpose

This commit is contained in:
2026-07-19 23:05:48 +02:00
parent 2defa32cb8
commit 4cd4367a19
13 changed files with 35 additions and 48 deletions
@@ -30,7 +30,7 @@ public abstract class Tool {
* 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() {
public final JSONObject getToolJSON() {
JSONObject ret = new JSONObject();
ret.put("type", "function");
@@ -39,11 +39,11 @@ public abstract class Tool {
if(description() != null) {
function.put("description", description());
}
function.put("parameters", (parameters() == null? new JSONObject() : new JSONObject(parameters().getJSON())));
function.put("parameters", (parameters() == null? new JSONObject() : parameters().getJSON()));
ret.put("function", function);
return ret.toString();
return ret;
}
/**
@@ -149,7 +149,7 @@ public class ToolParameters {
public ToolParameters build() {
JSONObject properties = new JSONObject();
for(String name : propertyMap.keySet()) {
properties.put(name, new JSONObject(propertyMap.get(name).toString()));
properties.put(name, propertyMap.get(name).toJSON());
}
return new ToolParameters(properties, required.toArray(new String[0]));
}
@@ -177,14 +177,13 @@ public class ToolParameters {
this.description = description;
}
@Override
public String toString() {
public JSONObject toJSON() {
JSONObject json = new JSONObject();
json.put("type", type);
json.put("description", description);
return json.toString();
return json;
}
}