Class GeminiResponse
A specialized, object-oriented Response class for the Gemini provider.
It encapsulates all the logic for converting a native Google GenerateContentResponse
into the Anahata domain model, making it a self-contained and reusable component.
- Author:
- anahata
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<GeminiModelMessage> The list of converted model messages.private final com.google.genai.types.GenerateContentResponseThe original, native response object from the Google GenAI API. transient to avoid serialization of SDK types.private final StringThe model version used for this specific generation.Optional feedback from the safety filters.private final StringThe raw JSON of the conversation history sent in the request.private final StringThe raw JSON of the entire response.private final StringThe raw JSON of the request configuration.private final ResponseUsageMetadataThe converted usage metadata. -
Constructor Summary
ConstructorsConstructorDescriptionGeminiResponse(String requestConfigJson, String historyJson, Agi agi, String modelId, com.google.genai.types.GenerateContentResponse genaiResponse) Constructs a GeminiResponse, performing the full conversion from the native Google GenAI response to the Anahata domain model. -
Method Summary
Modifier and TypeMethodDescriptionprivate ResponseUsageMetadataconvertUsageMetadata(com.google.genai.types.GenerateContentResponseUsageMetadata genaiUsage) Converts the native GenAI usage metadata to the V2 core model.intGets the total number of tokens for the entire interaction (prompt + all candidates).Methods inherited from class Response
getCandidates, getPromptFeedback, getRawHistoryJson, getRawJson, getRawRequestConfigJson, getUsageMetadata
-
Field Details
-
genaiResponse
private final transient com.google.genai.types.GenerateContentResponse genaiResponseThe original, native response object from the Google GenAI API. transient to avoid serialization of SDK types. -
candidates
The list of converted model messages. -
usageMetadata
The converted usage metadata. -
promptFeedback
-
rawRequestConfigJson
The raw JSON of the request configuration. -
rawHistoryJson
The raw JSON of the conversation history sent in the request. -
rawJson
The raw JSON of the entire response. -
modelVersion
The model version used for this specific generation.
-
-
Constructor Details
-
GeminiResponse
public GeminiResponse(String requestConfigJson, String historyJson, Agi agi, String modelId, com.google.genai.types.GenerateContentResponse genaiResponse) Constructs a GeminiResponse, performing the full conversion from the native Google GenAI response to the Anahata domain model.- Parameters:
requestConfigJson- The raw JSON of the request configuration.historyJson- The raw JSON of the conversation history sent in the request.agi- The parent agi session, required for constructing model messages.modelId- The ID of the model that generated this response.genaiResponse- The native response object from the API.
-
-
Method Details
-
convertUsageMetadata
private ResponseUsageMetadata convertUsageMetadata(com.google.genai.types.GenerateContentResponseUsageMetadata genaiUsage) Converts the native GenAI usage metadata to the V2 core model.- Parameters:
genaiUsage- The native usage metadata.- Returns:
- The V2
ResponseUsageMetadata.
-
getTotalTokenCount
public int getTotalTokenCount()Gets the total number of tokens for the entire interaction (prompt + all candidates).- Specified by:
getTotalTokenCountin classResponse<GeminiModelMessage>- Returns:
- The total token count.
-

