面向機器人建構者、開發者和維護者的高階腳本 API。
Python Dialogflow CX 腳本 API (DFCX SCRAPI) 是一個進階 API,擴展了 Dialogflow CX 的官方 Google Python 用戶端。對於機器人建構者、開發者和維護者來說,SCRAPI 讓 DFCX 的使用變得更容易、更友善、更 Pythonic。
SCRAPI --> Python Dialogflow CX
as
Keras --> Tensorflow
透過 DFCX SCRAPI,您可以大規模執行許多機器人建置和維護操作,包括但不限於:
身份驗證可能會有所不同,具體取決於您與 SCRAPI 互動的方式和位置。
如果您將 SCRAPI 與 Google Colab 筆記本一起使用,您可以將以下內容新增至筆記本頂部以便於驗證:
project_id = '<YOUR_GCP_PROJECT_ID>'
# this will launch an interactive prompt that allows you to auth with GCP in a browser
!g cloud auth application - default login - - no - launch - browser
# this will set your active project to the `project_id` above
!g cloud auth application - default set - quota - project $ project_id
執行上述命令後,Colab 將從環境中取得您的憑證並將其直接傳遞給 SCRAPI。無需使用服務帳戶金鑰!然後您可以像這樣簡單地使用 SCRAPI:
from dfcx_scrapi . core . intents import Intents
agent_id = '<YOUR_AGENT_ID>'
i = Intents () # <-- Creds will be automatically picked up from the environment
intents_map = i . get_intents_map ( agent_id )
如果您將 SCRAPI 與 Cloud Functions 或 Cloud Run 結合使用,SCRAPI 可以取得這些服務使用的預設環境憑證,而無需任何其他配置!
dfcx-scrapi
加入您的requirements.txt
檔案中一旦完成上述設置,您的函數程式碼就可以像這樣輕鬆使用:
from dfcx_scrapi . core . intents import Intents
agent_id = '<YOUR_AGENT_ID>'
i = Intents () # <-- Creds will be automatically picked up from the environment
intents_map = i . get_intents_map ( agent_id )
與 Cloud Functions / Cloud Run 類似,如果您使用 gcloud CLI,則 SCRAPI 可以取得您的本機驗證憑證。
gcloud init
。gcloud auth login
gcloud auth list
以確保您的主要帳戶處於活動狀態。這將使用 gcloud CLI 對您的主要 GCP 帳戶進行身份驗證,並且 SCRAPI 可以從此處取得憑證。
SCRAPI 中的一些類別仍然依賴服務帳戶金鑰,特別是 DataframeFunctions 類,因為它如何使用 Google Sheets 進行身份驗證。
為了使用這些功能,您需要一個對您的 GCP 項目具有適當存取權限的服務帳號。
有關更多資訊並查看服務帳戶的官方文檔,請前往建立和管理 GCP 服務帳戶。
取得具有適當權限的服務帳戶金鑰後,您可以按如下方式使用它:
from dfcx_scrapi . core . intents import Intents
from dfcx_scrapi . tools . dataframe_functions import DataframeFunctions
agent_id = '<YOUR_AGENT_ID>'
creds_path = '<PATH_TO_YOUR_SERVICE_ACCOUNT_JSON_FILE>'
i = Intents ( creds_path = creds_path )
dffx = DataframeFunctions ( creds_path = creds_path )
df = i . bulk_intent_to_df ( agent_id )
dffx . dataframe_to_sheets ( 'GOOGLE_SHEET_NAME' , 'TAB_NAME' , df )
設定 Google Cloud Platform 憑證並安裝相依性。
gcloud auth login
gcloud auth application-default login
gcloud config set project < project name >
python3 -m venv venv
source ./venv/bin/activate
pip install -r requirements.txt
要執行一段簡單的程式碼,您可以執行以下操作:
dfcx_scrapi.core
導入類 from dfcx_scrapi . core . intents import Intents
creds_path = '<PATH_TO_YOUR_SERVICE_ACCOUNT_JSON_FILE>'
agent_path = '<FULL_DFCX_AGENT_ID_PATH>'
# DFCX Agent ID paths are in this format:
# 'projects/<project_id>/locations/<location_id>/agents/<agent_id>'
# Instantiate your class object and pass in your credentials
i = Intents ( creds_path , agent_id = agent_path )
# Retrieve all Intents and Training Phrases from an Agent and push to a Pandas DataFrame
df = i . bulk_intent_to_df ()
以下是 SCRAPI 庫的結構以及該結構背後的動機的簡要概述。
Core 資料夾與 DFCX 代理程式中的核心資源類型(代理、意圖、流等)同義。
Tools 資料夾包含各種自訂工具包,可讓您執行更複雜的機器人管理任務,例如
Builders 資料夾包含用於在 Dialogflow CX 中建立底層原型的簡單方法
我們歡迎您提交任何貢獻或功能請求!
根據 Apache 2.0 許可證分發。請參閱許可證以了解更多資訊。
派崔克馬洛 - [email protected] - @kmaphoenix
米拉德·塔布里茲 - [email protected] - @MRyderOC
專案連結:https://github.com/GoogleCloudPlatform/dfcx-scrapi
Dialogflow CX Python 用戶端程式庫
擁抱臉 - 飛馬座釋義