Common shared infrastructure for integrating Google Gemini AI models with Quarkus applications through the LangChain4j framework, providing base chat model functionality, schema mapping, and embedding model support.
Multi-modal content structures supporting text, binary data (images), file references, function calls, and function responses. Content is organized into parts with role-based messaging compatible with Gemini's API format.
The primary container for multi-modal messages in chat conversations. Each Content instance has a role (user, model, system) and consists of one or more parts.
/**
* Represents content with a role and multiple parts.
*
* @param role The message role: "user", "model", or "system"
* @param parts List of content parts (text, images, function calls, etc.)
*/
public record Content(String role, List<Part> parts) {
/**
* Creates content with a single part.
*
* @param part The content part
* @return Content with the specified part
*/
public static Content ofPart(Part part);
}Individual components within a Content message. A part can be text, an inline image, a file reference, a function call, or a function response.
/**
* Individual part of content supporting multiple types.
*
* @param text Plain text content
* @param functionCall Function call from the model
* @param functionResponse Function response from the application
* @param fileData Reference to a file (e.g., in Google Cloud Storage)
* @param inlineData Inline binary data (e.g., base64-encoded image)
* @param thoughtSignature Signature for thinking/reasoning parts
*/
public record Part(
String text,
FunctionCall functionCall,
FunctionResponse functionResponse,
FileData fileData,
Blob inlineData,
String thoughtSignature
) {
/**
* Creates a text part.
*
* @param text The text content
* @return Part containing the text
*/
public static Part ofText(String text);
/**
* Creates a function call part.
*
* @param functionCall The function call
* @param thoughtSignature Optional signature for reasoning
* @return Part containing the function call
*/
public static Part ofFunctionCall(FunctionCall functionCall, String thoughtSignature);
/**
* Creates a function response part.
*
* @param functionResponse The function response
* @return Part containing the function response
*/
public static Part ofFunctionResponse(FunctionResponse functionResponse);
/**
* Creates a file data part.
*
* @param fileData The file reference
* @return Part containing the file reference
*/
public static Part ofFileData(FileData fileData);
/**
* Creates an inline data part.
*
* @param inlineData The binary data
* @return Part containing the inline data
*/
public static Part ofInlineData(Blob inlineData);
}Represents inline binary data with MIME type information, typically used for images embedded directly in requests.
/**
* Binary data with MIME type (e.g., base64-encoded images).
*
* @param mimeType The MIME type (e.g., "image/png", "image/jpeg")
* @param data Base64-encoded binary data
*/
public record Blob(String mimeType, String data);Represents a reference to a file stored externally, such as in Google Cloud Storage or Gemini's file API.
/**
* Reference to an external file with MIME type.
*
* @param mimeType The MIME type (e.g., "image/png", "application/pdf")
* @param fileUri The URI to the file (e.g., "gs://bucket/file.png")
*/
public record FileData(String mimeType, String fileUri);// Create a simple text message from the user
Content userMessage = new Content(
"user",
List.of(Content.Part.ofText("What is the capital of France?"))
);
// Using the ofPart convenience method
Content modelResponse = Content.ofPart(
Content.Part.ofText("The capital of France is Paris.")
);// Load and encode an image
byte[] imageBytes = Files.readAllBytes(Path.of("diagram.png"));
String base64Image = Base64.getEncoder().encodeToString(imageBytes);
// Create content with text and inline image
Content multiModalMessage = new Content(
"user",
List.of(
Content.Part.ofText("What does this diagram show?"),
Content.Part.ofInlineData(new Blob("image/png", base64Image))
)
);// Reference a file uploaded to Gemini or stored in GCS
FileData imageFile = new FileData(
"image/jpeg",
"gs://my-bucket/photos/landscape.jpg"
);
Content fileMessage = new Content(
"user",
List.of(
Content.Part.ofText("Describe this landscape photo."),
Content.Part.ofFileData(imageFile)
)
);// Model's function call response
FunctionCall call = new FunctionCall(
"get_weather",
Map.of(
"location", "New York",
"unit", "celsius"
)
);
Content functionCallMessage = Content.ofPart(
Content.Part.ofFunctionCall(call, null)
);// Application's function execution result
FunctionResponse.Response response = new FunctionResponse.Response(
"get_weather",
Map.of(
"temperature", 22,
"condition", "sunny",
"humidity", 65
)
);
FunctionResponse functionResponse = new FunctionResponse("get_weather", response);
Content functionResponseMessage = Content.ofPart(
Content.Part.ofFunctionResponse(functionResponse)
);// Combine multiple content types in a single message
Content complexMessage = new Content(
"user",
List.of(
Content.Part.ofText("Here are the images from our meeting:"),
Content.Part.ofInlineData(new Blob("image/png", base64Image1)),
Content.Part.ofInlineData(new Blob("image/png", base64Image2)),
Content.Part.ofText("Please analyze both images and compare them.")
)
);List<Content> conversation = new ArrayList<>();
// User's initial message
conversation.add(new Content(
"user",
List.of(Content.Part.ofText("I need help analyzing this chart."))
));
// User's follow-up with image
byte[] chartBytes = Files.readAllBytes(Path.of("chart.png"));
String base64Chart = Base64.getEncoder().encodeToString(chartBytes);
conversation.add(new Content(
"user",
List.of(Content.Part.ofInlineData(new Blob("image/png", base64Chart)))
));
// Model's response
conversation.add(Content.ofPart(
Content.Part.ofText("This chart shows quarterly revenue trends...")
));
// Use in a request
GenerateContentRequest request = new GenerateContentRequest(
conversation,
null, // systemInstruction
null, // tools
null // generationConfig
);image/pngimage/jpegimage/webpimage/heicimage/heifapplication/pdftext/plaintext/htmlaudio/wavaudio/mp3video/mp4video/mpeg(Note: Specific model support varies. Check Gemini model capabilities for supported media types.)
Content types integrate with:
Install with Tessl CLI
npx tessl i tessl/maven-io-quarkiverse-langchain4j--quarkus-langchain4j-gemini-common@1.7.0