Bug description
I have a Tool (func as tool) defined like this:
class PlanningTool implements Function<String, Result> {
public Result apply (String input) {
//
}
}
Declare and register FunctionToolCallback to ChatClient like this:
FunctionToolCallback
.builder(name, new PlanningTool())
.description(description)
.inputSchema(PARAMETERS)
.inputType(String.class)
.build();
If the LLM returns json style input String like blow:
Jackson parser will produce the following exception:
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `java.lang.String` from Object value (token `JsonToken.START_OBJECT`)
at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 1]
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59) ~[jackson-databind-2.18.1.jar:2.18.1]
at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1767) ~[jackson-databind-2.18.1.jar:2.18.1]
at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1541) ~[jackson-databind-2.18.1.jar:2.18.1]
Some code like this should solve this issue:
I request;
if (toolInputType == String.class) {
request = (I) toolInput;
} else{
request = JsonParser.fromJson(toolInput, toolInputType);
}
Environment 1.0.0-M6