Skip to content

Commit d76c1aa

Browse files
committed
Update to latest snapshot
1 parent 3670877 commit d76c1aa

File tree

10 files changed

+28
-106
lines changed

10 files changed

+28
-106
lines changed

patterns/tool-calling/tool-calling-mistral-ai/src/main/java/com/thomasvitale/ai/spring/BookService.java

+2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.thomasvitale.ai.spring;
22

3+
import org.springframework.aot.hint.annotation.RegisterReflectionForBinding;
34
import org.springframework.stereotype.Service;
45

56
import java.util.List;
67
import java.util.Map;
78
import java.util.concurrent.ConcurrentHashMap;
89

910
@Service
11+
@RegisterReflectionForBinding(classes = BookService.Book.class)
1012
public class BookService {
1113

1214
private static final Map<Integer,Book> books = new ConcurrentHashMap<>();

patterns/tool-calling/tool-calling-mistral-ai/src/main/java/com/thomasvitale/ai/spring/ChatController.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
55
import org.springframework.ai.chat.client.ChatClient;
6-
import org.springframework.ai.model.function.FunctionCallback;
6+
import org.springframework.ai.tool.function.FunctionToolCallback;
77
import org.springframework.web.bind.annotation.GetMapping;
88
import org.springframework.web.bind.annotation.RestController;
99

@@ -92,8 +92,7 @@ String chatFunctionVoidInput() {
9292
String chatFunctionVoidInputCallback() {
9393
return chatClient.prompt()
9494
.user("Welcome the users to the library")
95-
.toolCallbacks(FunctionCallback.builder()
96-
.function("sayWelcome", (input) -> {
95+
.toolCallbacks(FunctionToolCallback.builder("sayWelcome", (input) -> {
9796
logger.info("CALLBACK - Welcoming users to the library");
9897
})
9998
.description("Welcome users to the library")
@@ -124,8 +123,7 @@ String chatFunctionVoidOutputCallback(String user) {
124123
.text(userPromptTemplate)
125124
.param("user", user)
126125
)
127-
.toolCallbacks(FunctionCallback.builder()
128-
.function("welcomeUser", (input) -> {
126+
.toolCallbacks(FunctionToolCallback.builder("welcomeUser", (input) -> {
129127
logger.info("CALLBACK - Welcoming {} to the library", ((Functions.User) input).name());
130128
})
131129
.description("Welcome a specific user to the library")
@@ -160,8 +158,7 @@ String chatFunctionSingleCallback(String authorName) {
160158
.text(userPromptTemplate)
161159
.param("author", authorName)
162160
)
163-
.toolCallbacks(FunctionCallback.builder()
164-
.function("availableBooksByAuthor", function)
161+
.toolCallbacks(FunctionToolCallback.builder("availableBooksByAuthor", function)
165162
.description("Get the list of books written by the given author available in the library")
166163
.inputType(BookService.Author.class)
167164
.build())
@@ -196,8 +193,7 @@ String chatFunctionListCallback(String bookTitle1, String bookTitle2) {
196193
.param("bookTitle1", bookTitle1)
197194
.param("bookTitle2", bookTitle2)
198195
)
199-
.toolCallbacks(FunctionCallback.builder()
200-
.function("authorsByAvailableBooks", function)
196+
.toolCallbacks(FunctionToolCallback.builder("authorsByAvailableBooks", function)
201197
.description("Get the list of authors who wrote the given books available in the library")
202198
.inputType(BookService.Books.class)
203199
.build())

patterns/tool-calling/tool-calling-mistral-ai/src/main/java/com/thomasvitale/ai/spring/model/ChatModelController.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
import com.thomasvitale.ai.spring.Functions;
55
import org.springframework.ai.chat.model.ChatModel;
66
import org.springframework.ai.chat.prompt.PromptTemplate;
7-
import org.springframework.ai.model.function.FunctionCallback;
87
import org.springframework.ai.model.tool.ToolCallingChatOptions;
9-
import org.springframework.ai.tool.ToolCallback;
8+
import org.springframework.ai.tool.function.FunctionToolCallback;
109
import org.springframework.web.bind.annotation.GetMapping;
1110
import org.springframework.web.bind.annotation.RequestMapping;
1211
import org.springframework.web.bind.annotation.RestController;
@@ -49,12 +48,10 @@ String chatVariant(String authorName) {
4948
""");
5049
Map<String,Object> model = Map.of("author", authorName);
5150
var prompt = userPromptTemplate.create(model, ToolCallingChatOptions.builder()
52-
.toolCallbacks(
53-
(ToolCallback) FunctionCallback.builder()
54-
.function("BooksByAuthor", bookService::getBooksByAuthor)
55-
.description("Get the list of books written by the given author available in the library")
56-
.inputType(BookService.Author.class)
57-
.build()
51+
.toolCallbacks(FunctionToolCallback.builder("booksByAuthor", bookService::getBooksByAuthor)
52+
.description("Get the list of books written by the given author available in the library")
53+
.inputType(BookService.Author.class)
54+
.build()
5855
)
5956
.build());
6057

patterns/tool-calling/tool-calling-ollama/src/main/java/com/thomasvitale/ai/spring/BookService.java

+2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.thomasvitale.ai.spring;
22

3+
import org.springframework.aot.hint.annotation.RegisterReflectionForBinding;
34
import org.springframework.stereotype.Service;
45

56
import java.util.List;
67
import java.util.Map;
78
import java.util.concurrent.ConcurrentHashMap;
89

910
@Service
11+
@RegisterReflectionForBinding(classes = BookService.Book.class)
1012
public class BookService {
1113

1214
private static final Map<Integer,Book> books = new ConcurrentHashMap<>();

patterns/tool-calling/tool-calling-ollama/src/main/java/com/thomasvitale/ai/spring/ChatController.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
55
import org.springframework.ai.chat.client.ChatClient;
6-
import org.springframework.ai.model.function.FunctionCallback;
6+
import org.springframework.ai.tool.function.FunctionToolCallback;
77
import org.springframework.web.bind.annotation.GetMapping;
88
import org.springframework.web.bind.annotation.RestController;
99

@@ -92,8 +92,7 @@ String chatFunctionVoidInput() {
9292
String chatFunctionVoidInputCallback() {
9393
return chatClient.prompt()
9494
.user("Welcome the users to the library")
95-
.toolCallbacks(FunctionCallback.builder()
96-
.function("sayWelcome", (input) -> {
95+
.toolCallbacks(FunctionToolCallback.builder("sayWelcome", (input) -> {
9796
logger.info("CALLBACK - Welcoming users to the library");
9897
})
9998
.description("Welcome users to the library")
@@ -124,8 +123,7 @@ String chatFunctionVoidOutputCallback(String user) {
124123
.text(userPromptTemplate)
125124
.param("user", user)
126125
)
127-
.toolCallbacks(FunctionCallback.builder()
128-
.function("welcomeUser", (input) -> {
126+
.toolCallbacks(FunctionToolCallback.builder("welcomeUser", (input) -> {
129127
logger.info("CALLBACK - Welcoming {} to the library", ((Functions.User) input).name());
130128
})
131129
.description("Welcome a specific user to the library")
@@ -160,8 +158,7 @@ String chatFunctionSingleCallback(String authorName) {
160158
.text(userPromptTemplate)
161159
.param("author", authorName)
162160
)
163-
.toolCallbacks(FunctionCallback.builder()
164-
.function("availableBooksByAuthor", function)
161+
.toolCallbacks(FunctionToolCallback.builder("availableBooksByAuthor", function)
165162
.description("Get the list of books written by the given author available in the library")
166163
.inputType(BookService.Author.class)
167164
.build())
@@ -196,8 +193,7 @@ String chatFunctionListCallback(String bookTitle1, String bookTitle2) {
196193
.param("bookTitle1", bookTitle1)
197194
.param("bookTitle2", bookTitle2)
198195
)
199-
.toolCallbacks(FunctionCallback.builder()
200-
.function("authorsByAvailableBooks", function)
196+
.toolCallbacks(FunctionToolCallback.builder("authorsByAvailableBooks", function)
201197
.description("Get the list of authors who wrote the given books available in the library")
202198
.inputType(BookService.Books.class)
203199
.build())

patterns/tool-calling/tool-calling-ollama/src/main/java/com/thomasvitale/ai/spring/model/ChatModelController.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
import com.thomasvitale.ai.spring.Functions;
55
import org.springframework.ai.chat.model.ChatModel;
66
import org.springframework.ai.chat.prompt.PromptTemplate;
7-
import org.springframework.ai.model.function.FunctionCallback;
87
import org.springframework.ai.model.tool.ToolCallingChatOptions;
9-
import org.springframework.ai.tool.ToolCallback;
8+
import org.springframework.ai.tool.function.FunctionToolCallback;
109
import org.springframework.web.bind.annotation.GetMapping;
1110
import org.springframework.web.bind.annotation.RequestMapping;
1211
import org.springframework.web.bind.annotation.RestController;
@@ -49,9 +48,7 @@ String chatVariant(String authorName) {
4948
""");
5049
Map<String,Object> model = Map.of("author", authorName);
5150
var prompt = userPromptTemplate.create(model, ToolCallingChatOptions.builder()
52-
.toolCallbacks(
53-
(ToolCallback) FunctionCallback.builder()
54-
.function("BooksByAuthor", bookService::getBooksByAuthor)
51+
.toolCallbacks(FunctionToolCallback.builder("booksByAuthor", bookService::getBooksByAuthor)
5552
.description("Get the list of books written by the given author available in the library")
5653
.inputType(BookService.Author.class)
5754
.build()

patterns/tool-calling/tool-calling-openai/src/main/java/com/thomasvitale/ai/spring/ChatController.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
55
import org.springframework.ai.chat.client.ChatClient;
6-
import org.springframework.ai.model.function.FunctionCallback;
6+
import org.springframework.ai.tool.function.FunctionToolCallback;
77
import org.springframework.web.bind.annotation.GetMapping;
88
import org.springframework.web.bind.annotation.RestController;
99

@@ -92,8 +92,7 @@ String chatFunctionVoidInput() {
9292
String chatFunctionVoidInputCallback() {
9393
return chatClient.prompt()
9494
.user("Welcome the users to the library")
95-
.toolCallbacks(FunctionCallback.builder()
96-
.function("sayWelcome", (input) -> {
95+
.toolCallbacks(FunctionToolCallback.builder("sayWelcome", (input) -> {
9796
logger.info("CALLBACK - Welcoming users to the library");
9897
})
9998
.description("Welcome users to the library")
@@ -124,8 +123,7 @@ String chatFunctionVoidOutputCallback(String user) {
124123
.text(userPromptTemplate)
125124
.param("user", user)
126125
)
127-
.toolCallbacks(FunctionCallback.builder()
128-
.function("welcomeUser", (input) -> {
126+
.toolCallbacks(FunctionToolCallback.builder("welcomeUser", (input) -> {
129127
logger.info("CALLBACK - Welcoming {} to the library", ((Functions.User) input).name());
130128
})
131129
.description("Welcome a specific user to the library")
@@ -160,8 +158,7 @@ String chatFunctionSingleCallback(String authorName) {
160158
.text(userPromptTemplate)
161159
.param("author", authorName)
162160
)
163-
.toolCallbacks(FunctionCallback.builder()
164-
.function("availableBooksByAuthor", function)
161+
.toolCallbacks(FunctionToolCallback.builder("availableBooksByAuthor", function)
165162
.description("Get the list of books written by the given author available in the library")
166163
.inputType(BookService.Author.class)
167164
.build())
@@ -196,8 +193,7 @@ String chatFunctionListCallback(String bookTitle1, String bookTitle2) {
196193
.param("bookTitle1", bookTitle1)
197194
.param("bookTitle2", bookTitle2)
198195
)
199-
.toolCallbacks(FunctionCallback.builder()
200-
.function("authorsByAvailableBooks", function)
196+
.toolCallbacks(FunctionToolCallback.builder("authorsByAvailableBooks", function)
201197
.description("Get the list of authors who wrote the given books available in the library")
202198
.inputType(BookService.Books.class)
203199
.build())

patterns/tool-calling/tool-calling-openai/src/main/java/com/thomasvitale/ai/spring/ToolBeanRegistrationAotProcessor.java

-60
This file was deleted.

patterns/tool-calling/tool-calling-openai/src/main/java/com/thomasvitale/ai/spring/model/ChatModelController.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
import com.thomasvitale.ai.spring.Functions;
55
import org.springframework.ai.chat.model.ChatModel;
66
import org.springframework.ai.chat.prompt.PromptTemplate;
7-
import org.springframework.ai.model.function.FunctionCallback;
87
import org.springframework.ai.model.tool.ToolCallingChatOptions;
9-
import org.springframework.ai.tool.ToolCallback;
8+
import org.springframework.ai.tool.function.FunctionToolCallback;
109
import org.springframework.web.bind.annotation.GetMapping;
1110
import org.springframework.web.bind.annotation.RequestMapping;
1211
import org.springframework.web.bind.annotation.RestController;
@@ -50,8 +49,7 @@ String chatVariant(String authorName) {
5049
Map<String,Object> model = Map.of("author", authorName);
5150
var prompt = userPromptTemplate.create(model, ToolCallingChatOptions.builder()
5251
.toolCallbacks(
53-
(ToolCallback) FunctionCallback.builder()
54-
.function("BooksByAuthor", bookService::getBooksByAuthor)
52+
FunctionToolCallback.builder("booksByAuthor", bookService::getBooksByAuthor)
5553
.description("Get the list of books written by the given author available in the library")
5654
.inputType(BookService.Author.class)
5755
.build()

patterns/tool-calling/tool-calling-openai/src/main/resources/META-INF/spring/aot.factories

-2
This file was deleted.

0 commit comments

Comments
 (0)