Package dev.langchain4j.service
Class Result<T>
java.lang.Object
dev.langchain4j.service.Result<T>
- Type Parameters:
T
- The type of the content. Can be of any return type supported by AI Services, such as String, Enum, MyCustomPojo, etc.
Represents the result of an AI Service invocation.
It contains actual content (LLM response) and additional information associated with it,
such as:
- AggregateTokenUsage
over all calls to theChatModel
-FinishReason
of the finalChatResponse
- sources (Content
s) retrieved during RAG retrieval - all executed tools (both requests and results) - all intermediateChatResponse
s - finalChatResponse
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionResult
(Result.ResultBuilder<T> builder) Result
(T content, TokenUsage tokenUsage, List<Content> sources, FinishReason finishReason, List<ToolExecution> toolExecutions) -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Result.ResultBuilder
<T> builder()
content()
Returns final chat response returned by theChatModel
.Returns finish reason of the finalChatModel
response (taken fromfinalResponse()
).Returns all intermediate chat responses that were returned by theChatModel
.sources()
Returns all sources returned during RAG retrieval.Returns aggregate token usage over all calls to theChatModel
.Returns all tool executions that happened during AI Service invocation.
-
Constructor Details
-
Result
- Since:
- 1.2.0
-
Result
public Result(T content, TokenUsage tokenUsage, List<Content> sources, FinishReason finishReason, List<ToolExecution> toolExecutions)
-
-
Method Details
-
builder
-
content
-
tokenUsage
Returns aggregate token usage over all calls to theChatModel
. -
sources
Returns all sources returned during RAG retrieval. -
finishReason
Returns finish reason of the finalChatModel
response (taken fromfinalResponse()
). -
toolExecutions
Returns all tool executions that happened during AI Service invocation. -
intermediateResponses
Returns all intermediate chat responses that were returned by theChatModel
. All of these responses containToolExecutionRequest
s.- Since:
- 1.2.0
-
finalResponse
Returns final chat response returned by theChatModel
. This response does not containToolExecutionRequest
s.- Since:
- 1.2.0
-