Package dev.langchain4j.model.output
Class Response<T>
java.lang.Object
dev.langchain4j.model.output.Response<T>
- Type Parameters:
T
- The type of content generated by the model.
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
ConstructorDescriptionCreate 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 TypeMethodDescriptioncontent()
Get the content.boolean
Get the finish reason.static <T> Response
<T> from
(T content) Create a new Response.static <T> Response
<T> from
(T content, TokenUsage tokenUsage) Create a new Response.static <T> Response
<T> from
(T content, TokenUsage tokenUsage, FinishReason finishReason) Create a new Response.static <T> Response
<T> from
(T content, TokenUsage tokenUsage, FinishReason finishReason, Map<String, Object> metadata) Create a new Response.int
hashCode()
metadata()
Get the response metadata.Get the token usage statistics.toString()
-
Constructor Details
-
Response
Create a new Response.Will contain
null
TokenUsage
andFinishReason
- Parameters:
content
- the content to wrap.
-
Response
Create a new Response.- Parameters:
content
- the content to wrap.tokenUsage
- the token usage statistics, ornull
.finishReason
- the finish reason, ornull
.
-
Response
public 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 Details
-
content
Get the content.- Returns:
- the content.
-
tokenUsage
Get the token usage statistics.- Returns:
- the token usage statistics, or
null
.
-
finishReason
Get the finish reason.- Returns:
- the finish reason, or
null
.
-
metadata
Get the response metadata.- Returns:
- the response metadata.
-
equals
-
hashCode
public int hashCode() -
toString
-
from
Create a new Response.- Type Parameters:
T
- the type of content.- Parameters:
content
- the content to wrap.- Returns:
- the new Response.
-
from
Create a new Response.- Type Parameters:
T
- the type of content.- Parameters:
content
- the content to wrap.tokenUsage
- the token usage statistics.- Returns:
- the new Response.
-
from
Create a new Response.- Type Parameters:
T
- the type of content.- Parameters:
content
- the content to wrap.tokenUsage
- the token usage statistics.finishReason
- the finish reason.- Returns:
- the new Response.
-
from
public static <T> Response<T> from(T content, TokenUsage tokenUsage, FinishReason finishReason, Map<String, Object> metadata) Create a new Response.- Type Parameters:
T
- the type of content.- Parameters:
content
- the content to wrap.tokenUsage
- the token usage statistics.finishReason
- the finish reason.metadata
- the response metadata.- Returns:
- the new Response.
-