Skip to content

Latest commit

 

History

History
 
 

dialogflow

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Dialogflow Enterprise Edition API Python Samples

https://gstatic.com/cloudssh/images/open-btn.png

This directory contains samples for Dialogflow Enterprise Edition API. The Dialogflow Enterprise Edition 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

https://gstatic.com/cloudssh/images/open-btn.png

To run this sample:

$ python detect_intent_texts.py

usage: detect_intent_texts.py [-h] --project-id PROJECT_ID
                              [--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 --project-id PROJECT_ID   --session-id SESSION_ID   "hello" "book a meeting room" "Mountain View"
  python detect_intent_texts.py --project-id PROJECT_ID   --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
  --project-id PROJECT_ID
                        Project/agent id. 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

https://gstatic.com/cloudssh/images/open-btn.png

To run this sample:

$ python detect_intent_audio.py

usage: detect_intent_audio.py [-h] --project-id PROJECT_ID
                              [--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 --project-id PROJECT_ID   --session-id SESSION_ID --audio-file-path resources/book_a_room.wav
  python detect_intent_audio.py --project-id PROJECT_ID   --session-id SESSION_ID --audio-file-path resources/mountain_view.wav
  python detect_intent_audio.py --project-id PROJECT_ID   --session-id SESSION_ID --audio-file-path resources/today.wav

optional arguments:
  -h, --help            show this help message and exit
  --project-id PROJECT_ID
                        Project/agent id. 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

https://gstatic.com/cloudssh/images/open-btn.png

To run this sample:

$ python detect_intent_stream.py

usage: detect_intent_stream.py [-h] --project-id PROJECT_ID
                               [--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 --project-id PROJECT_ID   --session-id SESSION_ID --audio-file-path resources/book_a_room.wav
  python detect_intent_stream.py --project-id PROJECT_ID   --session-id SESSION_ID --audio-file-path resources/mountain_view.wav

optional arguments:
  -h, --help            show this help message and exit
  --project-id PROJECT_ID
                        Project/agent id. 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 Knowledge Base

https://gstatic.com/cloudssh/images/open-btn.png

To run this sample:

$ python detect_intent_knowledge.py

usage: detect_intent_knowledge.py [-h] --project-id PROJECT_ID
                                  [--session-id SESSION_ID]
                                  [--language-code LANGUAGE_CODE]
                                  --knowledge-base-id KNOWLEDGE_BASE_ID
                                  texts [texts ...]

Dialogflow API Detect Knowledge Base Intent Python sample with text inputs.

Examples:
  python detect_intent_knowledge.py -h
  python detect_intent_knowledge.py --project-id PROJECT_ID   --session-id SESSION_ID --knowledge-base-id KNOWLEDGE_BASE_ID   "hello" "how do I reset my password?"

positional arguments:
  texts                 Text inputs.

optional arguments:
  -h, --help            show this help message and exit
  --project-id PROJECT_ID
                        Project/agent id. Required.
  --session-id SESSION_ID
                        ID of the DetectIntent session. Defaults to a random
                        UUID.
  --language-code LANGUAGE_CODE
                        Language code of the query. Defaults to "en-US".
  --knowledge-base-id KNOWLEDGE_BASE_ID
                        The id of the Knowledge Base to query against

Detect Intent with Sentiment Analysis

https://gstatic.com/cloudssh/images/open-btn.png

To run this sample:

$ python detect_intent_with_sentiment_analysis.py

usage: detect_intent_with_sentiment_analysis.py [-h] --project-id PROJECT_ID
                                                [--session-id SESSION_ID]
                                                [--language-code LANGUAGE_CODE]
                                                texts [texts ...]

Dialogflow API Beta Detect Intent Python sample with sentiment analysis.

Examples:
  python detect_intent_with_sentiment_analysis.py -h
  python detect_intent_with_sentiment_analysis.py --project-id PROJECT_ID   --session-id SESSION_ID   "hello" "book a meeting room" "Mountain View"

positional arguments:
  texts                 Text inputs.

optional arguments:
  -h, --help            show this help message and exit
  --project-id PROJECT_ID
                        Project/agent id. 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 with Text to Speech Response

https://gstatic.com/cloudssh/images/open-btn.png

To run this sample:

$ python detect_intent_with_texttospeech_response.py

usage: detect_intent_with_texttospeech_response.py [-h] --project-id
                                                   PROJECT_ID
                                                   [--session-id SESSION_ID]
                                                   [--language-code LANGUAGE_CODE]
                                                   texts [texts ...]

Dialogflow API Beta Detect Intent Python sample with an audio response.

Examples:
  python detect_intent_with_texttospeech_response_test.py -h
  python detect_intent_with_texttospeech_response_test.py   --project-id PROJECT_ID --session-id SESSION_ID "hello"

positional arguments:
  texts                 Text inputs.

optional arguments:
  -h, --help            show this help message and exit
  --project-id PROJECT_ID
                        Project/agent id. 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".

Intent Management

https://gstatic.com/cloudssh/images/open-btn.png

To run this sample:

$ python intent_management.py

usage: intent_management.py [-h] --project-id PROJECT_ID
                            {list,create,delete} ...

DialogFlow API Intent Python sample showing how to manage intents.

Examples:
  python intent_management.py -h
  python intent_management.py --project-id PROJECT_ID list
  python intent_management.py --project-id PROJECT_ID create   "room.cancellation - yes"   --training-phrases-parts "cancel" "cancellation"   --message-texts "Are you sure you want to cancel?" "Cancelled."
  python intent_management.py --project-id PROJECT_ID delete   74892d81-7901-496a-bb0a-c769eda5180e

positional arguments:
  {list,create,delete}
    list
    create              Create an intent of the given intent type.
    delete              Delete intent with the given intent type and intent
                        value.

optional arguments:
  -h, --help            show this help message and exit
  --project-id PROJECT_ID
                        Project/agent id. Required.

Knowledge Base Management

https://gstatic.com/cloudssh/images/open-btn.png

To run this sample:

$ python knowledge_base_management.py

usage: knowledge_base_management.py [-h] --project-id PROJECT_ID
                                    {list,create,get,delete} ...

Dialogflow API Python sample showing how to manage Knowledge bases.

Examples:
  python knowledge_base_management.py -h
  python knowledge_base_management.py --project-id PROJECT_ID   list
  python knowledge_base_management.py --project-id PROJECT_ID   create --display-name DISPLAY_NAME
  python knowledge_base_management.py --project-id PROJECT_ID   get --knowledge-base-id knowledge_base_id
  python knowledge_base_management.py --project-id PROJECT_ID   delete --knowledge-base-id knowledge_base_id

positional arguments:
  {list,create,get,delete}
    list                List all Knowledge bases that belong to the project.
    create              Create a new Knowledge base.
    get                 Get a Knowledge base by its id.
    delete              Delete a Knowledge base by its id.

optional arguments:
  -h, --help            show this help message and exit
  --project-id PROJECT_ID
                        Project/agent id.

Document Management

https://gstatic.com/cloudssh/images/open-btn.png

To run this sample:

$ python document_management.py

usage: document_management.py [-h] --project-id PROJECT_ID --knowledge-base-id
                              KNOWLEDGE_BASE_ID
                              {list,create,get,delete} ...

Dialogflow API Python sample showing how to manage Knowledge Documents.

Examples:
  python document_management.py -h
  python document_management.py --project-id PROJECT_ID   --knowledge-base-id knowledge_base_id   list
  python document_management.py --project-id PROJECT_ID   --knowledge-base-id knowledge_base_id   create --display-name DISPLAY_NAME --mime-type MIME_TYPE   --knowledge-type KNOWLEDGE_TYPE --content-uri CONTENT_URI
  python document_management.py --project-id PROJECT_ID   --knowledge-base-id knowledge_base_id   get --document-id DOCUMENT_ID
  python document_management.py --project-id PROJECT_ID   --knowledge-base-id knowledge_base_id   delete --document-id DOCUMENT_ID

positional arguments:
  {list,create,get,delete}
    list                List all Documents that belong to a certain Knowledge
                        base.
    create              Create a Document for a certain Knowledge base.
    get                 Get a Document by its id and the Knowledge base id.
    delete              Delete a Document by its id and the Knowledge baseid.

optional arguments:
  -h, --help            show this help message and exit
  --project-id PROJECT_ID
                        Project id. Required.
  --knowledge-base-id KNOWLEDGE_BASE_ID
                        The id of the Knowledge Base that the Document belongs
                        to

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.