Slide 181
Slide 181 text
config = configparser.ConfigParser()
config.read('../smart_speaker.conf')
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = config.get('dialogflow',
'google_app_credential')
project_id = config.get('dialogflow', 'project_id')
query = sys.argv[1]
def detect_intent_texts(project_id, session_id, texts, language_code):
import dialogflow_v2 as dialogflow
session_client = dialogflow.SessionsClient()
session = session_client.session_path(project_id, session_id)
text_input = dialogflow.types.TextInput(
text=texts, language_code=language_code)
query_input = dialogflow.types.QueryInput(text=text_input)
response = session_client.detect_intent(
session=session, query_input=query_input)
●
detect_intent_texts(project_id, session_id, query, language_code)
Python 程式串接