+91 9873530045
admin@learnwithfrahimcom
Mon - Sat : 09 AM - 09 PM

Lesson 3: PyCharm Project & First Vertex AI Call

Vertex AI Chatbot Course – Lesson 3: PyCharm & First Call


Step A — Project Structure

C:/VertexChatbot/
├─ keys/
│  └─ sa.json                ← your service account JSON
├─ app/
│  ├─ main.py                ← will test the LLM call here
│  └─ requirements.txt
└─ .env                      ← optional: environment variables

Step B — Create Virtual Environment & Install

# In PyCharm terminal (or cmd)
python -m venv .venv
# Activate:
# Windows:
.venv\Scripts\activate
# macOS/Linux:
source .venv/bin/activate

pip install --upgrade pip
pip install google-cloud-aiplatform flask python-dotenv

Create requirements.txt (so deployment is easy):

google-cloud-aiplatform
flask
python-dotenv

Step C — Environment Variables

Create .env at project root and add:

GOOGLE_APPLICATION_CREDENTIALS=C:/VertexChatbot/keys/sa.json
GCP_PROJECT_ID=your-project-id
GCP_LOCATION=us-central1

PyCharm ▸ Run/Debug Configurations ▸ Environment ▸ Include system env + Add these vars if you prefer.

Step D — First Vertex AI Call

app/main.py:

import os
from dotenv import load_dotenv
from google.cloud import aiplatform

load_dotenv()  # load .env

project_id = os.getenv("GCP_PROJECT_ID")
location = os.getenv("GCP_LOCATION", "us-central1")

# Initialize Vertex AI client
aiplatform.init(project=project_id, location=location)

# Use a pre-trained text model (no training needed)
model = aiplatform.TextGenerationModel.from_pretrained("text-bison")  # or "text-bison@001"

prompt = "In one sentence, what is Vertex AI?"
response = model.predict(prompt, max_output_tokens=128)

print("Status: OK")
print("Response:", response.text)

Run in PyCharm (green ▶). Expected:

Status: OK
Response: Vertex AI is Google's unified platform for building, deploying, and managing machine learning models.
If you see a coherent response, your local machine → Vertex AI call works!