Skip to content

Commit b1458d8

Browse files
Merge pull request #362 from watson-developer-cloud/codegen/conversation
Regenerate conversation and add more tests
2 parents 1850dd4 + 20fbed6 commit b1458d8

4 files changed

Lines changed: 137 additions & 135 deletions

File tree

test/unit/test_conversation_v1.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,3 +1446,51 @@ def test_update_workspace():
14461446
assert workspace == response
14471447
# Verify that response can be converted to a Workspace
14481448
Workspace._from_dict(workspace)
1449+
1450+
@responses.activate
1451+
def test_dialog_nodes():
1452+
url = 'https://gateway.watsonplatform.net/conversation/api/v1/workspaces/id/dialog_nodes'
1453+
responses.add(
1454+
responses.GET,
1455+
url,
1456+
body='{ "application/json": { "dialog_node": "location-atm" }}',
1457+
status=200,
1458+
content_type='application/json')
1459+
1460+
responses.add(
1461+
responses.POST,
1462+
"{0}?version=2017-05-26".format(url),
1463+
body='{ "application/json": { "dialog_node": "location-done" }}',
1464+
status=200,
1465+
content_type='application/json')
1466+
1467+
responses.add(
1468+
responses.DELETE,
1469+
"{0}/location-done?version=2017-05-26".format(url),
1470+
body='{"description": "deleted successfully"}',
1471+
status=200,
1472+
content_type='application/json')
1473+
1474+
responses.add(
1475+
responses.GET,
1476+
"{0}/location-done?version=2017-05-26".format(url),
1477+
body='{ "application/json": { "dialog_node": "location-atm" }}',
1478+
status=200,
1479+
content_type='application/json')
1480+
1481+
conversation = watson_developer_cloud.ConversationV1('2017-05-26',
1482+
username="username", password="password")
1483+
1484+
conversation.create_dialog_node('id', 'location-done')
1485+
assert responses.calls[0].response.json()['application/json']['dialog_node'] == 'location-done'
1486+
1487+
conversation.delete_dialog_node('id', 'location-done')
1488+
assert responses.calls[1].response.json() == {"description": "deleted successfully"}
1489+
1490+
conversation.get_dialog_node('id', 'location-done')
1491+
assert responses.calls[2].response.json() == { "application/json": { "dialog_node": "location-atm" }}
1492+
1493+
conversation.list_dialog_nodes('id')
1494+
assert responses.calls[3].response.json() == { "application/json": { "dialog_node": "location-atm" }}
1495+
1496+
assert len(responses.calls) == 4

watson_developer_cloud/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from .watson_service import WatsonInvalidArgument
1919
from .authorization_v1 import AuthorizationV1
2020
from .conversation_v1 import ConversationV1
21-
from .dialog_v1 import DialogV1
2221
from .language_translation_v2 import LanguageTranslationV2
2322
from .language_translator_v2 import LanguageTranslatorV2
2423
from .natural_language_classifier_v1 import NaturalLanguageClassifierV1

watson_developer_cloud/conversation_v1.py

Lines changed: 89 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# coding: utf-8
22

