Google Gemini Course (1/7) – Introduction

Hi and welcome to this new tutorial series on Google Gemini! In this series, we will cover everything you need to know about the Google AI API, from the basics like simple requests to more advanced features like function calling.

We’ll start by taking a look at the basics of what Gemini is and how to build stuff in Google AI Studio. As we go we’ll switch to the API version and use Gemini programmatically, exploring more advanced features and more complex setups. So get ready to dive into the world of Google Gemini!

What is Gemini?

Google Gemini is a powerful LLM (Large Language Model) just like ChatGPT. It is designed to help you generate text, answer questions, and even have conversations with it. Just like ChatGPT, there are multi-model capabilities available, allowing you to not just work with text but also with images, videos, and audio.

There is a range of models available as of June 2024, note that models and exact pricing will change over time:

  • Gemini 1.0 Pro deals with Text only and is one of the earlier models available. It offers a good base option which is very affordable and more than capable enough for simpler everyday style tasks. It is comparable with the GPT 3.5-turbo model for the OpenAI models if you will. Pricing is very cheap at:
        – Input: $0.50 / 1 million tokens
        – Output: $1.50 / 1 million tokens
  • Gemini 1.0 Pro Vision is a version of the above that has been optimized for dealing with visually related tasks and thus deals not only with text but also images and even videos.
  • Gemini 1.5 Pro is the current flagship model of Gemini, dealing with text, images, videos and even audio. It is capable of complex reasoning and has a whopping maximum input context window of 1 million tokens which is absolutely insane. It is quite expensive if you use that many tokens though and it’s very unlikely you will ever even get close to that. Pricing is as follows:
        – Input: $3.50 / 1 million tokens (prompt < 128K tokens)     – Input: $7.00 / 1 million tokens (prompt > 128K tokens)
        – Output: $10.50 / 1 million tokens (prompt < 128K tokens)     – Output: $21.00 / 1 million tokens (prompt > 128K tokens)
  • Gemini 1.5 Flash is exactly 10 times as cheap at the time of writing compared to the Pro version. It is also faster. It’s basically a light version and where the Pro model can handle more complexity and more general tasks, Flash is good for faster and more narrowly defined tasks.
        – Input: $0.35 / 1 million tokens (prompt < 128K tokens)     – Input: $0.70 / 1 million tokens (prompt > 128K tokens)
        – Output: $1.05 / 1 million tokens (prompt < 128K tokens)     – Output: $2.10 / 1 million tokens (prompt > 128K tokens)

Do not worry about your wallet!

At first observation, some prices may seem really expensive but keep in mind that 1 million tokens is a very, very large amount when you are working with text. Working with videos or very huge inputs may be more expensive and we’ll look at that as we go and warn you ahead of time. For general use, you will not incur any large costs really.

Many very simple requests we do on a daily basis barely use 200 tokens or maybe 2000 if it gets longer with some responses and message history. Even if we assume a 2000 token request AND a fairly long 400 token response AND we use the most expensive Pro model here our costs would amount to slightly over $0.01 dollars or one cent! If we use the Flash version it’s only one-tenth of that price!

On top of that, most countries seem to have an option to get a free API without even setting up any billing at all. This means you will most likely be able to follow along with the entire tutorial series without paying anything. More details on this later. Even if you do set up billing though, this course will certainly not break your bank account!

For reference, a 2000 token request as described above would be a prompt that has roughly half the length of the text of this entire written tutorial part 1, and the output message would be the same size as the What is Gemini? chapter right before this one. Most requests we make will be much shorter than that.

As a second reference point, the new OpenAI GPT-4o model is more expensive than even the most expensive Gemini model (comparing only under 128k input sizes, but you should never get anywhere near that size anyway) at the following pricing:

  • Input: $5.00 / 1 million tokens
  • Output: $15.00 / 1 million tokens

If you’re very concerned about the costs, use the free option or use the Flash model throughout the course, but our local development testing really isn’t going to amount to much. As the new Gemini 1.5 Flash model is so affordable, we will be focusing mainly on the Gemini 1.5 Pro and Gemini 1.5 Flash models for the tutorial series without focusing too much on the older models.

Google AI Studio

Before we get started on the programmatic and more advanced features and using the APIs, let’s look at the simplest way of using Gemini. It’s very easy to use, free up to a certain number of requests per day and is actually quite powerful. I use this regularly for personal stuff if I just want to ask a quick question.

Go to the Google AI Studio and you will be greeted with a screen like this:

Login using your Google account, or create one if you don’t have one (it’s free!). Most people nowadays already have a Google account for Gmail so you can just log in straight away.

We’ll be taken to the prompting screen:

Let’s go over the settings on the right-hand side first:

  • Model: Will simply let us choose between 1.0 Pro, 1.5 Pro, and 1.5 Flash.
  • Token Count: Does what it says on the box. Nice for reference. The AI Studio usage is mostly free though so don’t worry about this too much.
  • Temperature: The temperature setting for LLMs controls the randomness of the model’s output. A higher temperature leads to more diverse and unpredictable responses, while a lower temperature makes the output more focused and deterministic.
  • Add stop sequence: A stop sequence is a specific string of text that, when detected, signals the model to stop generating further output. It’s like a command that tells the model “Once you’ve written this, you’re done”. Imagine that I am an LLM and we set the stop sequence to the word "suddenly", so now I am generating this response for you but if the word ⛔suddenly⛔ (appears then the rest of this sentence would never be generated).
  • Safety settings: This is basically the setting for how politically correct the output of the model is. I think the default for the sliders is set to Block some, but I have found it to give a lot of false positives, blocking its own generated output when there really is nothing wrong with it. I will go ahead and set the sliders to Block few before we move on:

Now click on the pencil at the top next to Untitled prompt to give your chat a name. I’ll name mine: Gloomy chat. Then click on the System Instructions right below the title and let’s give our chatbot a personality. I’ll give my chat the following system instructions:

You are Eeyore from Winnie the Pooh. You are known for your constant negativity. You offer information in a pessimistic light, but perhaps with a hint of underlying optimism.

Of course you can also ask questions without inputting any system instructions at all, but it’s nice to put any instructions and examples for the model in here so you don’t have to repeat them for each input message you type. Great! You can collapse the System Instructions with the ^ button. Now we just go to the bottom and Type something:

Well, that is a thoroughly depressing chat! I don’t recommend chatting to this model for too long as it may be bad for your mental health 😅. If you see the first response there is actually already a ⚠️ warning triangle next to it. If we click it we can see that this would have potentially already been blocked by the filter if we hadn’t set the safety settings sliders a bit lower: