fix: MethodToolCallbackProvider#isFunctionalType logic to check functiontype
- Change LHR <-> RHR in the ClassUtils.isAssignable Auto-cherry-pick to 1.0.x Fixes #GH-3355 Signed-off-by: Sun Yuhan <sunyuhan1998@users.noreply.github.com>
This commit is contained in:
committed by
Ilayaperumal Gopinathan
parent
6451fef547
commit
fe4f0d197c
@@ -103,9 +103,9 @@ public final class MethodToolCallbackProvider implements ToolCallbackProvider {
|
||||
}
|
||||
|
||||
private boolean isFunctionalType(Method toolMethod) {
|
||||
var isFunction = ClassUtils.isAssignable(toolMethod.getReturnType(), Function.class)
|
||||
|| ClassUtils.isAssignable(toolMethod.getReturnType(), Supplier.class)
|
||||
|| ClassUtils.isAssignable(toolMethod.getReturnType(), Consumer.class);
|
||||
var isFunction = ClassUtils.isAssignable(Function.class, toolMethod.getReturnType())
|
||||
|| ClassUtils.isAssignable(Supplier.class, toolMethod.getReturnType())
|
||||
|| ClassUtils.isAssignable(Consumer.class, toolMethod.getReturnType());
|
||||
|
||||
if (isFunction) {
|
||||
logger.warn("Method {} is annotated with @Tool but returns a functional type. "
|
||||
|
||||
@@ -78,6 +78,15 @@ class MethodToolCallbackProviderTests {
|
||||
.hasMessageContaining("Multiple tools with the same name (validTool) found in sources");
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenToolObjectHasObjectTypeMethodThenSuccess() {
|
||||
MethodToolCallbackProvider provider = MethodToolCallbackProvider.builder()
|
||||
.toolObjects(new ObjectTypeToolMethodsObject())
|
||||
.build();
|
||||
assertThat(provider.getToolCallbacks()).hasSize(1);
|
||||
assertThat(provider.getToolCallbacks()[0].getToolDefinition().name()).isEqualTo("objectTool");
|
||||
}
|
||||
|
||||
static class ValidToolObject {
|
||||
|
||||
@Tool
|
||||
@@ -137,4 +146,13 @@ class MethodToolCallbackProviderTests {
|
||||
|
||||
}
|
||||
|
||||
static class ObjectTypeToolMethodsObject {
|
||||
|
||||
@Tool
|
||||
public Object objectTool() {
|
||||
return "Object tool result";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user