docs: improve documentation for function callback and tool context
- Add cross-references to tool context documentation section - Enhance BiFunction section title and description - Improve readability and consistency of function callback documentation
This commit is contained in:
@@ -11,8 +11,8 @@ The main interface defines several key methods:
|
||||
* `getName()`: Returns the unique function name within the AI model context
|
||||
* `getDescription()`: Provides a description that helps the model decide when to invoke the function
|
||||
* `getInputTypeSchema()`: Defines the JSON schema for the function's input parameters
|
||||
* `call(String functionInput)`: Handles the actual function execution
|
||||
* `call(String functionInput, ToolContext toolContext)`: Extended version that supports additional context
|
||||
* `call(String functionArguments)`: Handles the actual function execution
|
||||
* `call(String functionArguments, ToolContext toolContext)`: Extended version that supports additional xref:api/functions.adoc#Tool-Context[tool context]
|
||||
|
||||
== Builder Pattern
|
||||
|
||||
@@ -39,7 +39,9 @@ FunctionCallback callback = FunctionCallback.builder()
|
||||
.build();
|
||||
----
|
||||
|
||||
==== BiFunction<I, ToolContext, O> with ToolContext
|
||||
==== BiFunction<I, ToolContext, O>
|
||||
|
||||
Using Function with input type <I> and additional xref:api/functions.adoc#Tool-Context[ToolContext] parameter:
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@@ -113,7 +115,7 @@ The method invoking implements the `FunctionCallback` interface and provides:
|
||||
- Support for both static and instance methods
|
||||
- Any number of parameters (including none) and return values (including void)
|
||||
- Any parameter/return types (primitives, objects, collections)
|
||||
- Special handling for `ToolContext` parameters
|
||||
- Special handling for xref:api/functions.adoc#Tool-Context[ToolContext] parameters
|
||||
|
||||
==== Static Method Invocation
|
||||
|
||||
@@ -231,7 +233,7 @@ FunctionCallback.builder()
|
||||
|
||||
=== Tool Context Usage
|
||||
|
||||
* Use ToolContext when additional state or context is required that is provided from the User and not part of the function input generated by the AI model.
|
||||
* Use xref:api/functions.adoc#Tool-Context[ToolContext] when additional state or context is required that is provided from the User and not part of the function input generated by the AI model.
|
||||
* Use `BiFunction<I, ToolContext, O>` to access the ToolContext in the function invocation approach and add `ToolContext` parameter in the method invoking approach.
|
||||
|
||||
|
||||
|
||||
@@ -378,6 +378,7 @@ String response = ChatClient.create(chatModel).prompt()
|
||||
The https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/client/OpenAiChatClientMethodInvokingFunctionCallbackIT.java[OpenAiChatClientMethodInvokingFunctionCallbackIT]
|
||||
integration test provides additional examples of how to use the FunctionCallback.Builder to create method invocation FunctionCallbacks.
|
||||
|
||||
[[Tool-Context]]
|
||||
== Tool Context
|
||||
|
||||
Spring AI now supports passing additional contextual information to function callbacks through a tool context.
|
||||
|
||||
Reference in New Issue
Block a user