Agent Platform SDK for Python 簡介

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) 工程師,或想透過程式將工作流程自動化的資料科學家,建議使用 Agent Platform SDK for Python。Agent Platform SDK for Python 與 Gemini Enterprise Agent Platform Python 用戶端程式庫類似,但 Agent Platform SDK 的層級較高,精細度較低。詳情請參閱「瞭解 SDK 和用戶端程式庫的差異」。

使用 Agent Platform SDK for Python 編寫程式碼

如要使用 Agent Platform SDK for Python,請按照下列步驟操作:

  1. 在虛擬環境中執行下列指令,安裝 google-cloud-aiplatform 套件,其中包含 Agent Platform SDK for Python 和 Gemini Enterprise Agent Platform Python 用戶端程式庫:

    pip install --upgrade google-cloud-aiplatform
    
  2. 請使用下列程式碼匯入 google.cloud.aiplatform 命名空間:

    from google.cloud import aiplatform
    
  3. 如果您使用的是本機殼層,請為使用者帳戶建立本機驗證憑證:

    gcloud auth application-default login

    如果您使用的是 Cloud Shell,則不必執行這項操作。

    如果系統傳回驗證錯誤,且您使用的是外部識別資訊提供者 (IdP),請確認您已使用聯合身分登入 gcloud CLI。

瞭解 Agent Platform SDK for Python

請參閱下列說明文件:

試用程式碼範例和教學課程

Notebook 教學課程說明如何將 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 指令碼中為用戶端程式庫和 Agent Platform SDK for Python 命名空間分別新增 import 行,即可在同一個 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

後續步驟