-
Notifications
You must be signed in to change notification settings - Fork 978
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
feat(core): Add Supplier and Consumer function callback support #1746
feat(core): Add Supplier and Consumer function callback support #1746
Conversation
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.
We may have to add support for the Kotlin's equivalent of java.util.Consumer() in a follow up PR.
return FunctionCallback.builder() | ||
.description(functionDescription) | ||
.schemaType(this.schemaType) | ||
.function(beanName, KotlinDelegate.wrapKotlinSupplier(bean)) |
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.
Maybe we will need support for the Kotlin's equivalent of java.util.Consumer?
But this can be implemented in a follow up PR.
@SuppressWarnings("unchecked") | ||
public static Supplier<?> wrapKotlinSupplier(Object function) { | ||
return () -> ((Function0<Object>) function).invoke(); | ||
} |
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.
Likely we may have to add support for the Kotlin's equivalent of java.util.Consumer() in a follow up PR.
Add support for no-argument Supplier and single-argument Consumer function callbacks in the Spring AI core module. This enhancement allows: - Registration of Supplier<O> callbacks with no input (Void) type - Registration of Consumer<I> callbacks with no output (Void) type - Support for Kotlin Function0 (equivalent to Java Supplier) - Handle empty properties for Void input types in schema generation - Enhance FunctionCallback builder to support Supplier/Consumer patterns Additional changes: - Add test coverage for both Supplier and Consumer callbacks in various scenarios - Enhance TypeResolverHelper to support Consumer input type resolution - Support lambda-style function declarations for improved ergonomics - Add test cases for void input/output handling in OpenAI chat model - Include examples of function calls without return values - Add support for parameterless functions through Supplier interface Resolves spring-projects#1718 , spring-projects#1277 , spring-projects#1118, spring-projects#860
Add comprehensive documentation for the FunctionCallback API in Spring AI, including: - Overview of the interface and its key methods - Builder pattern usage with function and method invocation approaches - Examples for different function types (Function, BiFunction, Supplier, Consumer) - Best practices and common pitfalls - Schema generation and customization options
e7cc220
to
8a32cff
Compare
Refactored some of the long methods so that it reads more cleanly. |
in the docs, the section "Customization Options" was empty, so I removed it. |
merged in 432954d |
Add support for no-argument Supplier and single-argument Consumer function callbacks in the Spring AI core module. This enhancement allows:
Additional changes:
Resolves #1718 , #1277 , #1118, #860