{"slug": "create-a-chatbot-with-google-generative-ai-and-quarkus", "title": "Create a Chatbot with Google Generative AI and Quarkus", "summary": "Developer Loïc Mathieu published a walkthrough showing how to build a chatbot with a new Quarkus extension, quarkus-google-cloud-genai, which injects a Client object into a Quarkus REST endpoint to call Google's Gemini models. The example exposes a /chat endpoint that sends each prompt to the \"gemini-3.8-flash\" model with a system instruction and returns the generated text, and Mathieu notes the bot has no memory of earlier turns until conversation history is added. The extension is available from code.quarkus.io alongside the quarkus-rest extension.", "body_md": "# Create a chatbot with Google Generative AI and Quarkus\n\nI recently created a Quarkus extension that provides access to [Google Generative AI](https://cloud.google.com/ai/generative-ai).\nIn this article, I’ll use this extension to create a chatbot.\n\nThe first step is to create a Quarkus project that includes the **REST** and **Google Cloud Gen AI** extensions.\n\nHere are the extensions to add to your dependencies file:\n\n```\n<dependency>\n        <groupId>io.quarkus</groupId>\n        <artifactId>quarkus-rest</artifactId>\n</dependency>\n<dependency>\n        <groupId>io.quarkiverse.googlecloudservices</groupId>\n        <artifactId>quarkus-google-cloud-genai</artifactId>\n</dependency>\n```\n\nOr, simpler, here’s a link that will let you create a project from [code.quarkus.io](https://code.quarkus.io/?g=fr.loicmathieu.google.genai&a=quarkus-gen-ai&e=rest&extension-search=rest,google-cloud-genai).\n\nThe extension allows you to inject a `Client` object into a Quarkus application to access the Google Cloud Generartive AI service. This service lets you use the **Gemini** generative AI model in a Google Cloud project.\n\nWe’ll use this extension in a REST endpoint to build a chatbot. Since I’m not too keen on developing UIs, I’ll use cURL to call the chatbot.\n\nHere’s the starting code for a chatbot:\n\n```\npackage fr.loicmathieu.google.genai;\n\n// [...] imports omitted for brevity\n\n// 1. Standard REST endpoint available on /chat\n@Path(\"/chat\")\npublic class GenAIResource {\n    // 2. System message telling the LLM it is a chatbot\n    private static final String SYSTEM_INSTRUCTION = \"\"\"\n        You are a chatbot named Loïc.\n        Don't pretend you know everything,\n        but be helpful with a touch of humour.\"\"\";\n\n    private GenerateContentConfig config;\n\n    // 3. Injection of the provided GenAI Client object\n    @Inject\n    Client client;\n\n    // 4. Init the configuration with the system instruction\n    @PostConstruct\n    void init() {\n        var systemInstruction = Content.fromParts(Part.fromText(SYSTEM_INSTRUCTION));\n        config = GenerateContentConfig.builder()\n            .systemInstruction(systemInstruction).build();\n    }\n\n    // 5. Generate a chat response on each call to /chat\n    @GET\n    public String chat(@QueryParam(\"prompt\") String prompt) {\n        return client.models\n            .generateContent(\"gemini-3.8-flash\", prompt, config).text() + \"\\n\";\n    }\n}\n```\n\n1. A REST endpoint using the JAX-RS standard, available at the `/chat` path in the application.\n2. System message informing the model that it is a chatbot and asking it to respond with a touch of humor.\n3. Injection of the `Client` GenAI service, which is provided by the**Quarkus Google Cloud GenAI** extension.\n4. Initialization of the configuration in the REST endpoint’s post-construct method.\n5. Each time the endpoint is called, we’ll invoke the model and return the first generated response. A real-world application would certainly implement something more advanced. Here, we’re using **Gemini Flash 3.8** because Gemini Flash is a model that combines performance with cost efficiency; exactly what we want for a chatbot that needs to respond quickly and doesn’t require overly complex*reasoning* .\n\nTo start the application in dev mode, you can use the Quarkus CLI: `quarkus dev`; the application will then be available on port 8080.\n\nTo call the chatbot, I use the following cURL command: `curl -G localhost:8080/chat --data-urlencode \"prompt=Tell me a joke\"`. For those who aren’t familiar with this, using `-G` forces cURL to perform a GET request, which will then pass the data as a query string in the URL. This helps avoid any encoding issues with spaces by using `--data-urlencode`.\n\nHere’s an example conversation:\n\nAs you can see, everything is going well until I ask him what my name is! Even though I just told him, he doesn’t know it because he has no memory.\n\nWe’re going to add a memory to the chatbot so we can have a real conversation with it; this is done through a chat session.\n\n```\npackage fr.loicmathieu.quarkus.vertexai;\n\n// [...] Imports omitted for brevity\n\n// 1. Standard REST endpoint available on /chat\n@Path(\"/chat\")\npublic class GenAIResource {\n    // 2. System message telling the LLM it is a chatbot\n    private static final String SYSTEM_INSTRUCTION = \"\"\"\n        You are a chatbot named Loïc.\n        Don't pretend you know everything;\n            but be helpful with a touch of humour.\"\"\";\n\n    private Chat chat;\n\n    // 3. Injection of the provided GenAI Client object\n    @Inject\n    Client client;\n\n    // 4. Init the configuration with the system instruction and a chat session\n    @PostConstruct\n    void init() {\n        var systemInstruction = Content.fromParts(Part.fromText(SYSTEM_INSTRUCTION));\n        var config = GenerateContentConfig.builder().\n            systemInstruction(systemInstruction).build();\n\n        chat = client.chats.create(\"gemini-3.8-flash\", config);\n    }\n\n    // 5. Generate a chat response on each call to /chat\n    @GET\n    public String chat(@QueryParam(\"prompt\") String prompt) {\n        return chat.sendMessage(prompt).text() + \"\\n\";\n    }\n}\n```\n\nWith a memory, the chatbot works much better!\n\nHere, I used a single chat session for the entire application, stored in memory (RAM). In a real-world scenario, you’ll of course need to use one chat session per user, ideally stored persistently.\n\nThat’s all for today; we’ve learned how to create a chatbot in Quarkus using Google Generative AI and the Gemini model.\nGoogle GenAI supports many other features: RAG, multimodal completion, tools, and more. You can find more information in its [documentation](https://github.com/googleapis/java-genai/tree/main).\n\nYou can find the project code on GitHub: [quarkus-gen-ai](https://github.com/loicmathieu/quarkus-gen-ai).\n\nThank you to Google for providing Google Cloud credits to write this article.", "url": "https://wpnews.pro/news/create-a-chatbot-with-google-generative-ai-and-quarkus", "canonical_source": "https://www.loicmathieu.fr/wordpress/informatique/create-a-chatbot-with-google-generative-ai-and-quarkus/", "published_at": "2026-12-03 12:31:42+00:00", "updated_at": "2026-12-03 12:47:09.096074+00:00", "lang": "en", "topics": ["generative-ai", "large-language-models", "ai-tools", "developer-tools"], "entities": ["Google", "Quarkus", "Gemini", "Loïc Mathieu", "quarkus-google-cloud-genai", "code.quarkus.io", "Google Cloud"], "also_reported_by": [], "takeaway": "Injecting the quarkus-google-cloud-genai Client into a JAX-RS endpoint and passing a GenerateContentConfig with a system instruction to client.models.generateContent(\"gemini-3.8-flash\", prompt, config) returns a chat reply in one call, but the bot forgets prior turns until conversation history is ad", "recommendation": {"advice": "Store conversation history and resend it with each request, since a stateless generateContent call with only a system instruction leaves the chatbot unable to recall earlier turns such as the user's name.", "playbook": "agent-architecture", "playbook_url": "https://wpnews.pro/playbooks/agent-architecture"}, "alternates": {"html": "https://wpnews.pro/news/create-a-chatbot-with-google-generative-ai-and-quarkus", "markdown": "https://wpnews.pro/news/create-a-chatbot-with-google-generative-ai-and-quarkus.md", "text": "https://wpnews.pro/news/create-a-chatbot-with-google-generative-ai-and-quarkus.txt", "jsonld": "https://wpnews.pro/news/create-a-chatbot-with-google-generative-ai-and-quarkus.jsonld"}}