Class GeminiAdapter
java.lang.Object
uno.anahata.ai.gemini.GeminiAdapter
A utility class for adapting Java types and objects to the Gemini API's data structures.
This class provides methods to:
- Generate
Schemaobjects from JavaTypes. - Extract tool call IDs from
Partobjects. - Sanitize model responses by ensuring all function calls have stable IDs.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic com.google.genai.types.SchemagetGeminiSchema(Class<?> clazz) Generates a GeminiSchemafor a given Java class.static com.google.genai.types.SchemagetGeminiSchema(Type type) Generates a GeminiSchemafor a given Java type.static com.google.genai.types.SchemagetGeminiSchema(Type type, boolean includeJsonSchemaId) Generates a GeminiSchemafor a given Java type, with an option to include a JSON schema ID.getToolCallId(com.google.genai.types.Part part) Extracts the tool call ID from a Part, checking both FunctionCall and FunctionResponse.static com.google.genai.types.Contentsanitize(com.google.genai.types.Content originalContent, AtomicInteger idCounter) Inspects a Content object from the model and ensures every FunctionCall part has a stable ID.
-
Constructor Details
-
GeminiAdapter
public GeminiAdapter()
-
-
Method Details
-
getGeminiSchema
-
getGeminiSchema
public static com.google.genai.types.Schema getGeminiSchema(Type type, boolean includeJsonSchemaId) throws Exception Generates a GeminiSchemafor a given Java type, with an option to include a JSON schema ID.- Parameters:
type- The Java type to convert.includeJsonSchemaId- Whether to include a unique ID in the schema.- Returns:
- The corresponding Gemini Schema.
- Throws:
Exception- if schema generation fails.
-
getGeminiSchema
-
getToolCallId
-
sanitize
public static com.google.genai.types.Content sanitize(com.google.genai.types.Content originalContent, AtomicInteger idCounter) Inspects a Content object from the model and ensures every FunctionCall part has a stable ID.If a FunctionCall is missing an ID, this method generates one and reconstructs the entire Content object to include it, preserving all other metadata.
- Parameters:
originalContent- The raw content received from the model.idCounter- The atomic counter to use for generating new IDs.- Returns:
- The original content if no changes were needed, or a new, patched Content object.
-
