Skip to content

Files

Latest commit

 

History

History
 
 

cloud-client

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 the repository and change directory to the sample directory.

    $ 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 2.7 and 3.4+.

    $ 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_ID
                                  texts [texts ...]

Dialogflow API Detect 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_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_ID
                        The id of the Knowledge Base to query against, e.g., OTE5NjYzMTkxNDA2NzI2MzQ4OA

Detect Intent with Model Selection

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

To run this sample:

$ python detect_intent_with_model_selection.py

usage: detect_intent_with_model_selection.py [-h] --project-id PROJECT_ID
                                             [--session-id SESSION_ID]
                                             [--language-code LANGUAGE_CODE]
                                             --audio-file-path AUDIO_FILE_PATH

Dialogflow API Beta Detect Intent Python sample with model selection.

Examples:
  python detect_intent_with_model_selection.py -h
  python detect_intent_with_model_selection.py --project-id PROJECT_ID   --session-id SESSION_ID --audio-file-path resources/book_a_room.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 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.py -h
  python detect_intent_with_texttospeech_response.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.

Entity Type Management

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

To run this sample:

$ python entity_type_management.py

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

DialogFlow API EntityType Python sample showing how to manage entity types.

Examples:
  python entity_type_management.py -h
  python entity_type_management.py --project-id PROJECT_ID list
  python entity_type_management.py --project-id PROJECT_ID create employee
  python entity_type_management.py --project-id PROJECT_ID delete   e57238e2-e692-44ea-9216-6be1b2332e2a

positional arguments:
  {list,create,delete}
    list
    create              Create an entity type with the given display name.
    delete              Delete entity type with the given entity type name.

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

Entity Management

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

To run this sample:

$ python entity_management.py

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

DialogFlow API Entity Python sample showing how to manage entities.

Examples:
  python entity_management.py -h
  python entity_management.py --project-id PROJECT_ID   list --entity-type-id e57238e2-e692-44ea-9216-6be1b2332e2a
  python entity_management.py --project-id PROJECT_ID   create new_room --synonyms basement cellar   --entity-type-id e57238e2-e692-44ea-9216-6be1b2332e2a
  python entity_management.py --project-id PROJECT_ID   delete new_room   --entity-type-id e57238e2-e692-44ea-9216-6be1b2332e2a

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

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

Session Entity Type Management

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

To run this sample:

$ python session_entity_type_management.py

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

DialogFlow API SessionEntityType Python sample showing how to manage
session entity types.

Examples:
  python session_entity_type_management.py -h
  python session_entity_type_management.py --project-id PROJECT_ID list   --session-id SESSION_ID
  python session_entity_type_management.py --project-id PROJECT_ID create   --session-id SESSION_ID   --entity-type-display-name room --entity-values C D E F
  python session_entity_type_management.py --project-id PROJECT_ID delete   --session-id SESSION_ID   --entity-type-display-name room

positional arguments:
  {list,create,delete}
    list
    create              Create a session entity type with the given display
                        name.
    delete              Delete session entity type with the given entity type
                        display name.

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. Please note that it will be initially disabled until you enable it.
    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, e.g., OTE5NjYzMTkxNDA2NzI2MzQ4OA
  --mime_type           The mime_type of the Document. e.g. text/csv, text/html,
                        text/plain, text/pdf etc.

  --knowledge_type      The Knowledge type of the Document. e.g. FAQ, EXTRACTIVE_QA.

  --content_uri         Uri of the document, e.g. gs://path/mydoc.csv,
                        http://mypage.com/faq.html.

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.