Use Google Gemini (Free version) in VSCode - Step by Step Installation Guide

You want to try an AI tool to help you with coding, but you don't want to pay for it. You can use Gemini free version. Free version of Gemini is based on the Gemini Pro model and is capable of assisting you with coding.

Use Google Gemini (Free version) in VSCode  - Step by Step Installation Guide

You want to try an AI tool to help you with coding, but you don't want to pay for it.

You can use Gemini. Free version of Gemini is based on the Gemini Pro model and is capable of assisting you with coding. While it won't write entire programs for you, the free version of Gemini can be a valuable tool for understanding existing code, generating snippets, and troubleshooting problems.

Here's what you can expect:

  • Code generation: You can provide prompts or descriptions of the functionality you desire, and Gemini Pro can attempt to generate some basic code for you.
  • Code completion: If you're stuck on a specific line of code, Gemini Pro might be able to suggest possible completions based on the context.
  • Debugging assistance: Explain your code's behavior and any errors you're encountering. Gemini Pro can potentially help identify issues or suggest solutions.

In this article we will try to integrate Gemini in VSCode (Visual Studio Code) step by step. We will use "Ask Bard" VSCode extension to integrate Gemini into VSCode. Though there are other ways out there to do the same, but this is by far the easiest method.

Install "Ask Bard" VSCode Extension

First step is to install the VSCode extension called "Ask Bard". Go to "extensions" in VSCode and search for "Ask Bard". The first result should be the right one as can be seen in the screenshot below.

Installing "Ask Bard" VSCode extension

After installing "Ask Bard", You can read the description of the extension as it explains how to get it working. It tells you to get the API Key for the Gemini. So in the next step we will do the same.

First you need to subscribe to Gemini. Navigate to https://gemini.google.com and subscribe for free version. If you already have subscribed, then you should see a screen something like this.

Getting the Gemini API Key

Now that you have subscribed to Free version of Gemini, you can go ahead and generate an API key in order to use it in "Ask Bard" VSCode extension. Navigate to https://aistudio.google.com/app/apikey and you should see a screen like below.

Generate API Key

Click on the button that says "Create API key", and it will open a popup something like this. Click on "Create API key in new project"

Generate API Key in new Project

Now you should see a popup with an input containing the API key and Copy button next to it.

Copy the Gemini API key

Copy the API key by clicking the Copy button. That's the end of this step. Let's move back to the VSCode in order to set the API key in "Ask Bard" settings.

Setting the API key In Bard Settings

Now that we have installed "Ask Bard" and got the Gemini API key, let's set the key into the settings.

Since I am using Mac. It should be "Code > Settings > Settings". Your menu can be different, depending on the operating system you are using.

Settings menu for VSCode in Mac

This will bring up a settings page, where you will have to navigate to "Extensions > Ask Bard > Bard API Key". Set the API key in the input box and it should save it automatically. See the screenshot below.

Setting the API Key in Bard

That's it. We are done with the setup. Let's do a quick test to check if everything is working fine.

Open a file in VS Code and write something that you want Gemini to code for you. In My case I have created a TypeScript file called "test.ts" and wrote a comment to write a function that sums two numbers.

Asking Bard to write code

Select the text and right click to view the context menu as shown in the screenshot.

Select Ask Bard for code

Select "Ask Bard for code" option in order to command "Bard" to generate code based on the highlighted text. On clicking you should see a progress bar at the bottom right part of the screen, saying "Bard is composing...", and in few seconds it should write a function for you like the one in screenshot below.

Bard suggested code

That's it. You now have a fully functional free AI coding tool using Gemini Pro Model.

Liked it ?

Read more