Class ModelResponseChunk

java.lang.Object
com.google.genkit.ai.ModelResponseChunk

public class ModelResponseChunk extends Object
ModelResponseChunk represents a streaming chunk from a generative AI model.
  • Constructor Details

    • ModelResponseChunk

      public ModelResponseChunk()
      Default constructor.
    • ModelResponseChunk

      public ModelResponseChunk(List<Part> content)
      Creates a ModelResponseChunk with the given content.
      Parameters:
      content - the content parts
  • Method Details

    • text

      public static ModelResponseChunk text(String text)
      Creates a ModelResponseChunk with text content.
      Parameters:
      text - the text content
      Returns:
      a new chunk
    • getText

      public String getText()
      Returns the text content from all text parts.
      Returns:
      the concatenated text, or null if no text content
    • getRole

      public Role getRole()
      Returns the role of the message this chunk contributes to.
      Returns:
      the role, or null if not set (defaults to model on the wire)
    • setRole

      public void setRole(Role role)
      Sets the role of the message this chunk contributes to.
      Parameters:
      role - the role
    • getContent

      public List<Part> getContent()
    • setContent

      public void setContent(List<Part> content)
    • getIndex

      public Integer getIndex()
    • setIndex

      public void setIndex(Integer index)