Bug description OpenAI and Azure OpenAI doesn't accept function definitions without "properties" parameter.
This example with a Request object without parameter produces the following error as the "properties" parameter in the request body is missing.
@Description("Fetches ingredients")
@Service("myFunction")
public class MyFunction implements Function<MyFunction.Request, MyFunction.Response> {
public MyFunction() { }
@Override
public Response apply(Request request) {
return new Response(List.of("Bacon"));
}
public record Request() {}
public record Response(List<String> ingredients) {}
}
com.azure.core.exception.HttpResponseException: Status code 400, "{
"error": {
"message": "Invalid schema for function 'fetchIngredientsAvailableAtHome': In context=(), object schema missing properties.",
"type": "invalid_request_error",
"param": "tools[0].function.parameters",
"code": "invalid_function_parameters"
}
}"]
tools:
- type: FUNCTION
function: {
"name": "myFunction",
"description": "Fetches ingredients",
"parameters": {
"$schema": "..."
"type": "object"
}
}
This example works as expected as it adds a "properties" parameter with empty value to the request body.
private Recipe fetchRecipeWithFunctionCallingFor(List<String> ingredients) {
return chatClient.prompt()
.user(...)
.functions(FunctionCallback.builder()
.description("Fetches ingredients")
.function("myFunction", () -> List.of("Bacon"))
.build())
.call()
.entity(Recipe.class);
}
tools:
- type: FUNCTION
function: {
"name": "myFunction",
"description": "Fetches ingredients",
"parameters": {
"$schema": "..."
"type": "object"
"properties": {},
}
}
Additionally, I don't see a way to define a function without arguments via the MethodInvokingSpec method(String methodName, Class<?>... argumentTypes); in FunctionCallback.Builder
Environment Spring AI M3/M4, Java 21
Steps to reproduce See examples
Expected behavior It should be supported to use functions without arguments in Function Calling
Comment From: tzolov
@timosalm since the Record is empty shouldn't you define your function like: Function<Void, MyFunction.Response> or even better Supplier<MyFunction.Response> instead?
Comment From: tzolov
Additionally, I don't see a way to define a function without arguments via the
MethodInvokingSpec method(String methodName, Class<?>... argumentTypes);in FunctionCallback.Builder
The argumentTypes is java varargs so you can decide to not provide any arguments (e.g. without arguments) like this: .method("methodName")