Class GeminiModelMessage

All Implemented Interfaces:
PropertyChangeSource, Rebindable

public class GeminiModelMessage extends AbstractModelMessage<GeminiResponse>
An object-oriented representation of a ModelMessage derived from the Gemini provider. This class encapsulates the logic for constructing a valid ModelMessage from a Gemini Content object, ensuring the parent message is created before its parts.
Author:
anahata-ai
  • Field Details

    • geminiCandidate

      private final transient com.google.genai.types.Candidate geminiCandidate
      The original, native Candidate object from the Google GenAI API.
  • Constructor Details

    • GeminiModelMessage

      public GeminiModelMessage(Agi agi, String modelId)
      Constructs a GeminiModelMessage for streaming, without an initial candidate.
      Parameters:
      agi - The parent agi session.
      modelId - The ID of the model.
    • GeminiModelMessage

      public GeminiModelMessage(Agi agi, String modelId, com.google.genai.types.Candidate candidate, GeminiResponse response)
      Constructs a GeminiModelMessage, encapsulating the conversion logic.
      Parameters:
      agi - The parent agi session.
      modelId - The ID of the model that generated the content.
      candidate - The source Gemini Candidate object.
      response - The GeminiResponse that returned this message.
  • Method Details

    • toAnahataPart

      public AbstractPart toAnahataPart(com.google.genai.types.Part googlePart)
      Converts a Google GenAI Part to an Anahata AbstractPart within the context of this message.

      Implementation details: This method encapsulates the logic previously in PartAdapter and FunctionCallAdapter, handling text, thoughts, tool calls, and multimodal data.

      Parameters:
      googlePart - The Google part to convert.
      Returns:
      The corresponding Anahata AbstractPart, or null if unsupported.
    • toAnahataToolCall

      private AbstractToolCall toAnahataToolCall(com.google.genai.types.FunctionCall googleFc)
      Converts a Google GenAI FunctionCall to an Anahata AbstractToolCall.
      Parameters:
      googleFc - The FunctionCall received from the Google API.
      Returns:
      A new AbstractToolCall.
    • toAnahataGroundingMetadata

      public static GroundingMetadata toAnahataGroundingMetadata(com.google.genai.types.GroundingMetadata gm)
      Converts Google's GroundingMetadata to Anahata's domain model.
      Parameters:
      gm - The Google GroundingMetadata object.
      Returns:
      The Anahata GroundingMetadata object.
    • toAnahataFinishReason

      public static FinishReason toAnahataFinishReason(com.google.genai.types.FinishReason fr)
      Maps a Google GenAI FinishReason to the Anahata FinishReason enum.
      Parameters:
      fr - The Google FinishReason object.
      Returns:
      The corresponding Anahata FinishReason.