My first API call to Google Gemini 2.0
- Ken Munson
- Feb 9
- 4 min read
Updated: Apr 15
With the seemingly unstoppable momentum that AI has here in early 2025, I decided to expand and go beyond relying on just OpenAI's o1 model for all my questions (physics, math, et al.). Over time, I hope to become proficient with Google Cloud and all the tools they offer like Vertex AI. To jump start that and make it interesting, I refreshed my GCP account (fixed the billing), and found a tutorial on GCP about attaching to Googles API's for the Gemini 2.0 LLM. So, that is what I did. Here is the short version:
In a VSCode terminal (not mandatory you be in VSCode - just simpler to me), you have to run two commands at the command prompt to get set up:
pip install --upgrade google-genai
gcloud auth application-default login
Rarely does this go smoothly but, I have to say, it went pretty well. There always seems to be an environment, or PATH, or variable, or version, or missing package, or authentication problem but none of that really happened here. Then it was simple just type in a prompt (I always use the same one for any new model I use as a kind of test), click save, and copy in the code from the from the "<> Get code" selection on the page titled Freeform Prompt under Vertex AI Studio top level menu: See screen shots just below:


To save time, you might be able to copy it in right from here:
from google import genai
from google.genai import types
import base64
def generate():
client = genai.Client(
vertexai=True,
project="xxxxxxxxxx-xxxxxxxx",
location="us-central1",
)
text1 = types.Part.from_text(text="""In physics, in as simple language as possible (for a complex subject like this), please explain what a Hilbert Space is?""")
model = "gemini-2.0-flash-001"
contents = [
types.Content(
role="user",
parts=[
text1
]
)
]
generate_content_config = types.GenerateContentConfig(
temperature = 1,
top_p = 0.95,
max_output_tokens = 8192,
response_modalities = ["TEXT"],
safety_settings = [types.SafetySetting(
category="HARM_CATEGORY_HATE_SPEECH",
threshold="OFF"
),types.SafetySetting(
category="HARM_CATEGORY_DANGEROUS_CONTENT",
threshold="OFF"
),types.SafetySetting(
category="HARM_CATEGORY_SEXUALLY_EXPLICIT",
threshold="OFF"
),types.SafetySetting(
category="HARM_CATEGORY_HARASSMENT",
threshold="OFF"
)],
)
for chunk in client.models.generate_content_stream(
model = model,
contents = contents,
config = generate_content_config,
):
print(chunk.text, end="")
generate()
Here is the output that it gave to this question, which I was really impressed with. I always ask this question because it really tests a model's ability to put something complex and abstract into simple terms Gemini 2.0 gets an "A" for this assignment. O and the prompt (the question" is on one line in the Python file above it is this line (shows as two in code above but actually one single line of code):
text1 = types.Part.from_text(text="""In physics, in as simple language as possible (for a complex subject like this), please explain what a Hilbert Space is?""")
[Response from Gemini 2.0]:
Okay, imagine you have a regular space, like the floor in your room. You can describe any point on the floor using just two numbers (like coordinates on a map: how far to the right and how far forward). This is a 2-dimensional space.
A Hilbert Space is a much, much more general and abstract version of that, but still has some of the same basic ideas. Think of it as a "super-floor" that can have an infinite number of dimensions!
Here's the breakdown, stripped down to the basics:
*Vectors:** Instead of just points on a floor, a Hilbert space contains things called "vectors." These could represent many different things, depending on what you're studying. In quantum mechanics, these vectors often represent the state of a particle (like its energy, momentum, or position). Think of them as arrows pointing in different directions in this abstract space.
*Adding and Scaling:** You can add vectors together. Imagine combining the "arrows" end-to-end. You can also scale vectors by multiplying them by a number (make the arrow longer or shorter, or even flip it around if the number is negative).
*Inner Product (Dot Product):** This is a way to compare two vectors. Think of it like measuring how much two arrows point in the same direction. It gives you a single number. Importantly, this is what allows us to define the length of a vector and the angle between vectors.
*Completeness:** This is the trickiest part to explain simply. Imagine you have a sequence of points on your floor that get closer and closer to a specific location. In a complete space, that location must also be a point on your floor. No gaps! In a Hilbert space, this means that if you have a sequence of vectors that are getting closer and closer together, the "limit" of that sequence is also a vector within the Hilbert space. This is crucial for doing calculus and solving equations.
Why is it important for Physics (especially Quantum Mechanics)?
*Describing Quantum States:** The state of a quantum particle (like an electron) is described by a vector in a Hilbert space. Everything you can know about the particle is somehow encoded in that vector.
*Superposition:** One of the strangest quantum phenomena is superposition, where a particle can be in multiple states at the same time. This is represented by adding vectors together in the Hilbert space.
*Calculations and Predictions:** Hilbert spaces provide the mathematical framework for making calculations and predictions about quantum systems. The "inner product" lets us calculate probabilities of measuring different outcomes.
In summary:
A Hilbert Space is a mathematical space where you can:
1. Represent things with vectors.
2. Add and scale vectors.
3. Measure how similar vectors are using an "inner product."
4. Be sure that there are no "gaps" (completeness).
It's an abstract tool, but it's absolutely fundamental for describing the behavior of the universe at the quantum level.
I'm pretty pleased with how this went. First, the setup was without any major snafu. Second, the response to the prompt was amazing. In the future (the road to heck paved with good intentions) I'd like to get into these topics:

Comments