Skip to content

Commit 29b04b8

Browse files
committed
fix(python sdk conversation): handling renamed props in nested json objects
1 parent d487608 commit 29b04b8

4 files changed

Lines changed: 262 additions & 117 deletions

File tree

examples/conversation_v1.py

Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,50 @@
1919
# workspaces
2020
#########################
2121

22-
response = conversation.create_workspace(name='test_workspace',
23-
description='Test workspace.',
24-
language='en',
25-
metadata={})
22+
create_workspace_data = {
23+
"name": "test_workspace",
24+
"description": "integration tests",
25+
"language": "en",
26+
"intents": [
27+
{
28+
"intent": "hello",
29+
"description": "string",
30+
"examples": [
31+
{
32+
"text": "good morning"
33+
}
34+
]
35+
}
36+
],
37+
"entities": [
38+
{
39+
"entity": "pizza_toppings",
40+
"description": "Tasty pizza toppings",
41+
"metadata": {
42+
"property": "value"
43+
}
44+
}
45+
],
46+
"counterexamples": [
47+
{
48+
"text": "string"
49+
}
50+
],
51+
"metadata": {},
52+
}
53+
54+
55+
response = conversation.create_workspace(name=create_workspace_data['name'],
56+
description=create_workspace_data['description'],
57+
language='en',
58+
intents=create_workspace_data['intents'],
59+
entities=create_workspace_data['entities'],
60+
counterexamples=create_workspace_data['counterexamples'],
61+
metadata=create_workspace_data['metadata'])
2662
print(json.dumps(response, indent=2))
2763

2864
workspace_id = response['workspace_id']
65+
print("Workspace id ".format(workspace_id))
2966

3067
response = conversation.get_workspace(workspace_id=workspace_id, export=True)
3168
print(json.dumps(response, indent=2))
@@ -48,9 +85,11 @@
4885
# intents
4986
#########################
5087

88+
examples = [{ "text": "good morning"}]
5189
response = conversation.create_intent(workspace_id=workspace_id,
5290
intent='test_intent',
53-
description='Test intent.')
91+
description='Test intent.',
92+
examples=examples)
5493
print(json.dumps(response, indent=2))
5594

5695
response = conversation.get_intent(workspace_id=workspace_id,
@@ -160,7 +199,7 @@
160199
print(json.dumps(response, indent=2))
161200

162201
response = conversation.get_entity(workspace_id=workspace_id,
163-
entity='test_entity',
202+
entity=entities[0]['entity'],
164203
export=True)
165204
print(json.dumps(response, indent=2))
166205

@@ -223,6 +262,43 @@
223262

224263
conversation.delete_entity(workspace_id, 'test_entity')
225264

265+
#########################
266+
# Dialog nodes
267+
#########################
268+
create_dialog_node = {
269+
"dialog_node": "greeting",
270+
"description": "greeting messages",
271+
"actions": [
272+
{
273+
"name": "hello",
274+
"type": "client",
275+
"parameters": {},
276+
"result_variable": "string",
277+
"credentials": "string"
278+
}
279+
]
280+
}
281+
response = conversation.create_dialog_node(workspace_id,
282+
create_dialog_node['dialog_node'],
283+
create_dialog_node['description'],
284+
actions=create_dialog_node['actions'])
285+
print(json.dumps(response, indent=2))
286+
287+
response = conversation.get_dialog_node(workspace_id,
288+
create_dialog_node['dialog_node'])
289+
print(json.dumps(response, indent=2))
290+
291+
response = conversation.list_dialog_nodes(workspace_id)
292+
print(json.dumps(response, indent=2))
293+
294+
response = conversation.update_dialog_node(workspace_id,
295+
create_dialog_node['dialog_node'],
296+
new_dialog_node='updated_node')
297+
print(json.dumps(response, indent=2))
298+
299+
response = conversation.delete_dialog_node(workspace_id, 'updated_node')
300+
print(json.dumps(response, indent=2))
301+
226302
#########################
227303
# logs
228304
#########################

test/unit/test_conversation_v1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ def test_message():
899899
message = conversation.message(
900900
workspace_id=workspace_id,
901901
input={'text': 'Turn on the lights'},
902-
context=json.dumps(message_ctx))
902+
context=json.dumps(message_ctx['context']))
903903

904904
assert message is not None
905905
assert responses.calls[1].request.url == message_url1

0 commit comments

Comments
 (0)