{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Assistant Service"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import json\n",
    "import sys\n",
    "import os\n",
    "sys.path.append(os.path.join(os.getcwd(),'..','..'))\n",
    "import ibm_watson\n",
    "from ibm_cloud_sdk_core.authenticators import IAMAuthenticator"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "API_KEY = os.environ.get('ASSISTANT_APIKEY','<ASSISTANT_APIKEY>')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "authenticator = IAMAuthenticator(API_KEY)\n",
    "assistant = ibm_watson.AssistantV1(version='2018-07-10', authenticator=authenticator)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Pizza Chatbot"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's create and chat with a simple pizza bot. We'll start by defining the bot's workspace, then add intents and examples to recognize pizza orders. Once the chatbot is configured, we'll send a message to converse with our pizza bot."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"learning_opt_out\": false, \n",
      "  \"workspace_id\": \"8db6b689-c4a7-4bb0-a2a7-86e58587f8f9\", \n",
      "  \"language\": \"en\", \n",
      "  \"name\": \"example_workspace\", \n",
      "  \"metadata\": {\n",
      "    \"api_version\": {\n",
      "      \"major_version\": \"v1\", \n",
      "      \"minor_version\": \"2018-07-10\"\n",
      "    }\n",
      "  }, \n",
      "  \"description\": \"An example workspace.\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "# define the dialog for our example workspace\n",
    "dialog_nodes = [{'conditions': '#order_pizza',\n",
    "                 'context': None,\n",
    "                 'description': None,\n",
    "                 'dialog_node': 'YesYouCan',\n",
    "                 'go_to': None,\n",
    "                 'metadata': None,\n",
    "                 'output': {'text': {'selection_policy': 'random',\n",
    "                                     'values': ['Yes You can!', 'Of course!']}},\n",
    "                 'parent': None,\n",
    "                 'previous_sibling': None,}]\n",
    "\n",
    "# create an example workspace\n",
    "workspace = assistant.create_workspace(name='example_workspace',\n",
    "                                          description='An example workspace.',\n",
    "                                          language='en',\n",
    "                                          dialog_nodes=dialog_nodes).get_result()\n",
    "\n",
    "# print response and save workspace_id\n",
    "print(json.dumps(workspace, indent=2))\n",
    "workspace_id=workspace['workspace_id']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"intent\": \"order_pizza\", \n",
      "  \"description\": \"A pizza order.\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "# add an intent to the workspace\n",
    "intent = assistant.create_intent(workspace_id=workspace_id,\n",
    "                                    intent='order_pizza',\n",
    "                                    description='A pizza order.').get_result()\n",
    "print(json.dumps(intent, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"text\": \"Can I order a pizza?\"\n",
      "}\n",
      "{\n",
      "  \"text\": \"I want to order a pizza.\"\n",
      "}\n",
      "{\n",
      "  \"text\": \"pizza order\"\n",
      "}\n",
      "{\n",
      "  \"text\": \"pizza to go\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "# add examples to the intent\n",
    "example1 = assistant.create_example(workspace_id=workspace_id,\n",
    "                                       intent='order_pizza',\n",
    "                                       text='Can I order a pizza?').get_result()\n",
    "example2 = assistant.create_example(workspace_id=workspace_id,\n",
    "                                       intent='order_pizza',\n",
    "                                       text='I want to order a pizza.').get_result()\n",
    "example3 = assistant.create_example(workspace_id=workspace_id,\n",
    "                                       intent='order_pizza',\n",
    "                                       text='pizza order').get_result()\n",
    "example4 = assistant.create_example(workspace_id=workspace_id,\n",
    "                                       intent='order_pizza',\n",
    "                                       text='pizza to go').get_result()\n",
    "\n",
    "print(json.dumps(example1, indent=2))\n",
    "print(json.dumps(example2, indent=2))\n",
    "print(json.dumps(example3, indent=2))\n",
    "print(json.dumps(example4, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The workspace status is: Available\n",
      "Ready to chat!\n"
     ]
    }
   ],
   "source": [
    "# check workspace status (wait for training to complete)\n",
    "workspace = assistant.get_workspace(workspace_id=workspace_id).get_result()\n",
    "print('The workspace status is: {0}'.format(workspace['status']))\n",
    "if workspace['status'] == 'Available':\n",
    "    print('Ready to chat!')\n",
    "else:\n",
    "    print('The workspace should be available shortly. Please try again in 30s.')\n",
    "    print('(You can send messages, but not all functionality will be supported yet.)')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"entities\": [], \n",
      "  \"intents\": [\n",
      "    {\n",
      "      \"confidence\": 1, \n",
      "      \"intent\": \"order_pizza\"\n",
      "    }\n",
      "  ], \n",
      "  \"output\": {\n",
      "    \"generic\": [\n",
      "      {\n",
      "        \"text\": \"Of course!\", \n",
      "        \"response_type\": \"text\"\n",
      "      }\n",
      "    ], \n",
      "    \"text\": [\n",
      "      \"Of course!\"\n",
      "    ], \n",
      "    \"log_messages\": [], \n",
      "    \"nodes_visited\": [\n",
      "      \"YesYouCan\"\n",
      "    ]\n",
      "  }, \n",
      "  \"context\": {\n",
      "    \"conversation_id\": \"f673c936-c8e6-41d1-9bae-771ef92e2f3d\", \n",
      "    \"system\": {\n",
      "      \"dialog_stack\": [\n",
      "        {\n",
      "          \"dialog_node\": \"root\"\n",
      "        }\n",
      "      ], \n",
      "      \"dialog_request_counter\": 1, \n",
      "      \"dialog_turn_counter\": 1, \n",
      "      \"branch_exited\": true, \n",
      "      \"initialized\": true, \n",
      "      \"_node_output_map\": {\n",
      "        \"YesYouCan\": [\n",
      "          0, \n",
      "          1, \n",
      "          0\n",
      "        ]\n",
      "      }, \n",
      "      \"branch_exited_reason\": \"completed\"\n",
      "    }\n",
      "  }, \n",
      "  \"input\": {\n",
      "    \"text\": \"Can I order a pizza?\"\n",
      "  }\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "# start a chat with the pizza bot\n",
    "input = {'text': 'Can I order a pizza?'}\n",
    "response = assistant.message(workspace_id=workspace_id,\n",
    "                                input=input).get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"entities\": [], \n",
      "  \"intents\": [], \n",
      "  \"output\": {\n",
      "    \"generic\": [], \n",
      "    \"text\": [], \n",
      "    \"warning\": \"No dialog node condition matched to true in the last dialog round - context.nodes_visited is empty. Falling back to the root node in the next round.\", \n",
      "    \"log_messages\": [\n",
      "      {\n",
      "        \"msg\": \"No dialog node condition matched to true in the last dialog round - context.nodes_visited is empty. Falling back to the root node in the next round.\", \n",
      "        \"level\": \"warn\"\n",
      "      }\n",
      "    ], \n",
      "    \"nodes_visited\": []\n",
      "  }, \n",
      "  \"context\": {\n",
      "    \"conversation_id\": \"f673c936-c8e6-41d1-9bae-771ef92e2f3d\", \n",
      "    \"system\": {\n",
      "      \"dialog_stack\": [\n",
      "        {\n",
      "          \"dialog_node\": \"root\"\n",
      "        }\n",
      "      ], \n",
      "      \"dialog_request_counter\": 2, \n",
      "      \"dialog_turn_counter\": 2, \n",
      "      \"branch_exited\": true, \n",
      "      \"initialized\": true, \n",
      "      \"_node_output_map\": {\n",
      "        \"YesYouCan\": [\n",
      "          0, \n",
      "          1, \n",
      "          0\n",
      "        ]\n",
      "      }, \n",
      "      \"branch_exited_reason\": \"fallback\"\n",
      "    }\n",
      "  }, \n",
      "  \"input\": {\n",
      "    \"text\": \"medium\"\n",
      "  }\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "# continue a chat with the pizza bot\n",
    "# (when you send multiple requests for the same conversation,\n",
    "#  then include the context object from the previous response)\n",
    "input = {'text': 'medium'}\n",
    "response = assistant.message(workspace_id=workspace_id,\n",
    "                             input=input,\n",
    "                             context=response['context']).get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Operation Examples"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The following examples demonstrate each operation of the Assistant service. They use the pizza chatbot workspace configured above."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Message"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"entities\": [], \n",
      "  \"intents\": [\n",
      "    {\n",
      "      \"confidence\": 1, \n",
      "      \"intent\": \"order_pizza\"\n",
      "    }\n",
      "  ], \n",
      "  \"output\": {\n",
      "    \"generic\": [\n",
      "      {\n",
      "        \"text\": \"Of course!\", \n",
      "        \"response_type\": \"text\"\n",
      "      }\n",
      "    ], \n",
      "    \"text\": [\n",
      "      \"Of course!\"\n",
      "    ], \n",
      "    \"log_messages\": [], \n",
      "    \"nodes_visited\": [\n",
      "      \"YesYouCan\"\n",
      "    ]\n",
      "  }, \n",
      "  \"context\": {\n",
      "    \"conversation_id\": \"f354f7ca-0996-47e6-b0aa-cc85f877eab1\", \n",
      "    \"system\": {\n",
      "      \"dialog_stack\": [\n",
      "        {\n",
      "          \"dialog_node\": \"root\"\n",
      "        }\n",
      "      ], \n",
      "      \"dialog_request_counter\": 1, \n",
      "      \"dialog_turn_counter\": 1, \n",
      "      \"branch_exited\": true, \n",
      "      \"initialized\": true, \n",
      "      \"_node_output_map\": {\n",
      "        \"YesYouCan\": [\n",
      "          0, \n",
      "          1, \n",
      "          0\n",
      "        ]\n",
      "      }, \n",
      "      \"branch_exited_reason\": \"completed\"\n",
      "    }\n",
      "  }, \n",
      "  \"input\": {\n",
      "    \"text\": \"Can I order a pizza?\"\n",
      "  }\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "input = {'text': 'Can I order a pizza?'}\n",
    "response = assistant.message(workspace_id=workspace_id,\n",
    "                                input=input).get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Workspaces"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"learning_opt_out\": false, \n",
      "  \"workspace_id\": \"a98ceedd-1d76-4e55-86f2-0fdbf79233d4\", \n",
      "  \"language\": \"en\", \n",
      "  \"name\": \"test_workspace\", \n",
      "  \"metadata\": {\n",
      "    \"api_version\": {\n",
      "      \"major_version\": \"v1\", \n",
      "      \"minor_version\": \"2018-07-10\"\n",
      "    }\n",
      "  }, \n",
      "  \"description\": \"Test workspace.\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.create_workspace(name='test_workspace',\n",
    "                                         description='Test workspace.',\n",
    "                                         language='en',\n",
    "                                         metadata={}).get_result()\n",
    "print(json.dumps(response, indent=2))\n",
    "test_workspace_id = response['workspace_id']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.delete_workspace(workspace_id=test_workspace_id).get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"status\": \"Available\", \n",
      "  \"learning_opt_out\": false, \n",
      "  \"intents\": [\n",
      "    {\n",
      "      \"intent\": \"order_pizza\", \n",
      "      \"examples\": [\n",
      "        {\n",
      "          \"text\": \"Can I order a pizza?\"\n",
      "        }, \n",
      "        {\n",
      "          \"text\": \"I want to order a pizza.\"\n",
      "        }, \n",
      "        {\n",
      "          \"text\": \"pizza order\"\n",
      "        }, \n",
      "        {\n",
      "          \"text\": \"pizza to go\"\n",
      "        }\n",
      "      ], \n",
      "      \"description\": \"A pizza order.\"\n",
      "    }\n",
      "  ], \n",
      "  \"description\": \"An example workspace.\", \n",
      "  \"language\": \"en\", \n",
      "  \"dialog_nodes\": [\n",
      "    {\n",
      "      \"output\": {\n",
      "        \"text\": {\n",
      "          \"values\": [\n",
      "            \"Yes You can!\", \n",
      "            \"Of course!\"\n",
      "          ], \n",
      "          \"selection_policy\": \"random\"\n",
      "        }\n",
      "      }, \n",
      "      \"conditions\": \"#order_pizza\", \n",
      "      \"type\": \"standard\", \n",
      "      \"dialog_node\": \"YesYouCan\", \n",
      "      \"title\": \"YesYouCan\"\n",
      "    }\n",
      "  ], \n",
      "  \"workspace_id\": \"8db6b689-c4a7-4bb0-a2a7-86e58587f8f9\", \n",
      "  \"entities\": [], \n",
      "  \"counterexamples\": [], \n",
      "  \"metadata\": {\n",
      "    \"api_version\": {\n",
      "      \"major_version\": \"v1\", \n",
      "      \"minor_version\": \"2018-07-10\"\n",
      "    }\n",
      "  }, \n",
      "  \"name\": \"example_workspace\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.get_workspace(workspace_id=workspace_id, export=True).get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"pagination\": {\n",
      "    \"refresh_url\": \"/v1/workspaces?version=2018-07-10\"\n",
      "  }, \n",
      "  \"workspaces\": [\n",
      "    {\n",
      "      \"learning_opt_out\": false, \n",
      "      \"workspace_id\": \"8db6b689-c4a7-4bb0-a2a7-86e58587f8f9\", \n",
      "      \"language\": \"en\", \n",
      "      \"name\": \"example_workspace\", \n",
      "      \"metadata\": {\n",
      "        \"api_version\": {\n",
      "          \"major_version\": \"v1\", \n",
      "          \"minor_version\": \"2018-07-10\"\n",
      "        }\n",
      "      }, \n",
      "      \"description\": \"An example workspace.\"\n",
      "    }\n",
      "  ]\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.list_workspaces().get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"learning_opt_out\": false, \n",
      "  \"workspace_id\": \"8db6b689-c4a7-4bb0-a2a7-86e58587f8f9\", \n",
      "  \"language\": \"en\", \n",
      "  \"name\": \"example_workspace\", \n",
      "  \"metadata\": {\n",
      "    \"api_version\": {\n",
      "      \"major_version\": \"v1\", \n",
      "      \"minor_version\": \"2018-07-10\"\n",
      "    }\n",
      "  }, \n",
      "  \"description\": \"An example workspace for ordering pizza.\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.update_workspace(workspace_id=workspace_id,\n",
    "                                         description='An example workspace for ordering pizza.').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Intents"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"intent\": \"test_intent\", \n",
      "  \"description\": \"Test intent.\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.create_intent(workspace_id=workspace_id,\n",
    "                                      intent='test_intent',\n",
    "                                      description='Test intent.').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.delete_intent(workspace_id=workspace_id,\n",
    "                                      intent='test_intent').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"intent\": \"order_pizza\", \n",
      "  \"examples\": [\n",
      "    {\n",
      "      \"text\": \"Can I order a pizza?\"\n",
      "    }, \n",
      "    {\n",
      "      \"text\": \"I want to order a pizza.\"\n",
      "    }, \n",
      "    {\n",
      "      \"text\": \"pizza order\"\n",
      "    }, \n",
      "    {\n",
      "      \"text\": \"pizza to go\"\n",
      "    }\n",
      "  ], \n",
      "  \"description\": \"A pizza order.\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.get_intent(workspace_id=workspace_id,\n",
    "                                   intent='order_pizza',\n",
    "                                   export=True).get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"intents\": [\n",
      "    {\n",
      "      \"intent\": \"order_pizza\", \n",
      "      \"examples\": [\n",
      "        {\n",
      "          \"text\": \"Can I order a pizza?\"\n",
      "        }, \n",
      "        {\n",
      "          \"text\": \"I want to order a pizza.\"\n",
      "        }, \n",
      "        {\n",
      "          \"text\": \"pizza order\"\n",
      "        }, \n",
      "        {\n",
      "          \"text\": \"pizza to go\"\n",
      "        }\n",
      "      ], \n",
      "      \"description\": \"A pizza order.\"\n",
      "    }\n",
      "  ], \n",
      "  \"pagination\": {\n",
      "    \"refresh_url\": \"/v1/workspaces/8db6b689-c4a7-4bb0-a2a7-86e58587f8f9/intents?version=2018-07-10&export=true\"\n",
      "  }\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.list_intents(workspace_id=workspace_id,\n",
    "                                     export=True).get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"intent\": \"order_pizza\", \n",
      "  \"description\": \"Order a pizza.\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.update_intent(workspace_id=workspace_id,\n",
    "                                      intent='order_pizza',\n",
    "                                      new_intent='order_pizza',\n",
    "                                      new_description='Order a pizza.').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Examples"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"text\": \"Gimme a pizza with pepperoni\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.create_example(workspace_id=workspace_id,\n",
    "                                       intent='order_pizza',\n",
    "                                       text='Gimme a pizza with pepperoni').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.delete_example(workspace_id=workspace_id,\n",
    "                                       intent='order_pizza',\n",
    "                                       text='Gimme a pizza with pepperoni').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"text\": \"I want to order a pizza.\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.get_example(workspace_id=workspace_id,\n",
    "                                    intent='order_pizza',\n",
    "                                    text='I want to order a pizza.').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"pagination\": {\n",
      "    \"refresh_url\": \"/v1/workspaces/8db6b689-c4a7-4bb0-a2a7-86e58587f8f9/intents/order_pizza/examples?version=2018-07-10\"\n",
      "  }, \n",
      "  \"examples\": [\n",
      "    {\n",
      "      \"text\": \"Can I order a pizza?\"\n",
      "    }, \n",
      "    {\n",
      "      \"text\": \"I want to order a pizza.\"\n",
      "    }, \n",
      "    {\n",
      "      \"text\": \"pizza order\"\n",
      "    }, \n",
      "    {\n",
      "      \"text\": \"pizza to go\"\n",
      "    }\n",
      "  ]\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.list_examples(workspace_id=workspace_id,\n",
    "                                      intent='order_pizza').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"text\": \"I want to order a pizza with pepperoni.\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.update_example(workspace_id=workspace_id,\n",
    "                                       intent='order_pizza',\n",
    "                                       text='I want to order a pizza.',\n",
    "                                       new_text='I want to order a pizza with pepperoni.').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Counterexamples"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"text\": \"I want financial advice today.\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.create_counterexample(workspace_id=workspace_id,\n",
    "                                              text='I want financial advice today.').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"text\": \"I want financial advice today.\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.get_counterexample(workspace_id=workspace_id,\n",
    "                                           text='I want financial advice today.').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"pagination\": {\n",
      "    \"refresh_url\": \"/v1/workspaces/8db6b689-c4a7-4bb0-a2a7-86e58587f8f9/counterexamples?version=2018-07-10\"\n",
      "  }, \n",
      "  \"counterexamples\": [\n",
      "    {\n",
      "      \"text\": \"I want financial advice today.\"\n",
      "    }\n",
      "  ]\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.list_counterexamples(workspace_id=workspace_id).get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"text\": \"I want financial advice for tomorrow.\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.update_counterexample(workspace_id=workspace_id,\n",
    "                                              text='I want financial advice today.',\n",
    "                                              new_text='I want financial advice for tomorrow.').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.delete_counterexample(workspace_id=workspace_id,\n",
    "                                              text='I want financial advice for tomorrow.').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Entities"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "values = [{\"value\": \"juice\"}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"description\": \"A test entity.\", \n",
      "  \"entity\": \"test_entity\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.create_entity(workspace_id=workspace_id,\n",
    "                                      entity='test_entity',\n",
    "                                      description='A test entity.',\n",
    "                                      values=values).get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"values\": [\n",
      "    {\n",
      "      \"synonyms\": [], \n",
      "      \"type\": \"synonyms\", \n",
      "      \"value\": \"juice\"\n",
      "    }\n",
      "  ], \n",
      "  \"description\": \"A test entity.\", \n",
      "  \"entity\": \"test_entity\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.get_entity(workspace_id=workspace_id,\n",
    "                                   entity='test_entity',\n",
    "                                   export=True).get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"entities\": [\n",
      "    {\n",
      "      \"description\": \"A test entity.\", \n",
      "      \"entity\": \"test_entity\"\n",
      "    }\n",
      "  ], \n",
      "  \"pagination\": {\n",
      "    \"refresh_url\": \"/v1/workspaces/8db6b689-c4a7-4bb0-a2a7-86e58587f8f9/entities?version=2018-07-10\"\n",
      "  }\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.list_entities(workspace_id=workspace_id).get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"description\": \"An updated test entity.\", \n",
      "  \"entity\": \"test_entity\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.update_entity(workspace_id=workspace_id,\n",
    "                                      entity='test_entity',\n",
    "                                      new_description='An updated test entity.').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.delete_entity(workspace_id=workspace_id,\n",
    "                                      entity='test_entity').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Synonyms"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{u'entity': u'beverage'}"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "values = [{\"value\": \"orange juice\"}]\n",
    "assistant.create_entity(workspace_id, 'beverage', values=values).get_result()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"synonym\": \"oj\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.create_synonym(workspace_id, 'beverage', 'orange juice', 'oj').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"synonym\": \"oj\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.get_synonym(workspace_id, 'beverage', 'orange juice', 'oj').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"synonyms\": [\n",
      "    {\n",
      "      \"synonym\": \"oj\"\n",
      "    }\n",
      "  ], \n",
      "  \"pagination\": {\n",
      "    \"refresh_url\": \"/v1/workspaces/8db6b689-c4a7-4bb0-a2a7-86e58587f8f9/entities/beverage/values/orange%20juice/synonyms?version=2018-07-10\"\n",
      "  }\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.list_synonyms(workspace_id, 'beverage', 'orange juice').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"synonym\": \"OJ\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.update_synonym(workspace_id, 'beverage', 'orange juice', 'oj', 'OJ').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.delete_synonym(workspace_id, 'beverage', 'orange juice', 'OJ').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{}"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "assistant.delete_entity(workspace_id, 'beverage').get_result()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{u'entity': u'test_entity'}"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "assistant.create_entity(workspace_id, 'test_entity').get_result()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"type\": \"synonyms\", \n",
      "  \"value\": \"test\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.create_value(workspace_id, 'test_entity', 'test').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"type\": \"synonyms\", \n",
      "  \"value\": \"test\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.get_value(workspace_id, 'test_entity', 'test').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"pagination\": {\n",
      "    \"refresh_url\": \"/v1/workspaces/8db6b689-c4a7-4bb0-a2a7-86e58587f8f9/entities/test_entity/values?version=2018-07-10\"\n",
      "  }, \n",
      "  \"values\": [\n",
      "    {\n",
      "      \"type\": \"synonyms\", \n",
      "      \"value\": \"test\"\n",
      "    }\n",
      "  ]\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.list_values(workspace_id, 'test_entity').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"type\": \"synonyms\", \n",
      "  \"value\": \"example\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.update_value(workspace_id, 'test_entity', 'test', 'example').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.delete_value(workspace_id, 'test_entity', 'example').get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{}"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "assistant.delete_entity(workspace_id, 'test_entity').get_result()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Logs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"pagination\": {}, \n",
      "  \"logs\": [\n",
      "    {\n",
      "      \"workspace_id\": \"8db6b689-c4a7-4bb0-a2a7-86e58587f8f9\", \n",
      "      \"language\": \"en\", \n",
      "      \"request_timestamp\": \"2019-03-18T18:45:04.031Z\", \n",
      "      \"log_id\": \"c5619c32-28bc-4518-b7af-ae5ea6297aac\", \n",
      "      \"request\": {\n",
      "        \"input\": {\n",
      "          \"text\": \"Can I order a pizza?\"\n",
      "        }\n",
      "      }, \n",
      "      \"response_timestamp\": \"2019-03-18T18:45:04.051Z\", \n",
      "      \"response\": {\n",
      "        \"entities\": [], \n",
      "        \"intents\": [\n",
      "          {\n",
      "            \"confidence\": 1, \n",
      "            \"intent\": \"order_pizza\"\n",
      "          }\n",
      "        ], \n",
      "        \"output\": {\n",
      "          \"generic\": [\n",
      "            {\n",
      "              \"text\": \"Of course!\", \n",
      "              \"response_type\": \"text\"\n",
      "            }\n",
      "          ], \n",
      "          \"text\": [\n",
      "            \"Of course!\"\n",
      "          ], \n",
      "          \"log_messages\": [], \n",
      "          \"nodes_visited\": [\n",
      "            \"YesYouCan\"\n",
      "          ]\n",
      "        }, \n",
      "        \"context\": {\n",
      "          \"conversation_id\": \"f673c936-c8e6-41d1-9bae-771ef92e2f3d\", \n",
      "          \"system\": {\n",
      "            \"dialog_stack\": [\n",
      "              {\n",
      "                \"dialog_node\": \"root\"\n",
      "              }\n",
      "            ], \n",
      "            \"dialog_request_counter\": 1, \n",
      "            \"dialog_turn_counter\": 1, \n",
      "            \"branch_exited\": true, \n",
      "            \"initialized\": true, \n",
      "            \"_node_output_map\": {\n",
      "              \"YesYouCan\": [\n",
      "                0, \n",
      "                1, \n",
      "                0\n",
      "              ]\n",
      "            }, \n",
      "            \"branch_exited_reason\": \"completed\"\n",
      "          }\n",
      "        }, \n",
      "        \"input\": {\n",
      "          \"text\": \"Can I order a pizza?\"\n",
      "        }\n",
      "      }\n",
      "    }, \n",
      "    {\n",
      "      \"workspace_id\": \"8db6b689-c4a7-4bb0-a2a7-86e58587f8f9\", \n",
      "      \"language\": \"en\", \n",
      "      \"request_timestamp\": \"2019-03-18T18:45:07.020Z\", \n",
      "      \"log_id\": \"5d90f82e-95e2-4281-87ab-36b1c53a4346\", \n",
      "      \"request\": {\n",
      "        \"input\": {\n",
      "          \"text\": \"medium\"\n",
      "        }, \n",
      "        \"context\": {\n",
      "          \"conversation_id\": \"f673c936-c8e6-41d1-9bae-771ef92e2f3d\", \n",
      "          \"system\": {\n",
      "            \"dialog_stack\": [\n",
      "              {\n",
      "                \"dialog_node_s\": \"root\"\n",
      "              }\n",
      "            ], \n",
      "            \"_node_output_map_s\": \"{\\\"YesYouCan\\\":[0,1,0]}\", \n",
      "            \"initialized_s\": \"true\", \n",
      "            \"dialog_request_counter\": 1, \n",
      "            \"dialog_turn_counter\": 1, \n",
      "            \"branch_exited_reason_s\": \"completed\", \n",
      "            \"branch_exited_s\": \"true\"\n",
      "          }\n",
      "        }\n",
      "      }, \n",
      "      \"response_timestamp\": \"2019-03-18T18:45:07.067Z\", \n",
      "      \"response\": {\n",
      "        \"entities\": [], \n",
      "        \"intents\": [], \n",
      "        \"output\": {\n",
      "          \"generic\": [], \n",
      "          \"text\": [], \n",
      "          \"warning\": \"No dialog node condition matched to true in the last dialog round - context.nodes_visited is empty. Falling back to the root node in the next round.\", \n",
      "          \"log_messages\": [\n",
      "            {\n",
      "              \"msg\": \"No dialog node condition matched to true in the last dialog round - context.nodes_visited is empty. Falling back to the root node in the next round.\", \n",
      "              \"level\": \"warn\"\n",
      "            }\n",
      "          ], \n",
      "          \"nodes_visited\": []\n",
      "        }, \n",
      "        \"context\": {\n",
      "          \"conversation_id\": \"f673c936-c8e6-41d1-9bae-771ef92e2f3d\", \n",
      "          \"system\": {\n",
      "            \"dialog_stack\": [\n",
      "              {\n",
      "                \"dialog_node\": \"root\"\n",
      "              }\n",
      "            ], \n",
      "            \"dialog_request_counter\": 2, \n",
      "            \"dialog_turn_counter\": 2, \n",
      "            \"branch_exited\": true, \n",
      "            \"initialized\": true, \n",
      "            \"_node_output_map\": {\n",
      "              \"YesYouCan\": [\n",
      "                0, \n",
      "                1, \n",
      "                0\n",
      "              ]\n",
      "            }, \n",
      "            \"branch_exited_reason\": \"fallback\"\n",
      "          }\n",
      "        }, \n",
      "        \"input\": {\n",
      "          \"text\": \"medium\"\n",
      "        }\n",
      "      }\n",
      "    }, \n",
      "    {\n",
      "      \"workspace_id\": \"8db6b689-c4a7-4bb0-a2a7-86e58587f8f9\", \n",
      "      \"language\": \"en\", \n",
      "      \"request_timestamp\": \"2019-03-18T18:44:13.669Z\", \n",
      "      \"log_id\": \"5c27b4ce-3e27-482c-8dc7-7012ce7104bd\", \n",
      "      \"request\": {\n",
      "        \"input\": {\n",
      "          \"text\": \"Can I order a pizza?\"\n",
      "        }\n",
      "      }, \n",
      "      \"response_timestamp\": \"2019-03-18T18:44:13.703Z\", \n",
      "      \"response\": {\n",
      "        \"entities\": [], \n",
      "        \"intents\": [], \n",
      "        \"output\": {\n",
      "          \"generic\": [], \n",
      "          \"text\": [], \n",
      "          \"warning\": \"No dialog node condition matched to true in the last dialog round - context.nodes_visited is empty. Falling back to the root node in the next round.\", \n",
      "          \"log_messages\": [\n",
      "            {\n",
      "              \"msg\": \"No dialog node condition matched to true in the last dialog round - context.nodes_visited is empty. Falling back to the root node in the next round.\", \n",
      "              \"level\": \"warn\"\n",
      "            }\n",
      "          ], \n",
      "          \"nodes_visited\": []\n",
      "        }, \n",
      "        \"context\": {\n",
      "          \"conversation_id\": \"d35c41de-b025-4cad-959a-b247b77d72fd\", \n",
      "          \"system\": {\n",
      "            \"dialog_turn_counter\": 1, \n",
      "            \"initialized\": true, \n",
      "            \"dialog_request_counter\": 1, \n",
      "            \"dialog_stack\": [\n",
      "              {\n",
      "                \"dialog_node\": \"root\"\n",
      "              }\n",
      "            ]\n",
      "          }\n",
      "        }, \n",
      "        \"input\": {\n",
      "          \"text\": \"Can I order a pizza?\"\n",
      "        }\n",
      "      }\n",
      "    }, \n",
      "    {\n",
      "      \"workspace_id\": \"8db6b689-c4a7-4bb0-a2a7-86e58587f8f9\", \n",
      "      \"language\": \"en\", \n",
      "      \"request_timestamp\": \"2019-03-18T18:45:11.036Z\", \n",
      "      \"log_id\": \"9bf03fa8-1c93-4dbf-9f29-d49b04520a69\", \n",
      "      \"request\": {\n",
      "        \"input\": {\n",
      "          \"text\": \"Can I order a pizza?\"\n",
      "        }\n",
      "      }, \n",
      "      \"response_timestamp\": \"2019-03-18T18:45:11.126Z\", \n",
      "      \"response\": {\n",
      "        \"entities\": [], \n",
      "        \"intents\": [\n",
      "          {\n",
      "            \"confidence\": 1, \n",
      "            \"intent\": \"order_pizza\"\n",
      "          }\n",
      "        ], \n",
      "        \"output\": {\n",
      "          \"generic\": [\n",
      "            {\n",
      "              \"text\": \"Of course!\", \n",
      "              \"response_type\": \"text\"\n",
      "            }\n",
      "          ], \n",
      "          \"text\": [\n",
      "            \"Of course!\"\n",
      "          ], \n",
      "          \"log_messages\": [], \n",
      "          \"nodes_visited\": [\n",
      "            \"YesYouCan\"\n",
      "          ]\n",
      "        }, \n",
      "        \"context\": {\n",
      "          \"conversation_id\": \"f354f7ca-0996-47e6-b0aa-cc85f877eab1\", \n",
      "          \"system\": {\n",
      "            \"dialog_stack\": [\n",
      "              {\n",
      "                \"dialog_node\": \"root\"\n",
      "              }\n",
      "            ], \n",
      "            \"dialog_request_counter\": 1, \n",
      "            \"dialog_turn_counter\": 1, \n",
      "            \"branch_exited\": true, \n",
      "            \"initialized\": true, \n",
      "            \"_node_output_map\": {\n",
      "              \"YesYouCan\": [\n",
      "                0, \n",
      "                1, \n",
      "                0\n",
      "              ]\n",
      "            }, \n",
      "            \"branch_exited_reason\": \"completed\"\n",
      "          }\n",
      "        }, \n",
      "        \"input\": {\n",
      "          \"text\": \"Can I order a pizza?\"\n",
      "        }\n",
      "      }\n",
      "    }\n",
      "  ]\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "response = assistant.list_logs(workspace_id=workspace_id).get_result()\n",
    "print(json.dumps(response, indent=2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Cleanup (Delete Pizza Chatbot)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's cleanup by deleting the pizza chatbot, since it is no longer needed."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{}"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# clean-up by deleting the workspace\n",
    "assistant.delete_workspace(workspace_id=workspace_id).get_result()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
