<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hieu Duong</title>
    <description>The latest articles on DEV Community by Hieu Duong (@duongminhhieu).</description>
    <link>https://dev.to/duongminhhieu</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1914433%2F913fca36-1211-436d-9ed5-fa93f7847c97.png</url>
      <title>DEV Community: Hieu Duong</title>
      <link>https://dev.to/duongminhhieu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/duongminhhieu"/>
    <language>en</language>
    <item>
      <title>My Experience with Unexpected AWS Charges (and How I Got a Refund)</title>
      <dc:creator>Hieu Duong</dc:creator>
      <pubDate>Sun, 27 Apr 2025 08:10:17 +0000</pubDate>
      <link>https://dev.to/duongminhhieu/my-experience-with-unexpected-aws-charges-and-how-i-got-a-refund-1n7b</link>
      <guid>https://dev.to/duongminhhieu/my-experience-with-unexpected-aws-charges-and-how-i-got-a-refund-1n7b</guid>
      <description>&lt;p&gt;As someone who's passionate about cloud computing and always looking to learn new things, I signed up for an AWS Free Tier account to practice deploying web applications and experimenting with services like EC2, RDS,…. Everything was going well - until one day, I received a bill I wasn't expecting.&lt;/p&gt;

&lt;h2&gt;
  
  
  😨 The Shock: A $39 Bill from AWS
&lt;/h2&gt;

&lt;p&gt;I had completely forgotten to stop some of the services I was testing, particularly Amazon RDS and VPC components. At the end of the month, I was charged $39.42, even though I thought I was still within the Free Tier limits.&lt;/p&gt;

&lt;p&gt;As a student on a tight budget, this was quite a surprise - and honestly, a little stressful.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Favnvdzvzeggop12jmw16.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Favnvdzvzeggop12jmw16.png" alt="Image description" width="800" height="781"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  📞 Reaching Out to AWS Support
&lt;/h2&gt;

&lt;p&gt;I didn't panic (well, maybe a little). I went to the &lt;a href="https://console.aws.amazon.com/support/home" rel="noopener noreferrer"&gt;AWS Support Center&lt;/a&gt; and created a billing support case. Here's what I did:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Choose the button "Create Case"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Selected "Account and Billing"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Select options question: &lt;strong&gt;Service&lt;/strong&gt;, &lt;strong&gt;Category&lt;/strong&gt;, and &lt;strong&gt;Severity&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Service&lt;/strong&gt;: Billing&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Category&lt;/strong&gt;: Other Billing Question&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Severity&lt;/strong&gt;: General Question&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fta2adc9qe1aiyoj6wtjd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fta2adc9qe1aiyoj6wtjd.png" alt="Image description" width="800" height="338"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. The next step is to type Subject, Description, and information about the invoice.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Subject&lt;/strong&gt;: Request for Refund Due to Unintended Usage Beyond Free Tier&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Dear AWS Support Team,

I hope this message finds you well.

