Skip to content
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

The function definition for function calls does not support generics. #1118

Closed
lvchzh opened this issue Jul 25, 2024 · 5 comments
Closed

The function definition for function calls does not support generics. #1118

lvchzh opened this issue Jul 25, 2024 · 5 comments
Assignees
Labels
bug Something isn't working tool/function calling
Milestone

Comments

@lvchzh
Copy link

lvchzh commented Jul 25, 2024

Bug description
The function definition for function calls does not support generics.

Environment
Spring ai 1.0.0-SNAPSHOT

Steps to reproduce
step1:
public class TrainSearchScheduleService implements Function<RequestBean<TrainSearchScheduleReq>, ResponseBean<TrainSearchScheduleResp>> { .... }
step2:
Runtime-based generic type erasure leads to the loss of generic information.

Expected behavior
Support for defining generic classes

lvchzh added a commit to lvchzh/spring-ai that referenced this issue Jul 25, 2024
@mxsl-gr
Copy link
Contributor

mxsl-gr commented Jul 26, 2024

generic type is not supported yet, because the FunctionCallback.inputTypeSchema is generated based on Class, not Type. In theory, it could be supported if the Class is replaced with Type.

@lvchzh
Copy link
Author

lvchzh commented Jul 26, 2024

generic type is not supported yet, because the FunctionCallback.inputTypeSchema is generated based on Class, not Type. In theory, it could be supported if the Class is replaced with Type.
Yes, I have noticed this through the code and submitted changes to address the issue.
commit 71e8cee

@csterwa
Copy link

csterwa commented Sep 9, 2024

@lvchzh is resolved with commit 71e8cee?

@csterwa csterwa added bug Something isn't working tool/function calling labels Sep 9, 2024
@markpollack
Copy link
Member

Hard to tell from the commit as it doesn't contain tests as specified in the example. That said, we have spent efforts to remove dependencies on type utils in spring cloud function and create our own type utils that also help with kotlin support. Will investigate the support of

public class TrainSearchScheduleService implements Function<RequestBean<TrainSearchScheduleReq>, ResponseBean<TrainSearchScheduleResp>> 

@markpollack markpollack added this to the 1.0.0-M4 milestone Nov 12, 2024
tzolov added a commit to tzolov/spring-ai that referenced this issue Nov 16, 2024
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
tzolov added a commit to tzolov/spring-ai that referenced this issue Nov 17, 2024
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
markpollack pushed a commit that referenced this issue Nov 18, 2024
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

Add comprehensive documentation for the FunctionCallback API:
- 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

Resolves #1718 , #1277 , #1118, #860
@tzolov
Copy link
Contributor

tzolov commented Nov 19, 2024

Resolved by 432954d

@tzolov tzolov closed this as completed Nov 19, 2024
leijendary pushed a commit to leijendary/spring-ai that referenced this issue Jan 24, 2025
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

Add comprehensive documentation for the FunctionCallback API:
- 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

Resolves spring-projects#1718 , spring-projects#1277 , spring-projects#1118, spring-projects#860

Signed-off-by: leijendary <jonathanleijendekker@gmail.com>
leijendary pushed a commit to leijendary/spring-ai that referenced this issue Jan 24, 2025
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

Add comprehensive documentation for the FunctionCallback API:
- 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

Resolves spring-projects#1718 , spring-projects#1277 , spring-projects#1118, spring-projects#860

Signed-off-by: leijendary <jonathanleijendekker@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tool/function calling
Projects
None yet
Development

No branches or pull requests

5 participants