You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/anthropic-chat-functions.adoc
+7-7Lines changed: 7 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ Spring AI provides flexible and user-friendly ways to register and call custom f
12
12
In general, the custom functions need to provide a function `name`, `description`, and the function call `signature` (as JSON schema) to let the model know what arguments the function expects.
13
13
The `description` helps the model to understand when to call the function.
14
14
15
-
As a developer, you need to implement a functions that takes the function call arguments sent from the AI model, and respond with the result back to the model.
15
+
As a developer, you need to implement a function that takes the function call arguments sent from the AI model, and respond with the result back to the model.
16
16
Your function can in turn invoke other 3rd party services to provide the results.
17
17
18
18
Spring AI makes this as easy as defining a `@Bean` definition that returns a `java.util.Function` and supplying the bean name as an option when invoking the `ChatClient`.
@@ -29,7 +29,7 @@ We can provide the AI model with metadata about our own functions that it can us
29
29
For example, if during the processing of a prompt, the AI Model determines that it needs additional information about the temperature in a given location, it will start a server side generated request/response interaction. The AI Model invokes a client side function.
30
30
The AI Model provides method invocation details as JSON and it is the responsibility of the client to execute that function and return the response.
31
31
32
-
Spring AI greatly simplifies code you need to write to support function invocation.
32
+
Spring AI greatly simplifies the code you need to write to support function invocation.
33
33
It brokers the function invocation conversation for you.
34
34
You can simply provide your function definition as a `@Bean` and then provide the bean name of the function in your prompt options.
35
35
You can also reference multiple function bean names in your prompt.
@@ -88,10 +88,10 @@ static class Config {
88
88
}
89
89
----
90
90
91
-
The `@Description` annotation is optional and provides a function description (2) that helps the model to understand when to call the function.
91
+
The `@Description` annotation is optional and provides a function description (2) that helps the model understand when to call the function.
92
92
It is an important property to set to help the AI model determine what client side function to invoke.
93
93
94
-
Another option to provide the description of the function is to the `@JacksonDescription` annotation on the `MockWeatherService.Request` to provide the function description:
94
+
Another option to provide the description of the function is to use the `@JsonClassDescription` annotation on the `MockWeatherService.Request` to provide the function description:
95
95
96
96
[source,java]
97
97
----
@@ -110,14 +110,14 @@ static class Config {
110
110
public record Request(String location, Unit unit) {}
111
111
----
112
112
113
-
It is a best practice to annotate the request object with information such that the generates JSON schema of that function is as descriptive as possible to help the AI model pick the correct function to invoke.
113
+
It is a best practice to annotate the request object with information such that the generated JSON schema of that function is as descriptive as possible to help the AI model pick the correct function to invoke.
114
114
115
115
The link:https://github.com/spring-projects/spring-ai/blob/main/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/anthropic/tool/FunctionCallWithFunctionBeanIT.java.java[FunctionCallWithFunctionBeanIT.java] demonstrates this approach.
116
116
117
117
118
118
==== FunctionCallback Wrapper
119
119
120
-
Another way register a function is to create `FunctionCallbackWrapper` wrapper like this:
120
+
Another way to register a function is to create a `FunctionCallbackWrapper` wrapper like this:
121
121
122
122
[source,java]
123
123
----
@@ -136,7 +136,7 @@ static class Config {
136
136
}
137
137
----
138
138
139
-
It wraps the 3rd party, `MockWeatherService` function and registers it as a `CurrentWeather` function with the `AnthropicChatClient`.
139
+
It wraps the 3rd party `MockWeatherService` function and registers it as a `CurrentWeather` function with the `AnthropicChatClient`.
140
140
It also provides a description (2) and an optional response converter (3) to convert the response into a text as expected by the model.
141
141
142
142
NOTE: By default, the response converter does a JSON serialization of the Response object.
Copy file name to clipboardExpand all lines: spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/azure-open-ai-chat-functions.adoc
+8-7Lines changed: 8 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,8 @@ The Azure OpenAI API does not call the function directly; instead, the model gen
13
13
Spring AI provides flexible and user-friendly ways to register and call custom functions.
14
14
In general, the custom functions need to provide a function `name`, `description`, and the function call `signature` (as JSON schema) to let the model know what arguments the function expects. The `description` helps the model to understand when to call the function.
15
15
16
-
As a developer, you need to implement a functions that takes the function call arguments sent from the AI model, and respond with the result back to the model. Your function can in turn invoke other 3rd party services to provide the results.
16
+
As a developer, you need to implement a function that takes the function call arguments sent from the AI model, and respond with the result back to the model.
17
+
Your function can in turn invoke other 3rd party services to provide the results.
17
18
18
19
Spring AI makes this as easy as defining a `@Bean` definition that returns a `java.util.Function` and supplying the bean name as an option when invoking the `ChatClient`.
19
20
@@ -29,7 +30,7 @@ We can provide the AI model with metadata about our own functions that it can us
29
30
For example, if during the processing of a prompt, the AI Model determines that it needs additional information about the temperature in a given location, it will start a server side generated request/response interaction. The AI Model invokes a client side function.
30
31
The AI Model provides method invocation details as JSON and it is the responsibility of the client to execute that function and return the response.
31
32
32
-
Spring AI greatly simplifies code you need to write to support function invocation.
33
+
Spring AI greatly simplifies the code you need to write to support function invocation.
33
34
It brokers the function invocation conversation for you.
34
35
You can simply provide your function definition as a `@Bean` and then provide the bean name of the function in your prompt options.
35
36
You can also reference multiple function bean names in your prompt.
@@ -87,9 +88,9 @@ static class Config {
87
88
}
88
89
----
89
90
90
-
The `@Description` annotation is optional and provides a function description (2) that helps the model to understand when to call the function. It is an important property to set to help the AI model determine what client side function to invoke.
91
+
The `@Description` annotation is optional and provides a function description (2) that helps the model understand when to call the function. It is an important property to set to help the AI model determine what client side function to invoke.
91
92
92
-
Another option to provide the description of the function is to the `@JacksonDescription` annotation on the `MockWeatherService.Request` to provide the function description:
93
+
Another option to provide the description of the function is to use the `@JsonClassDescription` annotation on the `MockWeatherService.Request` to provide the function description:
93
94
94
95
[source,java]
95
96
----
@@ -108,13 +109,13 @@ static class Config {
108
109
public record Request(String location, Unit unit) {}
109
110
----
110
111
111
-
It is a best practice to annotate the request object with information such that the generates JSON schema of that function is as descriptive as possible to help the AI model pick the correct function to invoke.
112
+
It is a best practice to annotate the request object with information such that the generated JSON schema of that function is as descriptive as possible to help the AI model pick the correct function to invoke.
112
113
113
114
The link:https://github.com/spring-projects/spring-ai/blob/main/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/azure/tool/FunctionCallWithFunctionBeanIT.java[FunctionCallWithFunctionBeanIT.java] demonstrates this approach.
114
115
115
116
==== FunctionCallback Wrapper
116
117
117
-
Another way register a function is to create `FunctionCallbackWrapper` wrapper like this:
118
+
Another way to register a function is to create a `FunctionCallbackWrapper` wrapper like this:
118
119
119
120
[source,java]
120
121
----
@@ -133,7 +134,7 @@ static class Config {
133
134
}
134
135
----
135
136
136
-
It wraps the 3rd party, `MockWeatherService` function and registers it as a `CurrentWeather` function with the `ChatClient` and provides a description (2).
137
+
It wraps the 3rd party `MockWeatherService` function and registers it as a `CurrentWeather` function with the `AzureAiChatClient` and provides a description (2).
137
138
138
139
NOTE: The default response converter does a JSON serialization of the Response object.
Copy file name to clipboardExpand all lines: spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/mistralai-chat-functions.adoc
+10-10Lines changed: 10 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -2,17 +2,17 @@
2
2
3
3
You can register custom Java functions with the `MistralAiChatClient` and have the Mistral AI models intelligently choose to output a JSON object containing arguments to call one or many of the registered functions.
4
4
This allows you to connect the LLM capabilities with external tools and APIs.
5
-
The `mistral_small_latest` and `mistral_large_latest` models are trained to detect when a function should be called and to respond with JSON that adheres to the function signature.
5
+
The `open-mixtral-8x22b`, `mistral_small_latest`, and `mistral_large_latest` models are trained to detect when a function should be called and to respond with JSON that adheres to the function signature.
6
6
7
7
The MistralAI API does not call the function directly; instead, the model generates JSON that you can use to call the function in your code and return the result back to the model to complete the conversation.
8
8
9
-
NOTE: As of March 13, 2024, Mistral AI has integrated support for parallel function calling into their `mistral_large_latest`` model, a feature that was absent at the time of the first Spring AI Mistral AI.
9
+
NOTE: As of March 13, 2024, Mistral AI has integrated support for parallel function calling into their `mistral_large_latest` model, a feature that was absent at the time of the first Spring AI Mistral AI.
10
10
11
11
Spring AI provides flexible and user-friendly ways to register and call custom functions.
12
12
In general, the custom functions need to provide a function `name`, `description`, and the function call `signature` (as JSON schema) to let the model know what arguments the function expects.
13
13
The `description` helps the model to understand when to call the function.
14
14
15
-
As a developer, you need to implement a functions that takes the function call arguments sent from the AI model, and respond with the result back to the model.
15
+
As a developer, you need to implement a function that takes the function call arguments sent from the AI model, and respond with the result back to the model.
16
16
Your function can in turn invoke other 3rd party services to provide the results.
17
17
18
18
Spring AI makes this as easy as defining a `@Bean` definition that returns a `java.util.Function` and supplying the bean name as an option when invoking the `ChatClient`.
@@ -29,7 +29,7 @@ We can provide the AI model with metadata about our own functions that it can us
29
29
For example, if during the processing of a prompt, the AI Model determines that it needs additional information about the temperature in a given location, it will start a server side generated request/response interaction. The AI Model invokes a client side function.
30
30
The AI Model provides method invocation details as JSON and it is the responsibility of the client to execute that function and return the response.
31
31
32
-
Spring AI greatly simplifies code you need to write to support function invocation.
32
+
Spring AI greatly simplifies the code you need to write to support function invocation.
33
33
It brokers the function invocation conversation for you.
34
34
You can simply provide your function definition as a `@Bean` and then provide the bean name of the function in your prompt options.
35
35
You can also reference multiple function bean names in your prompt.
@@ -41,7 +41,7 @@ To support the response of the chatbot, we will register our own function that t
41
41
42
42
When the response to the prompt to the model needs to answer a question such as `"What’s the weather like in Boston?"` the AI model will invoke the client providing the location value as an argument to be passed to the function. This RPC-like data is passed as JSON.
43
43
44
-
Our function can some SaaS based weather service API and returns the weather response back to the model to complete the conversation.
44
+
Our function calls some SaaS based weather service API and returns the weather response back to the model to complete the conversation.
45
45
In this example we will use a simple implementation named `MockWeatherService` that hard codes the temperature for various locations.
46
46
47
47
The following `MockWeatherService.java` represents the weather service API:
@@ -88,10 +88,10 @@ static class Config {
88
88
}
89
89
----
90
90
91
-
The `@Description` annotation is optional and provides a function description (2) that helps the model to understand when to call the function.
91
+
The `@Description` annotation is optional and provides a function description (2) that helps the model understand when to call the function.
92
92
It is an important property to set to help the AI model determine what client side function to invoke.
93
93
94
-
Another option to provide the description of the function is to the `@JacksonDescription` annotation on the `MockWeatherService.Request` to provide the function description:
94
+
Another option to provide the description of the function is the `@JsonClassDescription` annotation on the `MockWeatherService.Request` to provide the function description:
95
95
96
96
[source,java]
97
97
----
@@ -110,7 +110,7 @@ static class Config {
110
110
public record Request(String location, Unit unit) {}
111
111
----
112
112
113
-
It is a best practice to annotate the request object with information such that the generates JSON schema of that function is as descriptive as possible to help the AI model pick the correct function to invoke.
113
+
It is a best practice to annotate the request object with information such that the generated JSON schema of that function is as descriptive as possible to help the AI model pick the correct function to invoke.
114
114
115
115
The link:https://github.com/spring-projects/spring-ai/blob/main/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/mistralai/tool/PaymentStatusBeanIT.java[PaymentStatusBeanIT.java] demonstrates this approach.
116
116
@@ -120,7 +120,7 @@ MistralAI is almost identical to OpenAI in this regard.
120
120
121
121
==== FunctionCallback Wrapper
122
122
123
-
Another way register a function is to create `FunctionCallbackWrapper` wrapper like this:
123
+
Another way to register a function is to create `FunctionCallbackWrapper` wrapper like this:
124
124
125
125
[source,java]
126
126
----
@@ -139,7 +139,7 @@ static class Config {
139
139
}
140
140
----
141
141
142
-
It wraps the 3rd party, `MockWeatherService` function and registers it as a `CurrentWeather` function with the `MistralAiChatClient`.
142
+
It wraps the 3rd party `MockWeatherService` function and registers it as a `CurrentWeather` function with the `MistralAiChatClient`.
143
143
It also provides a description (2) and an optional response converter (3) to convert the response into a text as expected by the model.
144
144
145
145
NOTE: By default, the response converter does a JSON serialization of the Response object.
Copy file name to clipboardExpand all lines: spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/functions/openai-chat-functions.adoc
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ The AI Model provides method invocation details as JSON and it is the responsibi
30
30
31
31
The model-client interaction is illustrated in the <<spring-ai-function-calling-flow>> diagram.
32
32
33
-
Spring AI greatly simplifies code you need to write to support function invocation.
33
+
Spring AI greatly simplifies the code you need to write to support function invocation.
34
34
It brokers the function invocation conversation for you.
35
35
You can simply provide your function definition as a `@Bean` and then provide the bean name of the function in your prompt options.
36
36
You can also reference multiple function bean names in your prompt.
@@ -89,9 +89,9 @@ static class Config {
89
89
}
90
90
----
91
91
92
-
The `@Description` annotation is optional and provides a function description (2) that helps the model to understand when to call the function. It is an important property to set to help the AI model determine what client side function to invoke.
92
+
The `@Description` annotation is optional and provides a function description (2) that helps the model understand when to call the function. It is an important property to set to help the AI model determine what client side function to invoke.
93
93
94
-
Another option to provide the description of the function is to the `@JacksonDescription` annotation on the `MockWeatherService.Request` to provide the function description:
94
+
Another option to provide the description of the function is to use the `@JsonClassDescription` annotation on the `MockWeatherService.Request` to provide the function description:
95
95
96
96
[source,java]
97
97
----
@@ -110,14 +110,14 @@ static class Config {
110
110
public record Request(String location, Unit unit) {}
111
111
----
112
112
113
-
It is a best practice to annotate the request object with information such that the generates JSON schema of that function is as descriptive as possible to help the AI model pick the correct function to invoke.
113
+
It is a best practice to annotate the request object with information such that the generated JSON schema of that function is as descriptive as possible to help the AI model pick the correct function to invoke.
114
114
115
115
The link:https://github.com/spring-projects/spring-ai/blob/main/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/openai/tool/FunctionCallbackWithPlainFunctionBeanIT.java[FunctionCallbackWithPlainFunctionBeanIT.java] demonstrates this approach.
116
116
117
117
118
118
==== FunctionCallback Wrapper
119
119
120
-
Another way register a function is to create `FunctionCallbackWrapper` wrapper like this:
120
+
Another way to register a function is to create a `FunctionCallbackWrapper` wrapper like this:
121
121
122
122
[source,java]
123
123
----
@@ -136,7 +136,7 @@ static class Config {
136
136
}
137
137
----
138
138
139
-
It wraps the 3rd party, `MockWeatherService` function and registers it as a `CurrentWeather` function with the `OpenAiChatClient`.
139
+
It wraps the 3rd party `MockWeatherService` function and registers it as a `CurrentWeather` function with the `OpenAiChatClient`.
140
140
It also provides a description (2) and an optional response converter (3) to convert the response into a text as expected by the model.
141
141
142
142
NOTE: By default, the response converter does a JSON serialization of the Response object.
0 commit comments