Skip to content

[WIP] feat: Add support for Consumer and Supplier function callbacks #1719

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

Conversation

tzolov
Copy link
Contributor

@tzolov tzolov commented Nov 11, 2024

Depends on #1732

  • Add support for Java Consumer and Supplier functional interfaces in function callbacks
  • Handle void type inputs and outputs in function callbacks
  • Add test cases for void responses, Consumer callbacks, and Supplier callbacks
  • Update ModelOptionsUtils to properly handle void type schemas

Resolves #1718 , #1277 , #1118, #860

@markpollack markpollack self-assigned this Nov 11, 2024
@tzolov tzolov force-pushed the support_consumer_supplier_function_calling branch 2 times, most recently from 4849d92 to c848577 Compare November 12, 2024 13:57
@tzolov tzolov changed the title feat: Add support for Consumer and Supplier function callbacks [WIP] feat: Add support for Consumer and Supplier function callbacks Nov 12, 2024
- Add support for Java Consumer and Supplier functional interfaces in function callbacks
- Handle void type inputs and outputs in function callbacks
- Add test cases for void responses, Consumer callbacks, and Supplier callbacks
- Update ModelOptionsUtils to properly handle void type schemas

Resolves spring-projects#1718 and spring-projects#1277
…a function

This change adds the ability to specify the input type class when defining a function callback for the ChatClient.
Previously, the input type had to be inferred, which caused issues with lambda expressions due to type erasure.

The following new methods have been added:

- ChatClient.ChatClientRequestSpec.function(String, String, Class<I>, Function<I, O>)
- ChatClient.ChatClientRequestSpec.function(String, String, Class<I>, BiFunction<I, ToolContext, O>)
- ChatClient.ChatClientRequestSpec.function(String, String, Class<I>, Consumer<I>)
- ChatClient.Builder.defaultFunction(String, String, Class<I>, Function<I, O>)
- ChatClient.Builder.defaultFunction(String, String, Class<I>, BiFunction<I, ToolContext, O>)
- ChatClient.Builder.defaultFunction(String, String, Class<I>, Consumer<I>)

The deprecated methods without the input type parameter have also been kept for backwards compatibility.

This change should make it easier to use the ChatClient API, especially when dealing with lambda expressions.
…andling

Improves generic type support in function callbacks and JSON schema generation by:
- Moving CustomizedTypeReference to ModelOptionsUtils
- Updating BeanOutputConverter to use ParameterizedTypeReference
- Modifying function callbacks to support generic type resolution
- Adding train scheduler test case to validate generic type handling
@tzolov tzolov force-pushed the support_consumer_supplier_function_calling branch from c848577 to c30fda6 Compare November 12, 2024 21:56
@tzolov
Copy link
Contributor Author

tzolov commented Nov 16, 2024

Replaced by #1746

@tzolov tzolov closed this Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for Consumer and Supplier function callbacks
2 participants