봇 빌더, 개발자, 유지관리자를 위한 고급 스크립팅 API입니다.
Python Dialogflow CX 스크립팅 API(DFCX SCRAPI)는 Dialogflow CX용 공식 Google Python 클라이언트를 확장하는 고급 API입니다. SCRAPI를 사용하면 봇 빌더, 개발자 및 유지관리자가 DFCX를 더 쉽고, 더 친숙하고, 더 파이썬적으로 사용할 수 있습니다.
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는 추가 구성 없이 이러한 서비스에서 사용되는 기본 환경 자격 증명을 선택할 수 있습니다.
requirements.txt
파일에 dfcx-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과 유사하게, gcloud CLI를 사용하는 경우 SCRAPI는 로컬 인증 자격 증명을 선택할 수 있습니다.
gcloud init
실행하세요.gcloud auth login
실행gcloud auth list
실행하여 주 계정이 활성화되었는지 확인하세요.그러면 gcloud CLI를 사용하여 기본 GCP 계정이 인증되고 SCRAPI는 여기에서 자격 증명을 가져올 수 있습니다.
SCRAPI에는 여전히 서비스 계정 키를 사용하는 일부 클래스가 있습니다. 특히 Google Sheets로 인증하는 방식으로 인해 DataframeFunctions 클래스가 그렇습니다.
이러한 기능을 사용하려면 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 에이전트(에이전트, 의도, 흐름 등)의 핵심 리소스 유형과 동의어입니다.
도구 폴더에는 다음과 같은 보다 복잡한 봇 관리 작업을 수행할 수 있는 다양한 사용자 정의 도구 키트가 포함되어 있습니다.
Builders 폴더에는 Dialogflow CX에서 기본 proto를 구성하기 위한 간단한 방법이 포함되어 있습니다.
제출하고 싶은 기여나 기능 요청을 환영합니다!
Apache 2.0 라이센스에 따라 배포됩니다. 자세한 내용은 라이센스를 참조하세요.
패트릭 말로우 - [email protected] - @kmaphoenix
밀라드 타브리지 - [email protected] - @MRyderOC
프로젝트 링크: https://github.com/GoogleCloudPlatform/dfcx-scrapi
Dialogflow CX Python 클라이언트 라이브러리
포옹 얼굴 - 페가수스 의역