Package com.google.genkit.ai
Class ModelResponse
java.lang.Object
com.google.genkit.ai.ModelResponse
ModelResponse represents a response from a generative AI model.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.ModelResponse(List<Candidate> candidates) Creates a ModelResponse with the given candidates. -
Method Summary
Modifier and TypeMethodDescriptionstatic ModelResponse.Builderbuilder()Creates a builder for ModelResponse.Returns the list of interrupt tool requests.Returns the first candidate's message.Returns all messages including the model's response.getText()Returns the text content from the first candidate's first text part.Returns all tool request parts from the first candidate.getUsage()booleanChecks if generation was interrupted.voidsetCandidates(List<Candidate> candidates) voidvoidsetFinishMessage(String finishMessage) voidsetFinishReason(FinishReason finishReason) voidsetInterrupts(List<Part> interrupts) voidsetLatencyMs(Long latencyMs) voidsetRequest(ModelRequest request) void
-
Constructor Details
-
ModelResponse
public ModelResponse()Default constructor. -
ModelResponse
Creates a ModelResponse with the given candidates.- Parameters:
candidates- the candidates
-
-
Method Details
-
builder
Creates a builder for ModelResponse.- Returns:
- a new builder
-
getText
Returns the text content from the first candidate's first text part.- Returns:
- the text content, or null if no text content is available
-
getMessage
Returns the first candidate's message.- Returns:
- the message, or null if no candidates
-
getMessages
Returns all messages including the model's response.This is useful when resuming after an interrupt - pass these messages to the next generate call to maintain context.
- Returns:
- list of all messages (request messages + model response)
-
getToolRequests
Returns all tool request parts from the first candidate.- Returns:
- list of tool requests
-
getCandidates
-
setCandidates
-
getUsage
-
setUsage
-
getRequest
-
setRequest
-
getCustom
-
setCustom
-
getLatencyMs
-
setLatencyMs
-
getFinishReason
-
setFinishReason
-
getFinishMessage
-
setFinishMessage
-
getInterrupts
Returns the list of interrupt tool requests.When the model requests tools that are interrupts, this list contains the tool request parts with interrupt metadata. Check if this list is non-empty to determine if generation was interrupted.
- Returns:
- list of interrupt tool request parts, or empty list if none
-
setInterrupts
-
isInterrupted
public boolean isInterrupted()Checks if generation was interrupted.- Returns:
- true if there are pending interrupts
-