Skip to content

Add support for passing a FunctionCallbackWrapper when registering functions via ChatClientRequestSpec #1303

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

Closed
PedroAlvarado opened this issue Sep 2, 2024 · 2 comments

Comments

@PedroAlvarado
Copy link

PedroAlvarado commented Sep 2, 2024

It'd be great to have greater control on the FunctionCallbackWrapper created when dynamically providing functions to the ChatClient.

Expected Behavior

interface ChatClientRequestSpec {
 //...other interface methods
 
<I, O> ChatClientRequestSpec function(FunctionCallbackWrapper fcw);

 //...other interface methods
}

Current Behavior

Currently, it is not possible to customize the FunctionCallbackWrapper created when using the methods below. For example, a custom ObjectMapper can not be set. This means that custom Jackson modules can not be registed such as the com.fasterxml.jackson.module.kotlin.kotlinModule.

interface ChatClientRequestSpec {
 //...other interface methods

<I, O> ChatClientRequestSpec function(String name, String description,
				java.util.function.Function<I, O> function);

\<I, O> ChatClientRequestSpec function(String name, String description, Class<I> inputType,
				java.util.function.Function<I, O> function);

 //...other interface methods
}

Context

The workaround at the moment is to register the FunctionCallbackWrapper using the ChatModel interface directly rather than the ChatClient interface. ChatOptions can be used as well via model specific implementation.

If this change makes sense, I can submit a PR.

@csterwa csterwa added the kotlin label Sep 16, 2024
tzolov added a commit to tzolov/spring-ai that referenced this issue Oct 4, 2024
  This commit adds support for tool context in various chat options classes across
  different AI model implementations and enhances function calling capabilities.

  The tool context allows passing additional contextual information to function callbacks.

 - Add toolContext field to chat options classes
 - Update builder classes to support setting toolContext
 - Enhance FunctionCallback interface to support context-aware function calls
 - Update AbstractFunctionCallback to implement BiFunction instead of Function
 - Modify FunctionCallbackWrapper to support both Function and BiFunction and
   to use the new SchemaType location
 - Add support for BiFunction in TypeResolverHelper
 - Update ChatClient interface and DefaultChatClient implementation to support
   new function calling methods with Function, BiFunction and FunctionCallback arguments
 - Refactor AbstractToolCallSupport to pass tool context to function execution
 - Update all affected <Model>ChatOptions with tool context support
 - Simplify OpenAiChatClientMultipleFunctionCallsIT test
 - Add tests for function calling with tool context
 - Add new test cases for function callbacks with context in various integration tests
 - Modify existing tests to incorporate new context-aware function calling capabilities

 Resolves spring-projects#864, spring-projects#1303, spring-projects#991
markpollack pushed a commit that referenced this issue Oct 4, 2024
  This commit adds support for tool context in various chat options classes across
  different AI model implementations and enhances function calling capabilities.

  The tool context allows passing additional contextual information to function callbacks.

 - Add toolContext field to chat options classes
 - Update builder classes to support setting toolContext
 - Enhance FunctionCallback interface to support context-aware function calls
 - Update AbstractFunctionCallback to implement BiFunction instead of Function
 - Modify FunctionCallbackWrapper to support both Function and BiFunction and
   to use the new SchemaType location
 - Add support for BiFunction in TypeResolverHelper
 - Update ChatClient interface and DefaultChatClient implementation to support
   new function calling methods with Function, BiFunction and FunctionCallback arguments
 - Refactor AbstractToolCallSupport to pass tool context to function execution
 - Update all affected <Model>ChatOptions with tool context support
 - Simplify OpenAiChatClientMultipleFunctionCallsIT test
 - Add tests for function calling with tool context
 - Add new test cases for function callbacks with context in various integration tests
 - Modify existing tests to incorporate new context-aware function calling capabilities
 - Add docs in in openai function calling

 Resolves #864, #1303, #991
@markpollack markpollack added this to the 1.0.0-M3 milestone Oct 4, 2024
@tzolov
Copy link
Contributor

tzolov commented Oct 6, 2024

@PedroAlvarado with 9c10a08 we extended the ChatClient API with ChatClientRequestSpec functions(FunctionCallback... functionCallbacks).
Would this solve your case?

@tzolov
Copy link
Contributor

tzolov commented Oct 6, 2024

@PedroAlvarado I'm closing this issue as resolved by 9c10a08
Feel free to reopen if it doesn't address your case.

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

No branches or pull requests

4 participants