|
19 | 19 | # workspaces |
20 | 20 | ######################### |
21 | 21 |
|
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']) |
26 | 62 | print(json.dumps(response, indent=2)) |
27 | 63 |
|
28 | 64 | workspace_id = response['workspace_id'] |
| 65 | +print("Workspace id ".format(workspace_id)) |
29 | 66 |
|
30 | 67 | response = conversation.get_workspace(workspace_id=workspace_id, export=True) |
31 | 68 | print(json.dumps(response, indent=2)) |
|
48 | 85 | # intents |
49 | 86 | ######################### |
50 | 87 |
|
| 88 | +examples = [{ "text": "good morning"}] |
51 | 89 | response = conversation.create_intent(workspace_id=workspace_id, |
52 | 90 | intent='test_intent', |
53 | | - description='Test intent.') |
| 91 | + description='Test intent.', |
| 92 | + examples=examples) |
54 | 93 | print(json.dumps(response, indent=2)) |
55 | 94 |
|
56 | 95 | response = conversation.get_intent(workspace_id=workspace_id, |
|
134 | 173 | values=values) |
135 | 174 | print(json.dumps(response, indent=2)) |
136 | 175 |
|
| 176 | +entities = [{ |
| 177 | + 'entity': 'pattern_entity', |
| 178 | + 'values': [{ |
| 179 | + 'value': 'value0', 'patterns': ['\\d{6}\\w{1}\\d{7}'], 'value_type': 'patterns' |
| 180 | + }, |
| 181 | + {'value': 'value1', |
| 182 | + 'patterns': ['[-9][0-9][0-9][0-9][0-9]~! [1-9][1-9][1-9][1-9][1-9][1-9]'], |
| 183 | + 'value_type': 'patterns'}, |
| 184 | + {'value': 'value2', |
| 185 | + 'patterns': ['[a-z-9]{17}'], |
| 186 | + 'value_type': 'patterns'}, |
| 187 | + {'value': 'value3', |
| 188 | + 'patterns': [ |
| 189 | + '\\d{3}(\\ |-)\\d{3}(\\ |-)\\d{4}', |
| 190 | + '\\(\\d{3}\\)(\\ |-)\\d{3}(\\ |-)\\d{4}'], |
| 191 | + 'value_type': 'patterns'}, |
| 192 | + {'value': 'value4', |
| 193 | + 'patterns': ['\\b\\d{5}\\b'], |
| 194 | + 'value_type': 'patterns'}] |
| 195 | +}] |
| 196 | +response = conversation.create_entity(workspace_id, |
| 197 | + entity=entities[0]['entity'], |
| 198 | + values=entities[0]['values']) |
| 199 | +print(json.dumps(response, indent=2)) |
| 200 | + |
137 | 201 | response = conversation.get_entity(workspace_id=workspace_id, |
138 | | - entity='test_entity', |
| 202 | + entity=entities[0]['entity'], |
139 | 203 | export=True) |
140 | 204 | print(json.dumps(response, indent=2)) |
141 | 205 |
|
|
198 | 262 |
|
199 | 263 | conversation.delete_entity(workspace_id, 'test_entity') |
200 | 264 |
|
| 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 | + |
201 | 302 | ######################### |
202 | 303 | # logs |
203 | 304 | ######################### |
|
0 commit comments