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

Commit dfefa4e

Browse files
docs(samples): adds list training phrases sample (#196)
1 parent 74cfc9a commit dfefa4e

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START dialogflow_list_training_phrases]
16+
17+
18+
def list_training_phrases(project_id, agent_id, intent_id, location):
19+
"""Returns all training phrases for a specified intent."""
20+
21+
from google.cloud import dialogflowcx
22+
23+
# Create the intents client
24+
intent_client = dialogflowcx.IntentsClient()
25+
26+
# Specify working intent
27+
intent_name = intent_client.intent_path(project_id, location, agent_id, intent_id)
28+
29+
# Compose the get-intent request
30+
get_intent_request = dialogflowcx.GetIntentRequest(name=intent_name)
31+
32+
intent = intent_client.get_intent(get_intent_request)
33+
34+
# Iterate through the training phrases.
35+
for phrase in intent.training_phrases:
36+
print(phrase)
37+
38+
return intent.training_phrases
39+
40+
41+
# [END dialogflow_list_training_phrases]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2021 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import os
18+
19+
import google.auth
20+
21+
import list_training_phrases
22+
23+
24+
_, PROJECT_ID = google.auth.default()
25+
INTENT_ID = os.getenv("INTENT_ID")
26+
LOCATION = "global"
27+
AGENT_ID = os.getenv("AGENT_ID")
28+
29+
30+
def test_list_training_phrases(capsys):
31+
training_phrases = list_training_phrases.list_training_phrases(
32+
PROJECT_ID, AGENT_ID, INTENT_ID, LOCATION
33+
)
34+
assert len(training_phrases) >= 15 # Number of training phrases at this point.

samples/snippets/noxfile_config.py

+1
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@
3535
"AGENT_ID": "53516802-3e2a-4016-80b6-a3df0d240240",
3636
"AGENT_ID_US_CENTRAL1": "edf8372c-c66a-4984-83ba-b85885e95e2a",
3737
"AUDIO_PATH": "resources/hello.wav",
38+
"INTENT_ID": "164428bd-647a-4e30-ab0f-cc7f3e3b76f9",
3839
},
3940
}

0 commit comments

Comments
 (0)