Class DecisionMethod
java.lang.Object
dev.langchain4j.service.decision.internal.DecisionMethod
The analysis of one decision service method: the questions it asks, how its parameters become the input, and how
the answers are mapped back to its return type.
All validation happens in of(Method), so frameworks can detect errors at build time. At runtime, they
can call invoke(DecisionServiceConfig, Object[]) or invokeAsync(DecisionServiceConfig, Object[]) to implement the method without the proxy created by
DecisionServices.
-
Method Summary
Modifier and TypeMethodDescriptionThe type of the result, without theCompletableFutureandDecisionResultwrappers.The types of the parameters that are sent to the model.invoke(DecisionServiceConfig config, Object[] args) Invokes this method with the given configuration of the decision service.invokeAsync(DecisionServiceConfig config, Object[] args) Invokes this method asynchronously with the given model, whatever its return type.booleanisAsync()Whether the method returns aCompletableFutureor aCompletionStage.method()static DecisionMethodAnalyzes the given method of a decision service interface.static DecisionMethodAnalyzes the given method as if it returned the given type.The questions asked by this method, keyed by question name.The classes accessed by reflection when mapping the answers, so that frameworks can register them for native images: the returned object types and their superclasses (their declared fields and constructors are used, and for records their components), and the enums whose constants are the options (their constant fields are read for@Description).Creates the request for an invocation of this method with the given arguments.toResult(DecisionResponse response, Function<String, Double> thresholds) Maps the response to the result of this method, without theCompletableFuturewrapper.
-
Method Details
-
of
Analyzes the given method of a decision service interface.- Throws:
IllegalConfigurationException- if the method cannot be implemented.
-
of
Analyzes the given method as if it returned the given type. Frameworks can use this for return types that are not supported here, for example a reactive type such as Mutiny'sUni<T>: they passTand callinvokeAsync(DecisionServiceConfig, Object[]).- Throws:
IllegalConfigurationException- if the method cannot be implemented.
-
method
-
questions
-
isAsync
public boolean isAsync()Whether the method returns aCompletableFutureor aCompletionStage. -
contentType
The type of the result, without theCompletableFutureandDecisionResultwrappers. -
reflectiveTypes
The classes accessed by reflection when mapping the answers, so that frameworks can register them for native images: the returned object types and their superclasses (their declared fields and constructors are used, and for records their components), and the enums whose constants are the options (their constant fields are read for@Description). Whenof(Method)itself runs in a native image, the service interface (its methods, with their parameters and annotations) must be registered as well. -
inputTypes
-
toRequest
Creates the request for an invocation of this method with the given arguments. -
toResult
Maps the response to the result of this method, without theCompletableFuturewrapper.- Parameters:
thresholds- the threshold of eachbooleananswer, by question name;nullmeans 0.5.
-
invoke
Invokes this method with the given configuration of the decision service. -
invokeAsync
Invokes this method asynchronously with the given model, whatever its return type. The call to the model starts immediately; frameworks with lazy types (such as Mutiny'sUni) should call this method on subscription.- Returns:
- a future of the result, without the
CompletableFuturewrapper of the method's return type.
-