Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

Latest commit

 

History

History
221 lines (120 loc) · 6.81 KB

README.rst

File metadata and controls

221 lines (120 loc) · 6.81 KB

Dialogflow CX API Python Samples

image

This directory contains samples for Dialogflow CX API. The Dialogflow CX API enables you to create conversational experiences across devices and platforms.

Setup

Authentication

This sample requires you to have authentication setup. Refer to the Authentication Getting Started Guide for instructions on setting up credentials for applications.

Install Dependencies

  1. Clone python-docs-samples and change directory to the sample directory you want to use.

    $ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
  2. Install pip and virtualenv if you do not already have them. You may want to refer to the Python Development Environment Setup Guide for Google Cloud Platform for instructions.

  3. Create a virtualenv. Samples are compatible with Python 3.6+.

    $ virtualenv env
    $ source env/bin/activate
  4. Install the dependencies needed to run the samples.

    $ pip install -r requirements.txt

Samples

Detect Intent Text

image

To run this sample:

$ python detect_intent_texts.py


usage: detect_intent_texts.py [-h] --agent AGENT [--session-id SESSION_ID]
                              [--language-code LANGUAGE_CODE]
                              texts [texts ...]

DialogFlow API Detect Intent Python sample with text inputs.

Examples:
  python detect_intent_texts.py -h
  python detect_intent_texts.py --agent AGENT   --session-id SESSION_ID   "hello" "book a meeting room" "Mountain View"
  python detect_intent_texts.py --agent AGENT   --session-id SESSION_ID   "tomorrow" "10 AM" "2 hours" "10 people" "A" "yes"

positional arguments:
  texts                 Text inputs.

optional arguments:
  -h, --help            show this help message and exit
  --agent AGENT         Agent resource name. Required.
  --session-id SESSION_ID
                        Identifier of the DetectIntent session. Defaults to a
                        random UUID.
  --language-code LANGUAGE_CODE
                        Language code of the query. Defaults to "en-US".

Detect Intent Audio

image

To run this sample:

$ python detect_intent_audio.py


usage: detect_intent_audio.py [-h] --agent AGENT [--session-id SESSION_ID]
                              [--language-code LANGUAGE_CODE]
                              --audio-file-path AUDIO_FILE_PATH

DialogFlow API Detect Intent Python sample with audio file.

Examples:
  python detect_intent_audio.py -h
  python detect_intent_audio.py --agent AGENT   --session-id SESSION_ID --audio-file-path resources/hello.wav

optional arguments:
  -h, --help            show this help message and exit
  --agent AGENT         Agent resource name. Required.
  --session-id SESSION_ID
                        Identifier of the DetectIntent session. Defaults to a
                        random UUID.
  --language-code LANGUAGE_CODE
                        Language code of the query. Defaults to "en-US".
  --audio-file-path AUDIO_FILE_PATH
                        Path to the audio file.

Detect Intent Stream

image

To run this sample:

$ python detect_intent_stream.py


usage: detect_intent_stream.py [-h] --agent AGENT [--session-id SESSION_ID]
                               [--language-code LANGUAGE_CODE]
                               --audio-file-path AUDIO_FILE_PATH

DialogFlow API Detect Intent Python sample with audio files processed as an audio stream.

Examples:
  python detect_intent_stream.py -h
  python detect_intent_stream.py --agent AGENT   --session-id SESSION_ID --audio-file-path resources/hello.wav

optional arguments:
  -h, --help            show this help message and exit
  --agent AGENT         Agent resource name. Required.
  --session-id SESSION_ID
                        Identifier of the DetectIntent session. Defaults to a
                        random UUID.
  --language-code LANGUAGE_CODE
                        Language code of the query. Defaults to "en-US".
  --audio-file-path AUDIO_FILE_PATH
                        Path to the audio file.

The client library

This sample uses the Google Cloud Client Library for Python. You can read the documentation for more details on API usage and use GitHub to browse the source and report issues.