Python 適用的 Agent Platform SDK 可協助您自動擷取資料、訓練模型,以及在 Gemini Enterprise Agent Platform 上取得預測結果。Agent Platform SDK 會使用 Python 程式碼存取 Agent Platform API,讓您透過程式執行大部分可在 Google Cloud 控制台中執行的操作。
如要瞭解如何安裝或更新 Agent Platform SDK for Python,請參閱「安裝 Agent Platform SDK for Python」。詳情請參閱 Agent Platform SDK for Python API 參考文件。
使用 Agent Platform SDK 的原因
如果您是經驗豐富的機器學習 (ML) 和人工智慧 (AI) 工程師或資料科學家,且想以程式輔助方式自動執行工作流程,建議使用 Python 適用的 Agent Platform SDK。Agent Platform SDK for Python 與 Gemini Enterprise Agent Platform Python 用戶端程式庫類似,但 Agent Platform SDK 的層級較高,精細程度較低。詳情請參閱「瞭解 SDK 和用戶端程式庫的差異」。
使用 Agent Platform SDK for Python 編寫程式碼
如要使用 Agent Platform SDK for Python,請按照下列步驟操作:
在虛擬環境中執行下列指令,安裝
google-cloud-aiplatform套件,其中包含 Agent Platform SDK for Python 和 Gemini Enterprise Agent Platform Python 用戶端程式庫:pip install --upgrade google-cloud-aiplatform使用下列程式碼匯入
google.cloud.aiplatform命名空間:from google.cloud import aiplatform-
如果您使用本機殼層,請為使用者帳戶建立本機驗證憑證:
gcloud auth application-default login
如果您使用 Cloud Shell,則不需要執行這項操作。
如果系統傳回驗證錯誤,且您使用外部識別資訊提供者 (IdP),請確認您已 使用聯合身分登入 gcloud CLI。
瞭解 Agent Platform SDK for Python
請參閱下列說明文件:
Agent Platform SDK 類別總覽:介紹 Agent Platform SDK 的主要類別和功能。
Gemini Enterprise Agent Platform 的 Python 參考文件:包含
google-cloud-aiplatform套件中所有命名空間、類別、方法和屬性的參考說明文件,包括 Agent Platform SDK、Agent Platform SDK 預先發布版和 Gemini Enterprise Agent Platform 用戶端程式庫。
試用程式碼範例和教學課程
筆記本教學課程會說明如何在較大的工作流程中使用 Agent Platform SDK for Python。詳情請參閱 Gemini Enterprise Agent Platform 筆記本教學課程。
Agent Platform SDK for Python GitHub 存放區中的程式碼範例,會說明如何完成個別工作。詳情請參閱 Agent Platform SDK for Python GitHub 存放區。
瞭解 Agent Platform SDK 和用戶端程式庫的差異
安裝 Agent Platform SDK for Python 時,系統也會安裝 Gemini Enterprise Agent Platform Python 用戶端程式庫。Agent Platform SDK 和 Gemini Enterprise Agent Platform Python 用戶端程式庫提供類似功能,但精細程度不同。Agent Platform SDK 的抽象層級高於用戶端程式庫,適用於大多數常見的資料科學工作流程。如需較低層級的功能,請使用 Gemini Enterprise Agent Platform Python 用戶端程式庫。
Agent Platform SDK 適用於 Python,而 Gemini Enterprise Agent Platform 用戶端程式庫則適用於 Python、Java 和 Node.js。如要瞭解如何安裝 Java 或 Node.js 用戶端程式庫,請參閱「安裝 Gemini Enterprise Agent Platform 用戶端程式庫」。如果沒有您慣用程式設計語言的用戶端程式庫,可以使用 Gemini Enterprise Agent Platform REST API。詳情請參閱 Gemini Enterprise Agent Platform REST 參考資料。
同時使用 Gemini Enterprise Agent Platform Python 用戶端程式庫和 SDK
如果您使用 Agent Platform SDK for Python,但發現需要更大的彈性或控制權,或是需要 Agent Platform SDK 未提供的方法,可以在相同的工作流程中使用 Gemini Enterprise Agent Platform Python 用戶端程式庫。Gemini Enterprise Agent Platform Python 用戶端程式庫使用不同的命名空間來存取 Agent Platform API。只要在 Python 指令碼中為每個命名空間新增 import 行,即可在同一個 Python 指令碼中使用用戶端程式庫和 Agent Platform SDK for Python 命名空間。
匯入 Gemini Enterprise Agent Platform Python 用戶端程式庫命名空間
Gemini Enterprise Agent Platform Python 用戶端程式庫的命名空間為 google.cloud.aiplatform.gapic。這個命名空間會對應至
google.cloud.aiplatform_v1 命名空間。這兩個命名空間可以互換使用。如要匯入 Python 用戶端程式庫,請在 Python 指令碼中加入下列其中一項:
from google.cloud import aiplatform_v1
from google.cloud.aiplatform import gapic
後續步驟
瞭解如何選擇訓練方法。