3-
# Copyright 2017 IBM All Rights Reserved.
3+
# Copyright 2018 IBM All Rights Reserved.
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -213,7 +213,8 @@ def update_workspace(self,
213213
dialog_nodes=None,
214214
counterexamples=None,
215215
metadata=None,
216-
learning_opt_out=None):
216+
learning_opt_out=None,
217+
append=None):
217218
"""
218219
Update workspace.
219220
@@ -230,6 +231,7 @@ def update_workspace(self,
230231
:param list[CreateCounterexample] counterexamples: An array of objects defining input examples that have been marked as irrelevant input.
231232
:param object metadata: Any metadata related to the workspace.
232233
:param bool learning_opt_out: Whether training data from the workspace can be used by IBM for general service improvements. `true` indicates that workspace training data is not to be used.
234+
:param bool append: Specifies that the elements included in the request body are to be appended to the existing data in the workspace. The default value is `false`.
233235
:return: A `dict` containing the `Workspace` response.
234236
:rtype: dict
235237
"""
@@ -243,7 +245,7 @@ def update_workspace(self,
243245
dialog_nodes = [self._convert_model(x) for x in dialog_nodes]
244246
if counterexamples is not None:
245247
counterexamples = [self._convert_model(x) for x in counterexamples]
246-
params = {'version': self.version}
248+
params = {'version': self.version, 'append': append}
247249
data = {
248250
'name': name,
249251
'description': description,
@@ -264,14 +266,16 @@ def update_workspace(self,
264266
# message
265267
#########################
266268

269+
267270
def message(self,
268271
workspace_id,
269272
input=None,
270273
alternate_intents=None,
271274
context=None,
272275
entities=None,
273276
intents=None,
274-
output=None):
277+
output=None,
278+
nodes_visited_details=None):
275279
"""
276280
Get a response to a user's input.
277281
@@ -282,6 +286,7 @@ def message(self,
282286
:param list[RuntimeEntity] entities: Include the entities from the previous response when they do not need to change and to prevent Watson from trying to identify them.
283287
:param list[RuntimeIntent] intents: An array of name-confidence pairs for the user input. Include the intents from the previous response when they do not need to change and to prevent Watson from trying to identify them.
284288
:param OutputData output: System output. Include the output from the request when you have several requests within the same Dialog turn to pass back in the intermediate information.
289+
:param bool nodes_visited_details: Whether to include additional diagnostic information about the dialog nodes that were visited during processing of the message.
285290
:return: A `dict` containing the `MessageResponse` response.
286291
:rtype: dict
287292
"""
@@ -297,7 +302,10 @@ def message(self,
297302
intents = [self._convert_model(x) for x in intents]
298303
if output is not None:
299304
output = self._convert_model(output)
300-
params = {'version': self.version}
305+
params = {
306+
'version': self.version,
307+
'nodes_visited_details': nodes_visited_details
308+
}
301309
data = {
302310
'input': input,
303311
'alternate_intents': alternate_intents,
@@ -1310,7 +1318,7 @@ def update_dialog_node(self,
13101318
:param object new_metadata: The metadata for the dialog node.
13111319
:param DialogNodeNextStep new_next_step: The next step to execute following this dialog node.
13121320
:param str new_title: The alias used to identify the dialog node.
1313-
:param str new_type: How the node is processed.
1321+
:param str new_type: How the dialog node is processed.
13141322
:param str new_event_name: How an `event_handler` node is processed.
13151323
:param str new_variable: The location in the dialog context where output is stored.
13161324
:param list[DialogNodeAction] new_actions: The actions for the dialog node.
@@ -2726,6 +2734,58 @@ def __ne__(self, other):
27262734
return not self == other
27272735

27282736

2737+
class DialogNodeVisitedDetails(object):
2738+
"""
2739+
DialogNodeVisitedDetails.
2740+
2741+
:attr str dialog_node: (optional) A dialog node that was triggered during processing of the input message.
2742+
:attr str title: (optional) The title of the dialog node.
2743+
"""
2744+
2745+
def __init__(self, dialog_node=None, title=None):
2746+
"""
2747+
Initialize a DialogNodeVisitedDetails object.
2748+
2749+
:param str dialog_node: (optional) A dialog node that was triggered during processing of the input message.
2750+
:param str title: (optional) The title of the dialog node.
2751+
"""
2752+
self.dialog_node = dialog_node
2753+
self.title = title
2754+
2755+
@classmethod
2756+
def _from_dict(cls, _dict):
2757+
"""Initialize a DialogNodeVisitedDetails object from a json dictionary."""
2758+
args = {}
2759+
if 'dialog_node' in _dict:
2760+
args['dialog_node'] = _dict['dialog_node']
2761+
if 'title' in _dict:
2762+
args['title'] = _dict['title']
2763+
return cls(**args)
2764+
2765+
def _to_dict(self):
2766+
"""Return a json dictionary representing this model."""
2767+
_dict = {}
2768+
if hasattr(self, 'dialog_node') and self.dialog_node is not None:
2769+
_dict['dialog_node'] = self.dialog_node
2770+
if hasattr(self, 'title') and self.title is not None:
2771+
_dict['title'] = self.title
2772+
return _dict
2773+
2774+
def __str__(self):
2775+
"""Return a `str` version of this DialogNodeVisitedDetails object."""
2776+
return json.dumps(self._to_dict(), indent=2)
2777+
2778+
def __eq__(self, other):
2779+
"""Return `true` when self and other are equal, false otherwise."""
2780+
if not isinstance(other, self.__class__):
2781+
return False
2782+
return self.__dict__ == other.__dict__
2783+
2784+
def __ne__(self, other):
2785+
"""Return `true` when self and other are not equal, false otherwise."""
2786+
return not self == other
2787+
2788+
27292789
class Entity(object):
27302790
"""
27312791
Entity.
@@ -3980,20 +4040,28 @@ class OutputData(object):
39804040
:attr list[LogMessage] log_messages: Up to 50 messages logged with the request.
39814041
:attr list[str] text: An array of responses to the user.
39824042
:attr list[str] nodes_visited: (optional) An array of the nodes that were triggered to create the response.
4043+
:attr list[DialogNodeVisitedDetails] nodes_visited_details: (optional) An array of objects containing detailed diagnostic information about the nodes that were triggered during processing of the input message.
39834044
"""
39844045

3985-
def __init__(self, log_messages, text, nodes_visited=None, **kwargs):
4046+
def __init__(self,
4047+
log_messages,
4048+
text,
4049+
nodes_visited=None,
4050+
nodes_visited_details=None,
4051+
**kwargs):
39864052
"""
39874053
Initialize a OutputData object.
39884054
39894055
:param list[LogMessage] log_messages: Up to 50 messages logged with the request.
39904056
:param list[str] text: An array of responses to the user.
39914057
:param list[str] nodes_visited: (optional) An array of the nodes that were triggered to create the response.
4058+
:param list[DialogNodeVisitedDetails] nodes_visited_details: (optional) An array of objects containing detailed diagnostic information about the nodes that were triggered during processing of the input message.
39924059
:param **kwargs: (optional) Any additional properties.
39934060
"""
39944061
self.log_messages = log_messages
39954062
self.text = text
39964063
self.nodes_visited = nodes_visited
4064+
self.nodes_visited_details = nodes_visited_details
39974065
for _key, _value in kwargs.items():
39984066
setattr(self, _key, _value)
39994067

@@ -4020,6 +4088,12 @@ def _from_dict(cls, _dict):
40204088
if 'nodes_visited' in _dict:
40214089
args['nodes_visited'] = _dict['nodes_visited']
40224090
del xtra['nodes_visited']
4091+
if 'nodes_visited_details' in _dict:
4092+
args['nodes_visited_details'] = [
4093+
DialogNodeVisitedDetails._from_dict(x)
4094+
for x in _dict['nodes_visited_details']
4095+
]
4096+
del xtra['nodes_visited_details']
40234097
args.update(xtra)
40244098
return cls(**args)
40254099

@@ -4032,6 +4106,11 @@ def _to_dict(self):
40324106
_dict['text'] = self.text
40334107
if hasattr(self, 'nodes_visited') and self.nodes_visited is not None:
40344108
_dict['nodes_visited'] = self.nodes_visited
4109+
if hasattr(self, 'nodes_visited_details'
4110+
) and self.nodes_visited_details is not None:
4111+
_dict['nodes_visited_details'] = [
4112+
x._to_dict() for x in self.nodes_visited_details
4113+
]
40354114
if hasattr(self, '_additionalProperties'):
40364115
for _key in self._additionalProperties:
40374116
_value = getattr(self, _key, None)
@@ -4040,7 +4119,9 @@ def _to_dict(self):
40404119
return _dict
40414120

40424121
def __setattr__(self, name, value):
4043-
properties = {'log_messages', 'text', 'nodes_visited'}
4122+
properties = {
4123+
'log_messages', 'text', 'nodes_visited', 'nodes_visited_details'
4124+
}
40444125
if not hasattr(self, '_additionalProperties'):
40454126
super(OutputData, self).__setattr__('_additionalProperties', set())
40464127
if name not in properties:

watson_developer_cloud/dialog_v1.py

Lines changed: 0 additions & 126 deletions
This file was deleted.

0 commit comments

Comments
 (0)