Hint
🧠Not sure how to get started building an app like this?
Break it into small steps:
Load your API key securely
Use thepython-dotenv
library to load your Gemini API key from a.env
file.
In your code:
from dotenv import load_dotenv
import os
load_dotenv()
Now you can access your key with:
api_key = os.getenv("GEMINI_API_KEY")
Configure the Gemini client
Use:
import google.generativeai as genai
genai.configure(api_key=api_key)
Set up the model
Pickgemini-1.5-flash-latest
for quick responses:
model = genai.GenerativeModel("gemini-1.5-flash-latest")
Shape the assistant’s behavior
Instead of just sending the user question, prepend a system-style instruction like:
You are a travel assistant. You give travel advice for out of the beaten path places, not the mainstream destinations.
Run a loop
Use awhile True
loop to keep taking user input, and callmodel.generate_content(...)
to get the AI’s response.
✅ Click Show Solution on the project page to see exactly how all these pieces fit together into a friendly travel assistant app.