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/ollama-chat-functions.adoc
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
TIP: You need Ollama 0.2.8 or newer.
4
4
5
-
TIP: You need https://ollama.com/search?c=tools[Models] pre-trained for Tools support.
5
+
TIP: You need https://ollama.com/search?c=tools[Models] pre-trained for Tools support.
6
6
Usually, such models are tagged with a `Tools` tag.
7
7
For example `mistral`, `firefunction-v2` or `llama3.1:70b`.
8
8
@@ -14,10 +14,10 @@ The Ollama models tagged with the `Tools` label (see https://ollama.com/search?c
14
14
15
15
The Ollama 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.
16
16
Spring AI provides flexible and user-friendly ways to register and call custom functions.
17
-
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.
17
+
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.
18
18
The `description` helps the model to understand when to call the function.
19
19
20
-
As a developer, you need to implement a function that takes the function call arguments sent from the AI model, and responds with the result back to the model.
20
+
As a developer, you need to implement a function that takes the function call arguments sent from the AI model, and responds with the result back to the model.
21
21
Your function can in turn invoke other 3rd party services to provide the results.
22
22
23
23
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 `ChatModel`.
@@ -117,7 +117,7 @@ public record Request(String location, Unit unit) {}
117
117
118
118
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.
119
119
120
-
==== FunctionCallback Wrapper
120
+
==== FunctionCallbackWrapper
121
121
122
122
Another way to register a function is to create a `FunctionCallbackWrapper` like this:
NOTE: The in-prompt registered functions are enabled by default for the duration of this request.
198
198
199
-
This approach allows to choose dynamically different functions to be called based on the user input.
199
+
This approach allows you to dynamically choose different functions to be called based on the user input.
200
200
201
201
The link:https://github.com/spring-projects/spring-ai/blob/main/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/ollama/tool/FunctionCallbackInPromptIT.java[FunctionCallbackInPromptIT.java] integration test provides a complete example of how to register a function with the `OllamaChatModel` and use it in a prompt request.
0 commit comments