API การเขียนสคริปต์ระดับสูงสำหรับผู้สร้างบอท นักพัฒนา และผู้ดูแล
Python Dialogflow CX Scripting API (DFCX SCRAPI) เป็น API ระดับสูงที่ขยายไคลเอ็นต์ Google Python อย่างเป็นทางการสำหรับ Dialogflow CX 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 Run SCRAPI สามารถรับเครดิตการตรวจสอบสิทธิ์ในเครื่องของคุณ ได้ หากคุณใช้ gcloud CLI
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 และแรงจูงใจเบื้องหลังโครงสร้างนั้น
โฟลเดอร์หลักมีความหมายเหมือนกันกับประเภททรัพยากรหลักในตัวแทน DFCX (ตัวแทน ความตั้งใจ โฟลว์ ฯลฯ)
โฟลเดอร์เครื่องมือประกอบด้วยชุดเครื่องมือแบบกำหนดเองต่างๆ ที่ช่วยให้คุณสามารถทำงานการจัดการบอทที่ซับซ้อนมากขึ้นได้ เช่น
โฟลเดอร์ Builders มีวิธีง่ายๆ สำหรับการสร้างโปรโตสที่ซ่อนอยู่ใน Dialogflow CX
เรายินดีรับการมีส่วนร่วมหรือคำขอคุณสมบัติที่คุณต้องการส่ง!
เผยแพร่ภายใต้ลิขสิทธิ์ Apache 2.0 ดูใบอนุญาตสำหรับข้อมูลเพิ่มเติม
แพทริค มาร์โลว์ - [email protected] - @kmaphoenix
มิลาด ทาบริซี - [email protected] - @MRyderOC
ลิงค์โครงการ: https://github.com/GoogleCloudPlatform/dfcx-scrapi
ไลบรารีไคลเอ็นต์ Dialogflow CX Python
กอดใบหน้า - ถอดความเพกาซัส