Skip to content

Commit ac8deb6

Browse files
b-loved-dreamerparthea
authored andcommitted
docs(samples): adds training phrases sample (#404)
* docs(samples): adds training phrases sample * docs(samples): fixed lint * docs(samples): ignored auto-foratting Co-authored-by: Anthonios Partheniou <[email protected]>
1 parent 57df72a commit ac8deb6

15 files changed

+466
-374
lines changed

dialogflow/README.rst

Lines changed: 22 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
.. This file is automatically generated. Do not edit this file directly.
32
43
Dialogflow Enterprise Edition API Python Samples
@@ -16,11 +15,13 @@ This directory contains samples for Dialogflow Enterprise Edition API. The `Dia
1615
.. _Dialogflow Enterprise Edition API: https://cloud.google.com/dialogflow-enterprise/docs/
1716

1817

18+
19+
20+
1921
Setup
2022
-------------------------------------------------------------------------------
2123

2224

23-
2425
Authentication
2526
++++++++++++++
2627

@@ -31,9 +32,6 @@ credentials for applications.
3132
.. _Authentication Getting Started Guide:
3233
https://cloud.google.com/docs/authentication/getting-started
3334

34-
35-
36-
3735
Install Dependencies
3836
++++++++++++++++++++
3937

@@ -64,15 +62,9 @@ Install Dependencies
6462
.. _pip: https://pip.pypa.io/
6563
.. _virtualenv: https://virtualenv.pypa.io/
6664

67-
68-
69-
70-
71-
7265
Samples
7366
-------------------------------------------------------------------------------
7467

75-
7668
Detect Intent Text
7769
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7870

@@ -88,7 +80,6 @@ To run this sample:
8880
8981
$ python detect_intent_texts.py
9082
91-
9283
usage: detect_intent_texts.py [-h] --project-id PROJECT_ID
9384
[--session-id SESSION_ID]
9485
[--language-code LANGUAGE_CODE]
@@ -116,8 +107,6 @@ To run this sample:
116107
117108
118109
119-
120-
121110
Detect Intent Audio
122111
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
123112

@@ -133,7 +122,6 @@ To run this sample:
133122
134123
$ python detect_intent_audio.py
135124
136-
137125
usage: detect_intent_audio.py [-h] --project-id PROJECT_ID
138126
[--session-id SESSION_ID]
139127
[--language-code LANGUAGE_CODE]
@@ -161,8 +149,6 @@ To run this sample:
161149
162150
163151
164-
165-
166152
Detect Intent Stream
167153
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
168154

@@ -178,7 +164,6 @@ To run this sample:
178164
179165
$ python detect_intent_stream.py
180166
181-
182167
usage: detect_intent_stream.py [-h] --project-id PROJECT_ID
183168
[--session-id SESSION_ID]
184169
[--language-code LANGUAGE_CODE]
@@ -206,8 +191,6 @@ To run this sample:
206191
207192
208193
209-
210-
211194
Detect Intent Knowledge Base
212195
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
213196

@@ -223,7 +206,6 @@ To run this sample:
223206
224207
$ python detect_intent_knowledge.py
225208
226-
227209
usage: detect_intent_knowledge.py [-h] --project-id PROJECT_ID
228210
[--session-id SESSION_ID]
229211
[--language-code LANGUAGE_CODE]
@@ -253,8 +235,6 @@ To run this sample:
253235
254236
255237
256-
257-
258238
Detect Intent with Sentiment Analysis
259239
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
260240

@@ -270,7 +250,6 @@ To run this sample:
270250
271251
$ python detect_intent_with_sentiment_analysis.py
272252
273-
274253
usage: detect_intent_with_sentiment_analysis.py [-h] --project-id PROJECT_ID
275254
[--session-id SESSION_ID]
276255
[--language-code LANGUAGE_CODE]
@@ -297,8 +276,6 @@ To run this sample:
297276
298277
299278
300-
301-
302279
Detect Intent with Text to Speech Response
303280
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
304281

@@ -314,7 +291,6 @@ To run this sample:
314291
315292
$ python detect_intent_with_texttospeech_response.py
316293
317-
318294
usage: detect_intent_with_texttospeech_response.py [-h] --project-id
319295
PROJECT_ID
320296
[--session-id SESSION_ID]
@@ -342,8 +318,6 @@ To run this sample:
342318
343319
344320
345-
346-
347321
Intent Management
348322
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
349323

@@ -359,7 +333,6 @@ To run this sample:
359333
360334
$ python intent_management.py
361335
362-
363336
usage: intent_management.py [-h] --project-id PROJECT_ID
364337
{list,create,delete} ...
365338
@@ -385,8 +358,6 @@ To run this sample:
385358
386359
387360
388-
389-
390361
Knowledge Base Management
391362
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
392363

@@ -402,18 +373,24 @@ To run this sample:
402373
403374
$ python knowledge_base_management.py
404375
405-
406-
usage: knowledge_base_management.py [-h] --project-id PROJECT_ID {create} ...
376+
usage: knowledge_base_management.py [-h] --project-id PROJECT_ID
377+
{list,create,get,delete} ...
407378
408379
Dialogflow API Python sample showing how to manage Knowledge bases.
409380
410381
Examples:
411382
python knowledge_base_management.py -h
383+
python knowledge_base_management.py --project-id PROJECT_ID list
412384
python knowledge_base_management.py --project-id PROJECT_ID create --display-name DISPLAY_NAME
385+
python knowledge_base_management.py --project-id PROJECT_ID get --knowledge-base-id knowledge_base_id
386+
python knowledge_base_management.py --project-id PROJECT_ID delete --knowledge-base-id knowledge_base_id
413387
414388
positional arguments:
415-
{create}
389+
{list,create,get,delete}
390+
list List all Knowledge bases that belong to the project.
416391
create Create a new Knowledge base.
392+
get Get a Knowledge base by its id.
393+
delete Delete a Knowledge base by its id.
417394
418395
optional arguments:
419396
-h, --help show this help message and exit
@@ -422,8 +399,6 @@ To run this sample:
422399
423400
424401
425-
426-
427402
Document Management
428403
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
429404

@@ -439,21 +414,26 @@ To run this sample:
439414
440415
$ python document_management.py
441416
442-
443417
usage: document_management.py [-h] --project-id PROJECT_ID --knowledge-base-id
444418
KNOWLEDGE_BASE_ID
445-
{create} ...
419+
{list,create,get,delete} ...
446420
447421
Dialogflow API Python sample showing how to manage Knowledge Documents.
448422
449423
Examples:
450424
python document_management.py -h
425+
python document_management.py --project-id PROJECT_ID --knowledge-base-id knowledge_base_id list
451426
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
452-
python document_management.py --project-id PROJECT_ID --knowledge-base-id knowledge_base_id
427+
python document_management.py --project-id PROJECT_ID --knowledge-base-id knowledge_base_id get --document-id DOCUMENT_ID
428+
python document_management.py --project-id PROJECT_ID --knowledge-base-id knowledge_base_id delete --document-id DOCUMENT_ID
453429
454430
positional arguments:
455-
{create}
431+
{list,create,get,delete}
432+
list List all Documents that belong to a certain Knowledge
433+
base.
456434
create Create a Document for a certain Knowledge base.
435+
get Get a Document by its id and the Knowledge base id.
436+
delete Delete a Document by its id and the Knowledge baseid.
457437
458438
optional arguments:
459439
-h, --help show this help message and exit
@@ -467,10 +447,6 @@ To run this sample:
467447
468448
469449
470-
471-
472-
473-
474450
The client library
475451
-------------------------------------------------------------------------------
476452

@@ -486,5 +462,4 @@ to `browse the source`_ and `report issues`_.
486462
https://github.com/GoogleCloudPlatform/google-cloud-python/issues
487463

488464

489-
490-
.. _Google Cloud SDK: https://cloud.google.com/sdk/
465+
.. _Google Cloud SDK: https://cloud.google.com/sdk/

dialogflow/answer_record_management.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,17 @@ def update_answer_record(project_id, answer_record_id, is_clicked):
3030
is_clicked: whether the answer record is clicked."""
3131

3232
client = dialogflow.AnswerRecordsClient()
33-
answer_record_path = client.answer_record_path(project_id,
34-
answer_record_id)
33+
answer_record_path = client.answer_record_path(project_id, answer_record_id)
3534

3635
response = client.update_answer_record(
3736
answer_record={
38-
'name': answer_record_path,
39-
'answer_feedback': {
40-
'clicked': is_clicked
41-
}
37+
"name": answer_record_path,
38+
"answer_feedback": {"clicked": is_clicked},
4239
},
43-
update_mask={'paths': ['answer_feedback']})
44-
print('AnswerRecord Name: {}'.format(response.name))
45-
print('Clicked: {}'.format(response.answer_feedback.clicked))
40+
update_mask={"paths": ["answer_feedback"]},
41+
)
42+
print("AnswerRecord Name: {}".format(response.name))
43+
print("Clicked: {}".format(response.answer_feedback.clicked))
4644
return response
4745

4846

dialogflow/answer_record_management_test.py

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
import conversation_profile_management
2020
import participant_management
2121

22-
PROJECT_ID = os.getenv('GOOGLE_CLOUD_PROJECT')
23-
SMART_REPLY_MODEL = os.getenv('SMART_REPLY_MODEL')
24-
SMART_REPLY_ALLOWLIST = os.getenv('SMART_REPLY_ALLOWLIST')
25-
CONVERSATION_PROFILE_DISPLAY_NAME = 'sample code profile for smart reply'
22+
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
23+
SMART_REPLY_MODEL = os.getenv("SMART_REPLY_MODEL")
24+
SMART_REPLY_ALLOWLIST = os.getenv("SMART_REPLY_ALLOWLIST")
25+
CONVERSATION_PROFILE_DISPLAY_NAME = "sample code profile for smart reply"
2626

2727

2828
def test_smart_reply(capsys):
@@ -34,64 +34,72 @@ def test_smart_reply(capsys):
3434
project_id=PROJECT_ID,
3535
display_name=CONVERSATION_PROFILE_DISPLAY_NAME,
3636
smart_reply_allowlist_name=SMART_REPLY_ALLOWLIST,
37-
smart_reply_model_name=SMART_REPLY_MODEL)
37+
smart_reply_model_name=SMART_REPLY_MODEL,
38+
)
3839

3940
out, _ = capsys.readouterr()
40-
assert 'Display Name: {}'.format(CONVERSATION_PROFILE_DISPLAY_NAME) in out
41-
conversation_profile_id = out.split('conversationProfiles/')[1].rstrip()
41+
assert "Display Name: {}".format(CONVERSATION_PROFILE_DISPLAY_NAME) in out
42+
conversation_profile_id = out.split("conversationProfiles/")[1].rstrip()
4243

4344
# Create conversation.
4445
conversation_management.create_conversation(
45-
project_id=PROJECT_ID, conversation_profile_id=conversation_profile_id)
46+
project_id=PROJECT_ID, conversation_profile_id=conversation_profile_id
47+
)
4648

4749
out, _ = capsys.readouterr()
48-
conversation_id = out.split('conversations/')[1].rstrip()
50+
conversation_id = out.split("conversations/")[1].rstrip()
4951

5052
# Create end user participant.
51-
participant_management.create_participant(project_id=PROJECT_ID,
52-
conversation_id=conversation_id,
53-
role='END_USER')
53+
participant_management.create_participant(
54+
project_id=PROJECT_ID, conversation_id=conversation_id, role="END_USER"
55+
)
5456
out, _ = capsys.readouterr()
55-
end_user_id = out.split('participants/')[1].rstrip()
57+
end_user_id = out.split("participants/")[1].rstrip()
5658

5759
# Create human agent participant.
58-
participant_management.create_participant(project_id=PROJECT_ID,
59-
conversation_id=conversation_id,
60-
role='HUMAN_AGENT')
60+
participant_management.create_participant(
61+
project_id=PROJECT_ID, conversation_id=conversation_id, role="HUMAN_AGENT"
62+
)
6163
out, _ = capsys.readouterr()
62-
human_agent_id = out.split('participants/')[1].rstrip()
64+
human_agent_id = out.split("participants/")[1].rstrip()
6365

6466
# AnalyzeContent
6567
participant_management.analyze_content_text(
6668
project_id=PROJECT_ID,
6769
conversation_id=conversation_id,
6870
participant_id=human_agent_id,
69-
text='Hi, how are you?')
71+
text="Hi, how are you?",
72+
)
7073
out, _ = capsys.readouterr()
71-
assert 'What would you like to know?' in out
74+
assert "What would you like to know?" in out
7275

7376
response = participant_management.analyze_content_text(
7477
project_id=PROJECT_ID,
7578
conversation_id=conversation_id,
7679
participant_id=end_user_id,
77-
text='I am doing well, just want to check')
80+
text="I am doing well, just want to check",
81+
)
7882
out, _ = capsys.readouterr()
79-
assert 'Sounds good.' in out
83+
assert "Sounds good." in out
8084
# Update AnswerRecord.
81-
answer_record_id = response.human_agent_suggestion_results[
82-
0].suggest_smart_replies_response.smart_reply_answers[
83-
0].answer_record.split('answerRecords/')[1].rstrip()
85+
answer_record_id = (
86+
response.human_agent_suggestion_results[0]
87+
.suggest_smart_replies_response.smart_reply_answers[0]
88+
.answer_record.split("answerRecords/")[1]
89+
.rstrip()
90+
)
8491
answer_record_management.update_answer_record(
85-
project_id=PROJECT_ID,
86-
answer_record_id=answer_record_id,
87-
is_clicked=True)
92+
project_id=PROJECT_ID, answer_record_id=answer_record_id, is_clicked=True
93+
)
8894
out, _ = capsys.readouterr()
89-
assert 'Clicked: True' in out
95+
assert "Clicked: True" in out
9096

9197
# Complete conversation.
9298
conversation_management.complete_conversation(
93-
project_id=PROJECT_ID, conversation_id=conversation_id)
99+
project_id=PROJECT_ID, conversation_id=conversation_id
100+
)
94101

95102
# Delete conversation profile.
96103
conversation_profile_management.delete_conversation_profile(
97-
project_id=PROJECT_ID, conversation_profile_id=conversation_profile_id)
104+
project_id=PROJECT_ID, conversation_profile_id=conversation_profile_id
105+
)

0 commit comments

Comments
 (0)