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 from(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.static DecisionMethodAnalyzes the given method of a decision service interface.static DecisionMethodAnalyzes the given method as if it returned the given type.booleanWhether any question is answered as aboolean, the only kind of answer a threshold applies to.The types of the parameters that are sent to the model as structured values.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.invokeWithResponse(DecisionServiceConfig config, DecisionRequest request) Invokes this method synchronously with the given request, typically created withtoRequest(Object[]), and returns both its result and the response of the decision model, for frameworks that need the raw answers (for example their probabilities or the token usage) whatever the declared return type of the method.booleanisAsync()Whether the method returns aCompletableFutureor aCompletionStage.method()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
-
from
Analyzes the given method of a decision service interface.- Throws:
IllegalConfigurationException- if the method cannot be implemented.
-
from
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
-
hasBooleanAnswer
public boolean hasBooleanAnswer()Whether any question is answered as aboolean, the only kind of answer a threshold applies to. -
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). Whenfrom(Method)itself runs in a native image, the service interface (its methods, with their parameters and annotations) must be registered as well. -
inputTypes
The types of the parameters that are sent to the model as structured values. Objects among them are converted to maps with the JSON codec, so frameworks may need to register them, and the types they contain, for native images. Parameters ofContenttypes (such asImageContent) andImage, which are sent as contents, are left out. -
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. -
invokeWithResponse
public DecisionResult<Object> invokeWithResponse(DecisionServiceConfig config, DecisionRequest request) Invokes this method synchronously with the given request, typically created withtoRequest(Object[]), and returns both its result and the response of the decision model, for frameworks that need the raw answers (for example their probabilities or the token usage) whatever the declared return type of the method.- Returns:
- the result of the method as
content(itself aDecisionResultwhen the method declares one) and the response of the model asresponse.
-
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.
-