昨天我們已經學會如何在 Azure AI Foundry 中透過程式呼叫模型 API。今天換到 Google Cloud Vertex AI,體驗如何透過 API 與 Google 的 GenAI 模型互動。
和 Azure 一樣,Playground 方便用來測試,但實務上:
我們需要把 AI 整合到系統或服務
自動化內容生成或數據處理
串接資料庫與應用(BigQuery、Dataflow、App Engine)
👉 API 呼叫就是實戰專案的必備工具。
登入 Google Cloud Console
確認已啟用 Vertex AI API
建立或使用現有的 服務帳號 (Service Account)
下載 金鑰檔 (JSON key file),用於程式呼叫驗證
以下用 Python 呼叫 Gemini Pro 模型的範例:
from google.cloud import aiplatform
# 初始化 Vertex AI
aiplatform.init(project="YOUR_PROJECT_ID", location="us-central1")
# 指定模型
model = aiplatform.ChatModel.from_pretrained("chat-bison@001")
# 建立 Chat Session
chat = model.start_chat()
# 呼叫模型
response = chat.send_message("請幫我寫一封會議邀請信")
print(response.text)
👉 記得先安裝套件:
pip install google-cloud-aiplatform
使用者輸入需求
程式透過 Service Account 驗證
呼叫 Vertex AI 模型(Gemini / PaLM / Imagen)
API 返回生成結果
系統整合結果(例如顯示在 App 或報表)
Vertex AI 的 API 適合搭配 BigQuery,能直接對資料進行自然語言查詢
也能和 Google Workspace API(Docs、Sheets、Gmail) 整合,形成智慧辦公流程
相比 Azure,Google 給了更多 模型選擇與調整空間
小結
今天我們完成了 第一次程式呼叫 GCP Vertex AI,正式打通了 Google 平台的 GenAI 應用。
到這裡,無論是 Azure 還是 GCP,我們都已經能從 Playground 操作邁向 實際應用開發 🚀
接下來(Day 8),我們會做一個 Azure vs GCP API 使用體驗比較,幫助大家更清楚判斷在專案中應該選哪一個平台。