forked from googleapis/python-dialogflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticipant_management_test.py
144 lines (120 loc) · 5.77 KB
/
participant_management_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import conversation_management
import conversation_profile_management
import document_management
import knowledge_base_management
import participant_management
PROJECT_ID = os.getenv('GOOGLE_CLOUD_PROJECT')
KNOWLEDGE_BASE_DISPLAY_NAME = 'fake_KNOWLEDGE_BASE_DISPLAY_NAME'
DOCUMENT_DISPLAY_NAME = 'Cancel an order'
CONVERSATION_PROFILE_DISPLAY_NAME = 'fake_conversation_profile'
def test_analyze_content_text(capsys):
"""Test analyze content api with text only messages.
"""
# Create knowledge base.
knowledge_base_management.create_knowledge_base(
PROJECT_ID, KNOWLEDGE_BASE_DISPLAY_NAME)
out, _ = capsys.readouterr()
knowledge_base_id = out.split('knowledgeBases/')[1].rstrip()
# Get the knowledge base
knowledge_base_management.get_knowledge_base(PROJECT_ID, knowledge_base_id)
out, _ = capsys.readouterr()
assert 'Display Name: {}'.format(KNOWLEDGE_BASE_DISPLAY_NAME) in out
# Create documents. Note that you should get read permission of bucket gs://ruogu/parsed_5_24/7157212.html
# via Pantheon for service account (google application credential account) from here:
# https://pantheon.corp.google.com/storage/browser/ruogu/parsed_5_24/?project=agent-assistant-demo
document_management.create_document(PROJECT_ID, knowledge_base_id,
DOCUMENT_DISPLAY_NAME, 'text/html',
'ARTICLE_SUGGESTION',
'gs://ruogu/parsed_5_24/7157212.html')
out, _ = capsys.readouterr()
document_id = out.split('documents/')[1].split(' - MIME Type:')[0].rstrip()
# Get the Document
document_management.get_document(PROJECT_ID, knowledge_base_id,
document_id)
out, _ = capsys.readouterr()
assert 'Display Name: {}'.format(DOCUMENT_DISPLAY_NAME) in out
# Create conversation profile.
conversation_profile_management.create_conversation_profile_article_faq(
project_id=PROJECT_ID,
display_name=CONVERSATION_PROFILE_DISPLAY_NAME,
article_suggestion_knowledge_base_id=knowledge_base_id)
out, _ = capsys.readouterr()
assert 'Display Name: {}'.format(CONVERSATION_PROFILE_DISPLAY_NAME) in out
conversation_profile_id = out.split('conversationProfiles/')[1].rstrip()
# Create conversation.
conversation_management.create_conversation(
project_id=PROJECT_ID, conversation_profile_id=conversation_profile_id)
out, _ = capsys.readouterr()
conversation_id = out.split('conversations/')[1].rstrip()
# Create end user participant.
participant_management.create_participant(project_id=PROJECT_ID,
conversation_id=conversation_id,
role='END_USER')
out, _ = capsys.readouterr()
end_user_id = out.split('participants/')[1].rstrip()
# Create human agent participant.
participant_management.create_participant(project_id=PROJECT_ID,
conversation_id=conversation_id,
role='HUMAN_AGENT')
out, _ = capsys.readouterr()
human_agent_id = out.split('participants/')[1].rstrip()
# AnalyzeContent
participant_management.analyze_content_text(
project_id=PROJECT_ID,
conversation_id=conversation_id,
participant_id=human_agent_id,
text='Hi, how are you?')
out, _ = capsys.readouterr()
participant_management.analyze_content_text(
project_id=PROJECT_ID,
conversation_id=conversation_id,
participant_id=end_user_id,
text='Hi, I am doing well, how about you?')
out, _ = capsys.readouterr()
participant_management.analyze_content_text(
project_id=PROJECT_ID,
conversation_id=conversation_id,
participant_id=human_agent_id,
text='Great. How can I help you?')
out, _ = capsys.readouterr()
participant_management.analyze_content_text(
project_id=PROJECT_ID,
conversation_id=conversation_id,
participant_id=end_user_id,
text='So I ordered something, but I do not like it.')
out, _ = capsys.readouterr()
participant_management.analyze_content_text(
project_id=PROJECT_ID,
conversation_id=conversation_id,
participant_id=end_user_id,
text='Thinking if I can cancel that order')
suggestion_out, _ = capsys.readouterr()
# Currently suggestion_out won't contain the suggestion we want since it
# takes time for document to be ready to serve.
# assert 'Cancel an order' in suggestion_out
# Complete conversation.
conversation_management.complete_conversation(
project_id=PROJECT_ID, conversation_id=conversation_id)
# Delete conversation profile.
conversation_profile_management.delete_conversation_profile(
project_id=PROJECT_ID, conversation_profile_id=conversation_profile_id)
# Delete document.
document_management.delete_document(PROJECT_ID, knowledge_base_id,
document_id)
# Delete the Knowledge Base.
knowledge_base_management.delete_knowledge_base(PROJECT_ID,
knowledge_base_id)