Package dev.langchain4j.model.output
Class Response
-
- All Implemented Interfaces:
public class Response<T>Represents the response from various types of models, including language, chat, embedding, and moderation models. This class encapsulates the generated content, token usage statistics, finish reason, and response metadata.
-
-
Constructor Summary
Constructors Constructor Description Response(T content)Create a new Response. Response(T content, TokenUsage tokenUsage, FinishReason finishReason)Create a new Response. Response(T content, TokenUsage tokenUsage, FinishReason finishReason, Map<String, Object> metadata)Create a new Response.
-
Method Summary
Modifier and Type Method Description Tcontent()Get the content. TokenUsagetokenUsage()Get the token usage statistics. FinishReasonfinishReason()Get the finish reason. Map<String, Object>metadata()Get the response metadata. booleanequals(Object o)inthashCode()StringtoString()static <T> Response<T>from(@NonNull() T content)Create a new Response. static <T> Response<T>from(@NonNull() T content, TokenUsage tokenUsage)Create a new Response. static <T> Response<T>from(@NonNull() T content, TokenUsage tokenUsage, FinishReason finishReason)Create a new Response. static <T> Response<T>from(@NonNull() T content, TokenUsage tokenUsage, FinishReason finishReason, @Nullable() Map<String, Object> metadata)Create a new Response. -
-
Constructor Detail
-
Response
Response(T content)
Create a new Response.- Parameters:
content- the content to wrap.
-
Response
Response(T content, TokenUsage tokenUsage, FinishReason finishReason)
Create a new Response.- Parameters:
content- the content to wrap.tokenUsage- the token usage statistics, ornull.finishReason- the finish reason, ornull.
-
Response
Response(T content, TokenUsage tokenUsage, FinishReason finishReason, Map<String, Object> metadata)
Create a new Response.- Parameters:
content- the content to wrap.tokenUsage- the token usage statistics, ornull.finishReason- the finish reason, ornull.metadata- the response metadata, ornull.
-
-
Method Detail
-
tokenUsage
TokenUsage tokenUsage()
Get the token usage statistics.
- Returns:
the token usage statistics, or
null.
-
finishReason
FinishReason finishReason()
Get the finish reason.
- Returns:
the finish reason, or
null.
-
metadata
@NonNull() Map<String, Object> metadata()
Get the response metadata.
- Returns:
the response metadata.
-
hashCode
int hashCode()
-
from
@NonNull() static <T> Response<T> from(@NonNull() T content)
Create a new Response.
- Parameters:
content- the content to wrap.- Returns:
the new Response.
-
from
@NonNull() static <T> Response<T> from(@NonNull() T content, TokenUsage tokenUsage)
Create a new Response.
- Parameters:
content- the content to wrap.tokenUsage- the token usage statistics.- Returns:
the new Response.
-
from
@NonNull() static <T> Response<T> from(@NonNull() T content, TokenUsage tokenUsage, FinishReason finishReason)
Create a new Response.
- Parameters:
content- the content to wrap.tokenUsage- the token usage statistics.finishReason- the finish reason.- Returns:
the new Response.
-
from
@NonNull() static <T> Response<T> from(@NonNull() T content, TokenUsage tokenUsage, FinishReason finishReason, @Nullable() Map<String, Object> metadata)
Create a new Response.
- Parameters:
content- the content to wrap.tokenUsage- the token usage statistics.finishReason- the finish reason.metadata- the response metadata.- Returns:
the new Response.
-
-
-
-