Open jochenchrist opened 3 weeks ago
I reproduced the problem. The cause is that when inputType is not specified, the resolveInputType function uses reflection to get the generic type. However, when using a function with a trailing lambda, it is not possible to obtain the generic type declaration.
public FunctionCallbackWrapper<I, O> build() {
// ...
if (this.inputType == null) {
this.inputType = FunctionCallbackWrapper.resolveInputType(this.function);
}
// ...
}
Currently, the issue can be resolved through the aforementioned method, or by passing in a specific implementation class. Alternatively, it could be addressed by adding support for reified generic function extensions in the library:
inline fun<reified I,O> functionCallbackWrapperBuild(
noinline function:(I)->O
): FunctionCallbackWrapper.Builder<I,O> =
FunctionCallbackWrapper.builder(function).withInputType(I::class.java)
or perhaps by import other reflection packages to obtain the Metadata info?
Bug description When using a Kotlin function, the input type is not inferred. This causes an
invalid_request_error
error:Workaround is to specify the input type explictly
withInputType
(and use a custom object mapper)Environment Latest Snapshot.
Steps to reproduce See example below
Expected behavior Spring AI should also work with Kotlin or update the documentation.
Minimal Complete Reproducible example