I am a student using AWS for educational and practice purposes under the Free Tier. Recently, I received an invoice (Invoice #xxx) for $39.42 for the period March 1 – March 31, 2025. It appears I forgot to stop some services (Amazon RDS and VPC), which caused these unexpected charges.

I was not aware that these services were still running and did not intend to exceed the Free Tier usage. I have now stopped the services to avoid further charges.

As this is my first time experiencing this issue and I'm using AWS primarily for learning purposes, I kindly request your assistance in waiving the charges.

Thank you very much for your understanding and support.

Best regards, 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: There are some recommended fields below, which should update the information in this.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. After that, choose Next Step and select the support options. I choose Chat options, and choose Submit.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxfvimjw85426hxq3u9pv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxfvimjw85426hxq3u9pv.png" alt="Image description" width="800" height="316"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Immediately, AWS opens a new Windows chat. Within a few minutes, I received a friendly response from the AWS team. &lt;/p&gt;

&lt;p&gt;They will give me instructions to turn off the services that are charging money.&lt;/p&gt;

&lt;p&gt;They told me they had forwarded my request to the billing adjustment team, and that I just needed to wait about 24 hours for a final decision.&lt;/p&gt;

&lt;h2&gt;
  
  
  ✨ The Result: Full Waiver and Credit!
&lt;/h2&gt;

&lt;p&gt;The next day, I received an email with great news:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;entire March invoice was waived.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;I was also given a &lt;strong&gt;$33.22&lt;/strong&gt; credit toward my April usage.&lt;/li&gt;
&lt;li&gt;The credit appeared in my Billing Console and will automatically be applied to future charges.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I checked my&lt;a href="https://console.aws.amazon.com/billing/home#/credits" rel="noopener noreferrer"&gt; Credits page&lt;/a&gt;, and sure enough - there it was, untouched and ready to go!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwwfo7667d45y7nwtl6vc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwwfo7667d45y7nwtl6vc.png" alt="Image description" width="800" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🔐 Lessons Learned (the Hard Way)
&lt;/h2&gt;

&lt;p&gt;Here are a few important lessons I took away from this experience:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Always double-check&lt;/strong&gt; your running resources, especially databases, VPCs, and anything that runs 24/7.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Set up billing alarms&lt;/strong&gt; in CloudWatch to get notified when charges go beyond a threshold. It's super easy and can save you a lot of money.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don't hesitate to contact AWS Support&lt;/strong&gt; - they're helpful and understanding, especially for first-time mistakes and learning scenarios.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  💬 Final Thoughts
&lt;/h2&gt;

&lt;p&gt;This experience was a wake-up call, but also a good reminder that learning in the cloud comes with real-world responsibilities (and costs!). Thankfully, AWS was supportive and fair, and now I'm much more careful with my resource usage.&lt;/p&gt;

&lt;p&gt;If you're learning AWS and using the Free Tier, don't be afraid to make mistakes, but do be proactive in monitoring your resources.&lt;/p&gt;

&lt;p&gt;Have you had a similar experience with cloud billing? Feel free to share it - I'd love to hear how you handled it!&lt;/p&gt;

</description>
      <category>aws</category>
    </item>
    <item>
      <title>Image-Based Product Search Using Spring Boot, Google Cloud Vertex AI, and Gemini Model</title>
      <dc:creator>Hieu Duong</dc:creator>
      <pubDate>Tue, 13 Aug 2024 15:08:09 +0000</pubDate>
      <link>https://dev.to/duongminhhieu/image-based-product-search-using-spring-boot-google-cloud-vertex-ai-and-gemini-model-7io</link>
      <guid>https://dev.to/duongminhhieu/image-based-product-search-using-spring-boot-google-cloud-vertex-ai-and-gemini-model-7io</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Imagine you’re shopping online and come across a product you love but don’t know its name. Wouldn’t it be amazing to upload a picture and have the app find it for you?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feg4nox2xgvb1o50tta3j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feg4nox2xgvb1o50tta3j.png" alt="Image description" width="800" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this article, we’ll show you how to build exactly that: an image-based product search feature using Spring Boot and Google Cloud Vertex AI.&lt;/p&gt;

&lt;h2&gt;
  
  
  Overview of the Feature
&lt;/h2&gt;

&lt;p&gt;This feature allows users to upload an image and receive a list of products that match it, making the search experience more intuitive and visually driven.&lt;/p&gt;

&lt;p&gt;The image-based product search feature leverages Google Cloud Vertex AI to process images and extract relevant keywords. These keywords are then used to search for matching products in the database.&lt;/p&gt;

&lt;h3&gt;
  
  
  Technology Stack
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Java 21&lt;/li&gt;
&lt;li&gt;Spring boot 3.2.5&lt;/li&gt;
&lt;li&gt;PostgreSQL&lt;/li&gt;
&lt;li&gt;Vertex AI&lt;/li&gt;
&lt;li&gt;ReactJS&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We’ll walk through the process of setting up this functionality step-by-step.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step-by-Step Implementation
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwfzf3zspzwirwjxye9oj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwfzf3zspzwirwjxye9oj.png" alt="Image" width="800" height="478"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Create a new project on Google Console
&lt;/h3&gt;

&lt;p&gt;First, we need to create a new project on Google Console for this.&lt;/p&gt;

&lt;p&gt;We need to go to &lt;a href="https://console.cloud.google.com" rel="noopener noreferrer"&gt;https://console.cloud.google.com&lt;/a&gt; and create a new account if you already have one. If you have one, sign in to the account.&lt;/p&gt;

&lt;p&gt;If you add your bank account, Google Cloud will offer you a free trial.&lt;/p&gt;

&lt;p&gt;Once you have created an account or signed in to an already existing account, you can create a new project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fep01wz81zo6goewko0kx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fep01wz81zo6goewko0kx.png" alt="Image description" width="800" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Enable Vertex AI Service
&lt;/h3&gt;

&lt;p&gt;On the search bar, we need to find Vertex AI and enable all recommended APIs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk0aalqt13omly5lyaawf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk0aalqt13omly5lyaawf.png" alt="Image description" width="800" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Vertex AI&lt;/strong&gt; is Google Cloud’s fully managed machine learning (ML) platform designed to simplify the development, deployment, and management of ML models. It allows you to build, train, and deploy ML models at scale by providing tools and services like AutoML, custom model training, hyperparameter tuning, and model monitoring&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gemini 1.5 Flash&lt;/strong&gt; is part of Google’s Gemini family of models, specifically designed for efficient and high-performance inference in ML applications. Gemini models are a series of advanced AI models developed by Google, often used in natural language processing (NLP), vision tasks, and other AI-powered applications&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; For other frameworks, you can use Gemini API directly at &lt;a href="https://aistudio.google.com/app/prompts/new_chat" rel="noopener noreferrer"&gt;https://aistudio.google.com/app/prompts/new_chat&lt;/a&gt;. Use the structure prompt feature because you can customize your output to match the input so you will get better results.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Create a new prompt that matches your application
&lt;/h3&gt;

&lt;p&gt;At this step, we need to customize a prompt that matching with your application.&lt;/p&gt;

&lt;p&gt;Vertex AI Studio has provided a lot of sample prompts at &lt;strong&gt;Prompt Gallery&lt;/strong&gt;. We use sample &lt;em&gt;&lt;strong&gt;Image text to JSON&lt;/strong&gt;&lt;/em&gt; to extract keywords that are related to the product image.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feqxqlvj76gyiu5nfjn5o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feqxqlvj76gyiu5nfjn5o.png" alt="Image description" width="800" height="442"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My application is a CarShop, so I build a prompt like this. My expectation the model will respond to me with a list of keywords relating to the image.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;My prompt: &lt;em&gt;&lt;strong&gt;Extract the name car to a list keyword and output them in JSON. If you don’t find any information about the car, please output the list empty.\nExample response: [\”rolls\”, \”royce\”, \”wraith\”]&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa7pieuyodk0a5hkh8fdr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa7pieuyodk0a5hkh8fdr.png" alt="Image description" width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After we customize a suitable prompt with your application. Now, we go to explore how to integrate with Spring Boot Application.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Integrate with Spring Boot Application
&lt;/h3&gt;

&lt;p&gt;I have built an E-commerce application about cars. So I want to find cars by the image.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx9peqs6q0319kaewdt4m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx9peqs6q0319kaewdt4m.png" alt="Image description" width="800" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First, in the pom.xml file, you should update your dependency:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!-- config version for dependency--&amp;gt;
&amp;lt;properties&amp;gt;
    &amp;lt;spring-cloud-gcp.version&amp;gt;5.1.2&amp;lt;/spring-cloud-gcp.version&amp;gt;
    &amp;lt;google-cloud-bom.version&amp;gt;26.32.0&amp;lt;/google-cloud-bom.version&amp;gt;
&amp;lt;/properties&amp;gt;

&amp;lt;!-- In your dependencyManagement, please add 2 dependencies below --&amp;gt;
&amp;lt;dependencyManagement&amp;gt;
  &amp;lt;dependencies&amp;gt;
      &amp;lt;dependency&amp;gt;
          &amp;lt;groupId&amp;gt;com.google.cloud&amp;lt;/groupId&amp;gt;
          &amp;lt;artifactId&amp;gt;spring-cloud-gcp-dependencies&amp;lt;/artifactId&amp;gt;
          &amp;lt;version&amp;gt;${spring-cloud-gcp.version}&amp;lt;/version&amp;gt;
          &amp;lt;type&amp;gt;pom&amp;lt;/type&amp;gt;
          &amp;lt;scope&amp;gt;import&amp;lt;/scope&amp;gt;
      &amp;lt;/dependency&amp;gt;

      &amp;lt;dependency&amp;gt;
          &amp;lt;groupId&amp;gt;com.google.cloud&amp;lt;/groupId&amp;gt;
          &amp;lt;artifactId&amp;gt;libraries-bom&amp;lt;/artifactId&amp;gt;
          &amp;lt;version&amp;gt;${google-cloud-bom.version}&amp;lt;/version&amp;gt;
          &amp;lt;type&amp;gt;pom&amp;lt;/type&amp;gt;
          &amp;lt;scope&amp;gt;import&amp;lt;/scope&amp;gt;
      &amp;lt;/dependency&amp;gt;
  &amp;lt;/dependencies&amp;gt;
&amp;lt;/dependencyManagement&amp;gt;

&amp;lt;!-- In your tab dependencies, please add the dependency below --&amp;gt;
&amp;lt;dependencies&amp;gt;
  &amp;lt;dependency&amp;gt;
      &amp;lt;groupId&amp;gt;com.google.cloud&amp;lt;/groupId&amp;gt;
      &amp;lt;artifactId&amp;gt;google-cloud-vertexai&amp;lt;/artifactId&amp;gt;
  &amp;lt;/dependency&amp;gt;
&amp;lt;/dependencies&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After you have done the config in the pom.xml file, you create a config class &lt;strong&gt;GeminiConfig.java&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;MODEL_NAME: &lt;strong&gt;&lt;em&gt;“gemini-1.5-flash”&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;LOCATION: &lt;em&gt;&lt;strong&gt;“Your location when setting up the project”&lt;/strong&gt;&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;PROJECT_ID: &lt;strong&gt;&lt;em&gt;“your project ID ”&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhgb3henbvagdneocfga6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhgb3henbvagdneocfga6.png" alt="Image description" width="800" height="299"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import com.google.cloud.vertexai.VertexAI;
import com.google.cloud.vertexai.generativeai.GenerativeModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
public class GeminiConfig {

    private static final String MODEL_NAME = "gemini-1.5-flash";
    private static final String LOCATION = "asia-southeast1";
    private static final String PROJECT_ID = "yasmini";

    @Bean
    public VertexAI vertexAI() {
        return new VertexAI(PROJECT_ID, LOCATION);
    }

    @Bean
    public GenerativeModel getModel(VertexAI vertexAI) {
        return new GenerativeModel(MODEL_NAME, vertexAI);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Second, create layers Service, Controller to implement the find car function. Create class service.&lt;/p&gt;

&lt;p&gt;Because the Gemini API responds with markdown format, we need to create a function to help convert to JSON, and from JSON we will convert to List string in Java.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzpf5i8xkt3ci2qs3vz1e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzpf5i8xkt3ci2qs3vz1e.png" alt="Image description" width="800" height="161"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.cloud.vertexai.api.Content;
import com.google.cloud.vertexai.api.GenerateContentResponse;
import com.google.cloud.vertexai.api.Part;
import com.google.cloud.vertexai.generativeai.*;
import com.learning.yasminishop.common.entity.Product;
import com.learning.yasminishop.common.exception.AppException;
import com.learning.yasminishop.common.exception.ErrorCode;
import com.learning.yasminishop.product.ProductRepository;
import com.learning.yasminishop.product.dto.response.ProductResponse;
import com.learning.yasminishop.product.mapper.ProductMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

@Service
@RequiredArgsConstructor
@Slf4j
@Transactional(readOnly = true)
public class YasMiniAIService {

    private final GenerativeModel generativeModel;
    private final ProductRepository productRepository;

    private final ProductMapper productMapper;


    public List&amp;lt;ProductResponse&amp;gt; findCarByImage(MultipartFile file){
        try {
            var prompt = "Extract the name car to a list keyword and output them in JSON. If you don't find any information about the car, please output the list empty.\nExample response: [\"rolls\", \"royce\", \"wraith\"]";
            var content = this.generativeModel.generateContent(
                    ContentMaker.fromMultiModalData(
                            PartMaker.fromMimeTypeAndData(Objects.requireNonNull(file.getContentType()), file.getBytes()),
                            prompt
                    )
            );

            String jsonContent = ResponseHandler.getText(content);
            log.info("Extracted keywords from image: {}", jsonContent);
            List&amp;lt;String&amp;gt; keywords = convertJsonToList(jsonContent).stream()
                    .map(String::toLowerCase)
                    .toList();

            Set&amp;lt;Product&amp;gt; results = new HashSet&amp;lt;&amp;gt;();
            for (String keyword : keywords) {
                List&amp;lt;Product&amp;gt; products = productRepository.searchByKeyword(keyword);
                results.addAll(products);
            }

            return results.stream()
                    .map(productMapper::toProductResponse)
                    .toList();

        } catch (Exception e) {
            log.error("Error finding car by image", e);
            return List.of();
        }
    }

    private List&amp;lt;String&amp;gt; convertJsonToList(String markdown) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        String parseJson = markdown;
        if(markdown.contains("```

json")){
            parseJson = extractJsonFromMarkdown(markdown);
        }
        return objectMapper.readValue(parseJson, List.class);
    }

    private String extractJsonFromMarkdown(String markdown) {
        return markdown.replace("

```json\n", "").replace("\n```

", "");
    }
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We need to create a controller class to make an endpoint for front end&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import com.learning.yasminishop.product.dto.response.ProductResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/ai")
@RequiredArgsConstructor
@Slf4j
public class YasMiniAIController {

    private final YasMiniAIService yasMiniAIService;


    @PostMapping
    public List&amp;lt;ProductResponse&amp;gt; findCar(@RequestParam("file") MultipartFile file) {

        var response = yasMiniAIService.findCarByImage(file);
        return response;
    }
}



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  5. IMPORTANT step: Login to Google Cloud with Google Cloud CLI
&lt;/h3&gt;

&lt;p&gt;The Spring Boot Application can not verify who you are and isn't able for you to accept the resource in Google Cloud.&lt;/p&gt;

&lt;p&gt;So we need to log in to Google and provide authorization.&lt;/p&gt;
&lt;h4&gt;
  
  
  5.1 First we need to install GCloud CLI on your machine
&lt;/h4&gt;

&lt;p&gt;Link tutorial: &lt;a href="https://cloud.google.com/sdk/docs/install" rel="noopener noreferrer"&gt;https://cloud.google.com/sdk/docs/install&lt;/a&gt;&lt;br&gt;
Check the above link and install it on your machine&lt;/p&gt;
&lt;h4&gt;
  
  
  5.2 Login
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Open your terminal at the project (you must cd into the project)&lt;/li&gt;
&lt;li&gt;Type: gcloud auth login&lt;/li&gt;
&lt;li&gt;Enter, and you will see the windows that allow you to login&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

gcloud auth login


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgpuhp5o1a95ct27i0ibq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgpuhp5o1a95ct27i0ibq.png" alt="Image description" width="800" height="639"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1y6qbu8paj7eb6cppe58.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1y6qbu8paj7eb6cppe58.png" alt="Image description" width="800" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; After you log in, credentials are saved in the Google Maven package, and you don’t need to log in again when restart the Spring Boot application.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;So these implement above based on my project E-commerce, you can modify matching with your project, and your framework. In other frameworks, not spring boot (NestJs, ..), you can use &lt;a href="https://aistudio.google.com/app/prompts/new_chat" rel="noopener noreferrer"&gt;https://aistudio.google.com/app/prompts/new_chat&lt;/a&gt;. and don’t need to create a new Google Cloud account.&lt;/p&gt;

&lt;p&gt;You can check the detailed implementation at my repo:&lt;/p&gt;

&lt;p&gt;Backend: &lt;a href="https://github.com/duongminhhieu/YasMiniShop" rel="noopener noreferrer"&gt;https://github.com/duongminhhieu/YasMiniShop&lt;/a&gt;&lt;br&gt;
Front-end: &lt;a href="https://github.com/duongminhhieu/YasMini-Frontend" rel="noopener noreferrer"&gt;https://github.com/duongminhhieu/YasMini-Frontend&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy learning !!!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>ai</category>
      <category>java</category>
      <category>springboot</category>
    </item>
  </channel>
</rss>
