|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 23, |
| 6 | + "metadata": { |
| 7 | + "collapsed": false, |
| 8 | + "deletable": true, |
| 9 | + "editable": true |
| 10 | + }, |
| 11 | + "outputs": [], |
| 12 | + "source": [ |
| 13 | + "import json\n", |
| 14 | + "import sys\n", |
| 15 | + "import os\n", |
| 16 | + "sys.path.append(os.path.join(os.getcwd(),'..','..'))\n", |
| 17 | + "import watson_developer_cloud" |
| 18 | + ] |
| 19 | + }, |
| 20 | + { |
| 21 | + "cell_type": "code", |
| 22 | + "execution_count": 14, |
| 23 | + "metadata": { |
| 24 | + "collapsed": true, |
| 25 | + "deletable": true, |
| 26 | + "editable": true |
| 27 | + }, |
| 28 | + "outputs": [], |
| 29 | + "source": [ |
| 30 | + "USERNAME = os.environ.get('CONVERSATION_USERNAME','<USERNAME>')\n", |
| 31 | + "PASSWORD = os.environ.get('CONVERSATION_PASSWORD','<PASSWORD>')" |
| 32 | + ] |
| 33 | + }, |
| 34 | + { |
| 35 | + "cell_type": "code", |
| 36 | + "execution_count": 15, |
| 37 | + "metadata": { |
| 38 | + "collapsed": false, |
| 39 | + "deletable": true, |
| 40 | + "editable": true |
| 41 | + }, |
| 42 | + "outputs": [], |
| 43 | + "source": [ |
| 44 | + "conversation = watson_developer_cloud.ConversationV1(username=USERNAME,\n", |
| 45 | + " password=PASSWORD,\n", |
| 46 | + " version='2016-09-20')" |
| 47 | + ] |
| 48 | + }, |
| 49 | + { |
| 50 | + "cell_type": "code", |
| 51 | + "execution_count": 28, |
| 52 | + "metadata": { |
| 53 | + "collapsed": false, |
| 54 | + "deletable": true, |
| 55 | + "editable": true |
| 56 | + }, |
| 57 | + "outputs": [ |
| 58 | + { |
| 59 | + "data": { |
| 60 | + "text/plain": [ |
| 61 | + "{'pagination': {'refresh_url': '/v1/workspaces?version=2016-09-20'},\n", |
| 62 | + " 'workspaces': [{'created': '2017-02-09T19:46:26.792Z',\n", |
| 63 | + " 'description': 'yo dawg',\n", |
| 64 | + " 'language': 'en',\n", |
| 65 | + " 'metadata': None,\n", |
| 66 | + " 'name': 'development',\n", |
| 67 | + " 'updated': '2017-02-09T20:00:38.558Z',\n", |
| 68 | + " 'workspace_id': '8c8ee3b3-6149-4bc0-ba66-6517fd6c976a'}]}" |
| 69 | + ] |
| 70 | + }, |
| 71 | + "execution_count": 28, |
| 72 | + "metadata": {}, |
| 73 | + "output_type": "execute_result" |
| 74 | + } |
| 75 | + ], |
| 76 | + "source": [ |
| 77 | + "conversation.list_workspaces()" |
| 78 | + ] |
| 79 | + }, |
| 80 | + { |
| 81 | + "cell_type": "code", |
| 82 | + "execution_count": 29, |
| 83 | + "metadata": { |
| 84 | + "collapsed": false, |
| 85 | + "deletable": true, |
| 86 | + "editable": true |
| 87 | + }, |
| 88 | + "outputs": [ |
| 89 | + { |
| 90 | + "name": "stdout", |
| 91 | + "output_type": "stream", |
| 92 | + "text": [ |
| 93 | + "{'name': 'my experimental workspace', 'created': '2017-02-09T21:48:35.245Z', 'updated': '2017-02-09T21:48:35.245Z', 'language': 'en', 'metadata': None, 'description': 'an experimental workspace', 'workspace_id': 'dbd1211f-3abb-4165-8a67-8bfa95410aa9'}\n" |
| 94 | + ] |
| 95 | + } |
| 96 | + ], |
| 97 | + "source": [ |
| 98 | + "new_workspace = conversation.create_workspace(name='my experimental workspace',\n", |
| 99 | + " description='an experimental workspace',\n", |
| 100 | + " language='en',\n", |
| 101 | + " intents=[{\n", |
| 102 | + " \"intent\": \"orderpizza\",\n", |
| 103 | + " \"examples\": [\n", |
| 104 | + " {\n", |
| 105 | + " \"text\": \"can I order a pizza?\"\n", |
| 106 | + " },\n", |
| 107 | + " {\n", |
| 108 | + " \"text\": \"I want to order a pizza\"\n", |
| 109 | + " },\n", |
| 110 | + " {\n", |
| 111 | + " \"text\": \"pizza order\"\n", |
| 112 | + " },\n", |
| 113 | + " {\n", |
| 114 | + " \"text\": \"pizza to go\"\n", |
| 115 | + " }\n", |
| 116 | + " ],\n", |
| 117 | + " \"description\": \"pizza intents\"\n", |
| 118 | + " }\n", |
| 119 | + " ],\n", |
| 120 | + " dialog_nodes=[{'conditions': '#orderpizza',\n", |
| 121 | + " 'context': None,\n", |
| 122 | + " 'description': None,\n", |
| 123 | + " 'dialog_node': 'YesYouCan',\n", |
| 124 | + " 'go_to': None,\n", |
| 125 | + " 'metadata': None,\n", |
| 126 | + " 'output': {'text': {'selection_policy': 'random',\n", |
| 127 | + " 'values': \n", |
| 128 | + " ['Yes You can!', 'Of course!']}},\n", |
| 129 | + " 'parent': None,\n", |
| 130 | + " 'previous_sibling': None,}])\n", |
| 131 | + "print(new_workspace)" |
| 132 | + ] |
| 133 | + }, |
| 134 | + { |
| 135 | + "cell_type": "code", |
| 136 | + "execution_count": 31, |
| 137 | + "metadata": { |
| 138 | + "collapsed": false, |
| 139 | + "deletable": true, |
| 140 | + "editable": true |
| 141 | + }, |
| 142 | + "outputs": [ |
| 143 | + { |
| 144 | + "data": { |
| 145 | + "text/plain": [ |
| 146 | + "{'created': '2017-02-09T21:48:35.245Z',\n", |
| 147 | + " 'description': 'an experimental workspace',\n", |
| 148 | + " 'language': 'en',\n", |
| 149 | + " 'metadata': None,\n", |
| 150 | + " 'name': 'my experimental workspace',\n", |
| 151 | + " 'status': 'Training',\n", |
| 152 | + " 'updated': '2017-02-09T21:48:35.245Z',\n", |
| 153 | + " 'workspace_id': 'dbd1211f-3abb-4165-8a67-8bfa95410aa9'}" |
| 154 | + ] |
| 155 | + }, |
| 156 | + "execution_count": 31, |
| 157 | + "metadata": {}, |
| 158 | + "output_type": "execute_result" |
| 159 | + } |
| 160 | + ], |
| 161 | + "source": [ |
| 162 | + "conversation.get_workspace(workspace_id=new_workspace['workspace_id'])" |
| 163 | + ] |
| 164 | + }, |
| 165 | + { |
| 166 | + "cell_type": "code", |
| 167 | + "execution_count": 20, |
| 168 | + "metadata": { |
| 169 | + "collapsed": false, |
| 170 | + "deletable": true, |
| 171 | + "editable": true |
| 172 | + }, |
| 173 | + "outputs": [ |
| 174 | + { |
| 175 | + "data": { |
| 176 | + "text/plain": [ |
| 177 | + "{'created': '2017-02-09T21:39:30.390Z',\n", |
| 178 | + " 'description': 'an experimental workspace',\n", |
| 179 | + " 'language': 'en',\n", |
| 180 | + " 'metadata': None,\n", |
| 181 | + " 'name': 'changed name',\n", |
| 182 | + " 'updated': '2017-02-09T21:39:59.124Z',\n", |
| 183 | + " 'workspace_id': '66e78807-13fa-47ae-9251-dd8c89c8fd19'}" |
| 184 | + ] |
| 185 | + }, |
| 186 | + "execution_count": 20, |
| 187 | + "metadata": {}, |
| 188 | + "output_type": "execute_result" |
| 189 | + } |
| 190 | + ], |
| 191 | + "source": [ |
| 192 | + "new_workspace['name'] = 'changed name'\n", |
| 193 | + "conversation.update_workspace(new_workspace['workspace_id'], name=new_workspace['name'])" |
| 194 | + ] |
| 195 | + }, |
| 196 | + { |
| 197 | + "cell_type": "code", |
| 198 | + "execution_count": 32, |
| 199 | + "metadata": { |
| 200 | + "collapsed": false, |
| 201 | + "deletable": true, |
| 202 | + "editable": true |
| 203 | + }, |
| 204 | + "outputs": [ |
| 205 | + { |
| 206 | + "data": { |
| 207 | + "text/plain": [ |
| 208 | + "{'counterexamples': [],\n", |
| 209 | + " 'created': '2017-02-09T21:48:35.245Z',\n", |
| 210 | + " 'description': 'an experimental workspace',\n", |
| 211 | + " 'dialog_nodes': [{'conditions': '#orderpizza',\n", |
| 212 | + " 'context': None,\n", |
| 213 | + " 'created': '2017-02-09T21:48:35.245Z',\n", |
| 214 | + " 'description': None,\n", |
| 215 | + " 'dialog_node': 'YesYouCan',\n", |
| 216 | + " 'go_to': None,\n", |
| 217 | + " 'metadata': None,\n", |
| 218 | + " 'output': {'text': {'selection_policy': 'random',\n", |
| 219 | + " 'values': ['Yes You can!', 'Of course!']}},\n", |
| 220 | + " 'parent': None,\n", |
| 221 | + " 'previous_sibling': None,\n", |
| 222 | + " 'updated': '2017-02-09T21:48:35.245Z'}],\n", |
| 223 | + " 'entities': [],\n", |
| 224 | + " 'intents': [{'created': '2017-02-09T21:48:35.245Z',\n", |
| 225 | + " 'description': 'pizza intents',\n", |
| 226 | + " 'examples': [{'created': '2017-02-09T21:48:35.245Z',\n", |
| 227 | + " 'text': 'can I order a pizza?',\n", |
| 228 | + " 'updated': '2017-02-09T21:48:35.245Z'},\n", |
| 229 | + " {'created': '2017-02-09T21:48:35.245Z',\n", |
| 230 | + " 'text': 'I want to order a pizza',\n", |
| 231 | + " 'updated': '2017-02-09T21:48:35.245Z'},\n", |
| 232 | + " {'created': '2017-02-09T21:48:35.245Z',\n", |
| 233 | + " 'text': 'pizza order',\n", |
| 234 | + " 'updated': '2017-02-09T21:48:35.245Z'},\n", |
| 235 | + " {'created': '2017-02-09T21:48:35.245Z',\n", |
| 236 | + " 'text': 'pizza to go',\n", |
| 237 | + " 'updated': '2017-02-09T21:48:35.245Z'}],\n", |
| 238 | + " 'intent': 'orderpizza',\n", |
| 239 | + " 'updated': '2017-02-09T21:48:35.245Z'}],\n", |
| 240 | + " 'language': 'en',\n", |
| 241 | + " 'metadata': None,\n", |
| 242 | + " 'name': 'my experimental workspace',\n", |
| 243 | + " 'status': 'Available',\n", |
| 244 | + " 'updated': '2017-02-09T21:48:35.245Z',\n", |
| 245 | + " 'workspace_id': 'dbd1211f-3abb-4165-8a67-8bfa95410aa9'}" |
| 246 | + ] |
| 247 | + }, |
| 248 | + "execution_count": 32, |
| 249 | + "metadata": {}, |
| 250 | + "output_type": "execute_result" |
| 251 | + } |
| 252 | + ], |
| 253 | + "source": [ |
| 254 | + "conversation.get_workspace(new_workspace['workspace_id'], export=True)" |
| 255 | + ] |
| 256 | + }, |
| 257 | + { |
| 258 | + "cell_type": "code", |
| 259 | + "execution_count": 34, |
| 260 | + "metadata": { |
| 261 | + "collapsed": false, |
| 262 | + "deletable": true, |
| 263 | + "editable": true |
| 264 | + }, |
| 265 | + "outputs": [ |
| 266 | + { |
| 267 | + "name": "stdout", |
| 268 | + "output_type": "stream", |
| 269 | + "text": [ |
| 270 | + "{\n", |
| 271 | + " \"intents\": [\n", |
| 272 | + " {\n", |
| 273 | + " \"intent\": \"orderpizza\",\n", |
| 274 | + " \"confidence\": 1\n", |
| 275 | + " }\n", |
| 276 | + " ],\n", |
| 277 | + " \"entities\": [],\n", |
| 278 | + " \"input\": {\n", |
| 279 | + " \"text\": \"can I order a pizza?\"\n", |
| 280 | + " },\n", |
| 281 | + " \"output\": {\n", |
| 282 | + " \"log_messages\": [],\n", |
| 283 | + " \"text\": [\n", |
| 284 | + " \"Of course!\"\n", |
| 285 | + " ],\n", |
| 286 | + " \"nodes_visited\": [\n", |
| 287 | + " \"YesYouCan\"\n", |
| 288 | + " ]\n", |
| 289 | + " },\n", |
| 290 | + " \"context\": {\n", |
| 291 | + " \"conversation_id\": \"972f212d-be0f-47fd-a82d-a6f917e16cfd\",\n", |
| 292 | + " \"system\": {\n", |
| 293 | + " \"dialog_stack\": [\n", |
| 294 | + " {\n", |
| 295 | + " \"dialog_node\": \"root\"\n", |
| 296 | + " }\n", |
| 297 | + " ],\n", |
| 298 | + " \"dialog_turn_counter\": 1,\n", |
| 299 | + " \"dialog_request_counter\": 1,\n", |
| 300 | + " \"_node_output_map\": {\n", |
| 301 | + " \"YesYouCan\": [\n", |
| 302 | + " 0,\n", |
| 303 | + " 1,\n", |
| 304 | + " 0\n", |
| 305 | + " ]\n", |
| 306 | + " }\n", |
| 307 | + " }\n", |
| 308 | + " },\n", |
| 309 | + " \"alternate_intents\": false\n", |
| 310 | + "}\n" |
| 311 | + ] |
| 312 | + } |
| 313 | + ], |
| 314 | + "source": [ |
| 315 | + "response = conversation.message(workspace_id=new_workspace['workspace_id'],\n", |
| 316 | + " message_input={'text': 'can I order a pizza?'})\n", |
| 317 | + "print(json.dumps(response, indent=2))" |
| 318 | + ] |
| 319 | + }, |
| 320 | + { |
| 321 | + "cell_type": "code", |
| 322 | + "execution_count": 35, |
| 323 | + "metadata": { |
| 324 | + "collapsed": false, |
| 325 | + "deletable": true, |
| 326 | + "editable": true |
| 327 | + }, |
| 328 | + "outputs": [ |
| 329 | + { |
| 330 | + "data": { |
| 331 | + "text/plain": [ |
| 332 | + "{}" |
| 333 | + ] |
| 334 | + }, |
| 335 | + "execution_count": 35, |
| 336 | + "metadata": {}, |
| 337 | + "output_type": "execute_result" |
| 338 | + } |
| 339 | + ], |
| 340 | + "source": [ |
| 341 | + "conversation.delete_workspace(new_workspace['workspace_id'])" |
| 342 | + ] |
| 343 | + } |
| 344 | + ], |
| 345 | + "metadata": { |
| 346 | + "kernelspec": { |
| 347 | + "display_name": "Python 3", |
| 348 | + "language": "python", |
| 349 | + "name": "python3" |
| 350 | + }, |
| 351 | + "language_info": { |
| 352 | + "codemirror_mode": { |
| 353 | + "name": "ipython", |
| 354 | + "version": 3 |
| 355 | + }, |
| 356 | + "file_extension": ".py", |
| 357 | + "mimetype": "text/x-python", |
| 358 | + "name": "python", |
| 359 | + "nbconvert_exporter": "python", |
| 360 | + "pygments_lexer": "ipython3", |
| 361 | + "version": "3.6.0" |
| 362 | + } |
| 363 | + }, |
| 364 | + "nbformat": 4, |
| 365 | + "nbformat_minor": 2 |
| 366 | +} |
0 commit comments