-
Notifications
You must be signed in to change notification settings - Fork 932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support function calling for reflection Method with multiple arguments #1099
Conversation
tzolov
commented
Jul 23, 2024
•
edited
Loading
edited
-- add FunctionCallbackMethodProcessor to support parsing. -- add the FunctionCalling annotation to declare -- add FunctionCallbackMethodProcessorIT as test Dependent on spring-projects#1099
-- add FunctionCallbackMethodProcessor to support parsing. -- add the FunctionCalling annotation to declare -- add FunctionCallbackMethodProcessorIT as test Dependent on spring-projects#1099
String className = entry.getKey(); | ||
Class<?> clazz = entry.getValue(); | ||
|
||
JsonSchema schema = schemaGen.generateSchema(clazz); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking into BeanOutputConverter
we could use the following code to reuse the "victools" json schema that I believe is what supports the 2020_12 draft as standard jackson doesn't support that version of the schema. If jackson now supports it, that would be great.
JacksonModule jacksonModule = new JacksonModule();
SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(DRAFT_2020_12, PLAIN_JSON)
.with(jacksonModule);
SchemaGeneratorConfig config = configBuilder.build();
SchemaGenerator generator = new SchemaGenerator(config);
JsonNode jsonNode = generator.generateSchema(this.typeRef.getType());
... convert node to string..
f47fe19
to
8d11a01
Compare
8d11a01
to
73205e4
Compare
…uments and return values This change enables more flexible integration between Spring AI and LLM function calling capabilities while maintaining type safety and ease of use. - Add new MethodFunctionCallback class to support method invocation via reflection - Supports both static and non-static method calls - Handles multiple parameter types including primitives, objects, collections - Supports empty parameters and empty response - Auto-generates JSON schema from method parameters - Special handling for ToolContext parameters - Builder pattern for easy configuration - Add comprehensive unit tests for MethodFunctionCallback - Add integration tests for MethodFunctionCallback with both Anthropic and OpenAI clients - Add jackson-module-jsonSchema dependency - Modify FunctionCallback to check for empty tool context Testing coverage includes: - Static method invocation scenarios - Non-static method calls with various parameter types - Void return type methods - Complex parameter types (enums, records, lists) - Tool context handling - Error cases and validation
73205e4
to
f302dc0
Compare
This looks amazing. I'm havingsome odd issues that seem to be related to classpath. when building and then running
and when running it in intellij it gives
when running OpenAiChatClientMethodFunctionCallbackIT.methodTurnLightNoResponse |
@markpollack thanks for reviewing it. |
The -U seems to have helped with the maven build, so that is passing now. For IntelliJ I had to do the 'repair ide' steps and eventually it worked. Odd. |
} | ||
catch (Exception e) { | ||
ReflectionUtils.handleReflectionException(e); | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why return null?
merged in 5f6b892 |