GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - ddobrin/gemini-workshop-for-spring-ai-java-developers: Gemini workshop for Java developers, using the Spring AI orchestration framework

BranchesTags
Open more actions menu

Latest commit

 

History

59 Commits
59 Commits

Folders and files

NameName
Last commit message
Last commit date
.mvn/wrapper
.mvn/wrapper
 
 
src/main
src/main
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
mvnw
mvnw
 
 
mvnw.cmd
mvnw.cmd
 
 
pom.xml
pom.xml
 
 

Repository files navigation

Gemini in Java with Google GenAI SDK and Spring AI

Gemini workshop for Java developers, using the Spring AI orchestration framework

Note

These snippets are geared towards Java developers, allowing them to discover capabilities and patterns supported by Gemini using the Spring AI framework.

Library support

  • Spring AI 2.0.0
  • Spring Boot 4.0.2
  • Jackson 3

Prerequisites

The code snippets have been tested on the following environment:

  • Java 21/25
  • Maven >= 3.9.6

In order to run these code snippets, you need to have a Google Cloud account and project ready or generate an API Key in Google AIStudio.

Before running the examples, you'll need to set up environment variables, for either Google credentials or or an API Key from Google AI Studio:

Credentials: 
  Google creds set:
    export GOOGLE_CLOUD_PROJECT=<your-project-id>
    export GOOGLE_CLOUD_LOCATION=<your region>, ex: us-central1
    export USE_VERTEX_AI=true

  Google API Key:
    export GOOGLE_API_KEY=...
    export USE_VERTEX_AI=false

Model:     
  export GEMINI_MODEL=<model>, ex: gemini-3-pro-preview, gemini-2.5-flash

Important

Please update the project ID and location to match your project and select the model of your choice

Create the Maven wrapper:

mvn wrapper:wrapper

Complete list

The snippets in this workshop are grouped by various capabilities and patterns. You will find, in order:

  • Chat
    • Simple Q&A with Gemini
    • Conversation with Gemini with chat history
    • Simple Q&A via streaming
  • Multimodality
    • Analyzing & extracting image data using Multimodality
    • Transcribing audio data using Multimodality
    • Transcribing video data using Multimodality
  • Capabilities
    • Structure prompts with prompt templates
    • Extracting structured data from unstructured text
    • Grounding responses with Web Search
    • Function Calling with Spring AI (multiple functions, JSON Schema, Async, Streaming)
  • Document utilities
    • Document Readers and Splitters
  • Embeddings
    • Generating Text Embeddings with Vertex AI
    • Generating Multimodal Embeddings with Vertex AI
  • Token Management
    • Compute Tokens
    • Count Tokens
    • Count Tokens with Configs
  • File Search Store
    • File Search Store (Sync)
    • File Search Store (Async)
  • AI use-cases and patterns
    • Retrieval-augmented generation(RAG)
    • Text classification with Few-shot prompting
    • Sentiment analysis with few-shot prompting
    • Summarization Patterns with Gemini: Stuffing, Map-Reduce Patterns
  • Local environments
    • Running Open-models with Ollama and Testcontainers

Build

Tip

Note the profile complete used for the build

Build the samples in a single JAR, then run them individually for the respective use-case:

./mvnw clean package -Pcomplete

Run

Tip

List of samples, by use-case. Each sample can be run independently

  • Chat

    • Simple Q&A with Gemini

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.SimpleChatExample
    • Conversation with Gemini with chat history

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.ConversationExample
    • Simple Q&A via streaming

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.SimpleChatStreamingExample
  • Multimodality

    • Analyzing & extracting image data using Multimodality

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.MultimodalImagesExample
    • Transcribing audio data using Multimodality

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.MultimodalAudioExample
    • Transcribing video data using Multimodality

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.MultimodalVideoExample
  • Capabilities

    • Structure prompts with prompt templates

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.WorkingWithTemplatesExample
    • Extracting structured data from unstructured text

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.StructuredOutputExample
    • Grounding responses with Web Search with GenAI SDK SDK

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.GroundingWithWebsearchExample
    • Grounding responses with Web Search with SpringAI

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.GroundingWithWebsearchSpringAIExample
    • Function Calling with Spring AI

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.FunctionCallingExample
    • Function Calling with Spring AI (Streaming)

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.FunctionCallingStreamingExample
    • Function Calling with Spring AI (Multiple Functions)

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.FunctionCallingMultipleExample
    • Function Calling with Spring AI (Async)

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.FunctionCallingAsyncExample
    • Function Calling with Spring AI (JSON Schema)

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.FunctionCallingJsonSchemaExample
    • File Search Store (Sync)

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.FileSearchStoreExample
    • File Search Store (Async)

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.FileSearchStoreAsyncExample
  • Document utilities

    • Document Readers and Splitters
      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.DocumentProcessingExample
  • Embeddings

    • Generating Text Embeddings with GenAI SDK

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.TextEmbeddingExample
    • Generating Multimodal Embeddings with GenAI SDK

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.MultimodalEmbeddingExample
  • Token Management

    • Compute Tokens

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.ComputeTokensExample
    • Count Tokens

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.CountTokensExample
    • Count Tokens with Configs

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.CountTokensWithConfigsExample
  • AI use-cases and patterns

    • Retrieval-augmented generation(RAG)

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.RAGExample
    • Text classification with Few-shot prompting

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.TextClassificationExample
    • Sentiment analysis with Few-shot prompting

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.SentimentAnalysisExample
    • Summarization Patterns with Gemini: Stuffing, Map-Reduce Patterns

      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.SummarizationExample
  • Local environments

    • Running Open-models with Ollama and Testcontainers
      java -cp ./target/spring-ai-workshop-1.0.0-jar-with-dependencies.jar gemini.workshop.LocalTestingWithOllamaContainers

Warning

This is not an official Google product. The snippets are provided for educational purposes only

About

Gemini workshop for Java developers, using the Spring AI orchestration framework

Resources

Readme
Apache-2.0 license
Activity

Stars

14 stars

Watchers

4 watching

Forks

4 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.