ボットビルダー、開発者、保守者向けの高レベルのスクリプト API。
Python Dialogflow CX Scripting API (DFCX SCRAPI) は、Dialogflow CX の公式 Google Python クライアントを拡張する高レベル API です。 SCRAPI を使用すると、ボット ビルダー、開発者、メンテナーにとって DFCX の使用がより簡単で、よりフレンドリーで、よりPython的になります。
SCRAPI --> Python Dialogflow CX
as
Keras --> Tensorflow
DFCX SCRAPI を使用すると、次のようなボットの構築およびメンテナンス アクションを大規模に実行できますが、これらに限定されません。
認証は、SCRAPI と対話する方法と場所によって異なる場合があります。
Google Colab ノートブックで SCRAPI を使用している場合は、認証を簡単にするためにノートブックの先頭に次の内容を追加できます。
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 )
Cloud Functions または Cloud Run で SCRAPI を使用している場合、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
実行して、プリンシパル アカウントがアクティブであることを確認します。これにより、プリンシパル GCP アカウントが gcloud CLI で認証され、SCRAPI はここから認証情報を取得できます。
SCRAPI には依然としてサービス アカウント キーに依存するクラスがいくつかあります。特に DataframeFunctions クラスは、Google スプレッドシートでの認証方法が原因です。
これらの機能を使用するには、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 クライアント ライブラリ
ハグフェイス - ペガサスの言い換え