-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Please do a quick search on GitHub issues first, the feature you are about to request might have already been requested.
Expected Behavior
I expect that Spring AI should support registering java.util.function.Supplier
functions for LLM (Large Language Model) function calling, in addition to the currently supported java.util.function.Function
interface. This would allow developers to register functions that do not take any arguments but return a dynamic result, such as a random number generator, the current time, or the server's health status.
Here are a few examples where Supplier
functions would be useful:
-
Random Value Generation:
- Generate a random integer within a specified range:
Supplier<Integer> randomNumberSupplier = () -> new Random().nextInt(100); // Generates a random number between 0 and 99
- Generate a random UUID string:
Supplier<String> randomStringSupplier = () -> UUID.randomUUID().toString();
- Generate a random integer within a specified range:
-
Time-Related Information:
- Retrieve the current timestamp:
Supplier<LocalDateTime> currentTimeSupplier = () -> LocalDateTime.now();
- Retrieve the current date in a specific format:
Supplier<String> formattedDateSupplier = () -> LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
- Retrieve the current timestamp:
-
Server Status Monitoring:
- Return the server's current health status, such as "OK" or "FAIL":
Supplier<String> serverStatusSupplier = () -> "OK"; // In a real scenario, this would check the actual server status
- Return the server's current health status, such as "OK" or "FAIL":
By supporting Supplier
functions, Spring AI would allow for more dynamic and versatile function calling capabilities in LLM-powered applications. These functions are essential for generating real-time or context-dependent data without requiring any input parameters.
Current Behavior
Currently, it appears that Spring AI only supports registering functions that implement the java.util.function.Function interface for LLM function calling. This limits the functionality to only those functions that take an input and return an output. However, there are use cases where functions that take no arguments but return a value (like Supplier) would be more appropriate. This limitation makes it impossible to implement certain types of functionality using the current version.
Context
This issue has affected our ability to fully utilize Spring AI for dynamic content generation, such as generating random numbers or strings within the context of an LLM-powered application. We have considered alternative approaches, such as wrapping a Supplier within a Function, but this feels like a workaround rather than a proper solution. We believe that direct support for Supplier would be a more elegant and useful addition to the framework.
Are there any plans to support this feature, or is there a recommended workaround that we may not be aware of?