Lets define a simple WeatherFunction function:
public record WeatherRequest(String city) {
}
public record WeatherResponse(float temperatureInCelsius) {
}
public static class WeatherFunction implements Function<WeatherRequest, WeatherResponse> {
@Override
public WeatherResponse apply(WeatherRequest weatherRequest) {
return new WeatherResponse(42.0f);
}
}
If the function @Bean is defined to return Function<WeatherRequest, WeatherResponse>
like this:
@Bean()
Function<WeatherRequest, WeatherResponse> weatherFunctionDefinition() {
return new WeatherFunction();
}
then SpringAI properly resolves the WeatherRequest
input type.
But if the function @Bean return type is the function class itself (e.g. WeatherFunction
) like:
@Bean()
WeatherFunction weatherClassDefinition() {
return new WeatherFunction();
}
Then SpringAI will fail to resolve the input type (resolves to Object class) and the the function call will fail with error like:
"error": {
"message": "Invalid schema for function 'weather': schema must be a JSON Schema of 'type: \"object\"', got 'type: \"None\"'.",
"type": "invalid_request_error",
"param": "tools[0].function.parameters",
"code": "invalid_function_parameters"
}
A solution ensure that the TypeResolverHelper#getFunctionArgumentType
properly resolves the input type when the @Bean return type is an explicit Function<I, O>