Below is the architecture overview of workshop 2, the Watson Conversation Service (WCS). This architecture is consistent with the reference implementations of WCS for cloud native applications using microservices.
Workshop 2 is intended to help you understand the basics of the Watson Conversation Service (WCS) as part of the Watson API's. WCS is a question and answer system that focuses on providing a dialog type of experience between the user and the conversation system. This style of interaction is commonly called a bot. The intent of this lab is to take the base work model from workshop 1 and extend the lab to leverage the WCS capabilities. We will enable through a dialog approach WCS interacting with the data from the IoT device, asking questions specific to the data that is captured. The lab will also allow for commands to be sent to the IoT device, directed from the response of the WCS dialog flow. Though the example is simple, it will provide you with a solid understanding of the core pieces of WCS.
WCS has a couple of terms that need to be understood. This will allow for an easier time with creating an application (i.e. Dialog) in WCS
Intent: An intent is the intention of the command or question given by the user to WCS. It is common to think of intents as the verbs or actions that need to occur. An Example of an Intent is "Tell me the temperature" or "I want to know the current temperature". In both cases, though the sentences are different they both as asking WCS for temperature information. It should be noted that WCS can only support a single Intent per interaction with WCS. So asking questions with multiple intents will produce unreliable ordering of answers to the question.
Entities: An entity is the object that intents use to help narrow the scope of the request. It is common to think of entities as nouns or objects. The nice thing about entities, compared to intents, is that you can have multiple entities per interaction. This is very helpful when trying to narrow down the answers to a question.
Dialog: The conversation that is created within WCS, is called a dialog. A dialog is composed of creating a flow between intents and entities. The combination of flows and subFlows allows WCS to provide mult-layered conversation based on multiple interactions, instead of a single question and answer.
Below are the steps for workshop 2
- Create a Watson Conversation Service instance
- Logon to BlueMix and go to your dashboard.
- Click on the catalog button at the top navigation on the right
- Select "Watson" on the left navigation under the Services menu
- Click on "Conversation"
- In the service name type STSA-WK2-WCS-xxx (where xxx is your team number). You can leave credential name as is if you like
- Click on the create in the lower right corner. You should now see the following
- You will need cut and paste your service credentials. Click on "Service Credentials" on the left navigation, right under "Manage". Once the page has loaded, click on "View Credentials" on the right side of the screen. A drop down will show with your specific credentials Your values for username and password will be different than shown.
- Click the copy icon to copy the values to your clipboard. Paste the values in a text file for later use.
- Go back to the manage page, by clicking on the manage link on the left side navigation. This will take you back to the manage page.
You have now completed the first step in creating the WCS service instance.
-
Launch WCS tooling
-
Click on the "Launch tool" icon to take you to the WCS workspace
-
This will open another browser window and you should now be on the Watson Conversation Workspace page
-
You are going to create a new workspace. Click on the "Create a new workspace" tile.
-
Enter a workspace name i.e. STSA-WK2-xxx (where xxx is your team number).
-
You are now ready to create some Intents. Click on the Intents link. You should now see the following: Click the "Create New" button in the middle of the page. You should now see the following:
- Add a new Intent name of Information. You then need to provide some examples. Copy the samples provided and look at the image below.
What is the temperature Can you explain What is a I need information about What is the current temperature I need some information on the temperature Can you tell me the temperature I need to know the temperature
It should look like the following: Click Done in the upper right corner when finished.
- Add another intent, by clicking "Create new" button. Use the new Intent name of Greeting. Copy the samples and look at the image below.
good evening Hello Hi Howdy Good morning Good afternoon Yo Yo Yo Sup dude
- Add another intent GoodBye. Add the following examples also.
good-bye see you later talk to you later goodbye later
- Add one last intent ChangeColor with the following examples:
I need to change the color of the sensor Please change the sensor color Change the color of the sensor make the sensors color green change the sensor color to green
You have now finished creating all of the intents. (Nice Job!)
-
Next we want to create some Entities. Click on the "Entities" link at the top of the page. Click the "Create New" button.
- Type "Temperature" as the new Entity name. Now notice, you need to add examples of new "Temperature" entities. So add "Current Temperature" as a new entity but also you need to provide some synonyms to help identify variations of the entity value. Now add "Temperature now" and "Current Temp" as synonyms. You now need to add "Average Temperature" and "Temperature" with the corresponding synonyms, as shown in the image above. After you are finished with each set of synonyms click the Plus icon to add them.
Current temperature current temp temperature now Average temperature avg temp avg temperature Temperature Temp
Click Done when finished.
- Create another entity called "degree" also add the associated synonyms.
Celsius celcius degrees in c degrees C Fahrenheit Degrees F degrees in f
- Add one last entity called Colors and the associated values.
Yellow Blue White Green Red Black off
Great you now completed the adding of Entities. (Well done!).
-
We are now ready to create a dialog. Click on the Dialog link at the top of the page. Click the "Create" button to start to create a dialog. You should now see the following:
What you see are two "Dialog Nodes". The first is the standard "Welcome" message and the other is a catch-all "Anything else" . Remember the way a conversation dialog works is by scanning from the top of the tree and evaluating every node until a condition is met that satisfies the question being asked. So when the conversation starts WCS will respond with the "Welcome" Node. If you click on the "Welcome" node you will see that the standard Watson response is "Hello. How can I help you?"
-
We now want to create our own node, based on the "Intents" we create earlier. To add a new node in the tree, click on the "Welcome" node, and then click on the "Add Node" icon. You should now see the following:
- We are going to add some very simple nodes. Type Greeting as the name of the node. The trigger should be "#Greeting". The Response condition should be set to "True" and you can provide any response text you like. It should look similar to the following:
- Again create another root node by clicking on the "Greeting" node and then clicking "Add node". This will add another node. This nodes values are as follows:
- Create a new node under the "Goodbye" node, called Color Change with the following information:
In this node, your response needs to have a condition set, prior to responding. This is done by clicking on the Add response condidtion link.
Take special note of the extra information in the first response. Make sure to copy it properly.
I just changed the color to <? entities.Colors.literal ?>
This is an expression langage snippet of code. If you look at the information in the node, the intent is to change color and the first condition for a response is "@Colors", which signals to Watson, if a known color is provided in the user's input then use that color in the response.
Now click on the Add another response to add another condition. Make the second resposes response condition True. If an unknown color is typed (i.e. Violet) in the user's input the processing will hit the "True" condition. This is because "Violet" is not in our "@Color" entity definition.-
Create a node under "Color Change" called WhatElse, with the following information:
-
We are now on the last node we are going to create. Insert this node between the "Goodbye" and "Color Change" node. This is done by clicking on the goodbye node and then clicking the "Add Node".
-
Enter "Information" as the name of the node. In the "If bot recognizes" type the word "Information" you will see a type ahead pop up. Select the "#Information" entry. Do not provide any responses.
-
Click the large green X at the top to close the dialog editor.
-
Now you want to create a sub-dialog. This time make sure the "Information" node is selected and then click on the "Add child node" button.
-
Enter "Temperature" as the name of the node.
-
In the "If bot recognizes" field enter "@Temperature:(Current Temperature)". This is the entity defined earlier.
-
In the Response section, for the first response, add a response condition. Type "@degree:Celsius" in the response condition field. Then add the Watson response of "The current temperature in celsius is"
-
Add another response condition of "@degree:Fahrenheit" with the response message of "The current temperature in fahrenheit is".
-
Add one last response condition of "True". this is a catch all condition for this node. Add the Watson response as "The current temperature in fahrenheit is" The reason for this last response to have a response in the event Watson knows you are looking for information about the temperature, but isn't sure if you mean in celsius or fahrenheit. Your completed node should look the like the following: Close the node editor, we have one last sub-node to create.
-
Under the "Temperature" node, create a new node. The is done by clicking on the "Temperature" node and then clicking on Add node button.
Call it Unknown Add the information like below:
- The next step is to go back to the "Information" node, by clicking on the node itself. Next click on the Three green buttons This will open a small menu like the following:
Click on the Jump to menu item and then click on the Temperature node. You should now see the following:
Click on the If Bot recognized condition menu item. You screen should now look like the following:
-
Next we want to select the three circles on the "Temperature" node. Like with the "Information" node, select the Jump to menu item. Then select the "WhatElse" node. This time select the "Respond" option. The sub-flow should now look like the following:
-
Next we want to select the three circles on the "Color Change" node. Like with the "Temperature" node, select the Jump to menu item. Then select the "WhatElse" node. This time select the "Respond" option. The sub-flow should now look like the following:
-
Go back to the "Information" node and click on it to open the node editor. Click the three bubbles in the upper right on the Temperature node by the responses Then click on the Open JSON Editor menu item.
- We are going to add a single line of code to the JSON. The purpose of this code, is to send a signal to the NodeRed application that some special processing needs to occur. So for the JSON response to the degree:Celsius entity we need to have a new attribute on the JSON object. Type "action": "CurrentTempCelsius" make sure you put the "comma" right after the curly bracket, but before the new code you just added.
- You now need to do the same thing for the each of the other responses on the temperature node. For the degree:Fahrenheit response add "action": "CurrentTempFahrenheit"
- Now do it for the True condition as well. We will have the default response be in fahrenheit so add "action": "CurrentTempFahrenheit"
-
The last step is to update the ChangeColor dialog node, with a similar action command. but this time set the command value to "action":"changeColor" We are now finished with the entire Dialog. Congratulations. We will be coming back here to make a couple of minor updates. Now is time to test your code.
What might become obvious is that the responses from WCS are static. There is nothing personalized in the responses. Because of this we need to add a layer in front of WCS to take the responses and make them personalized. We are going to use NodeRed, like we did for the IoT lab. Below are the steps needed for adding a new flow to your existing BlueMix NodeRed application.
-
Open your browser and go to the BlubMix NodeRed URL. It should be something like STSAWorkshops-xx.mybluemix.net. You can also get to it from your BlueMix Dashboard.
-
You should now see something like the following, which is your flow for IoT
-
Go to the following URL https://github.com/jdcalus/STSA-Workshop-2-WCS You should see something similar to the following:
-
Click on the wk2-wcs-flow.json link. This will take you to the NodeRed flow json file which has a predeveloped flow for talking to WCS. You should now see:
-
Highlight all of the json text and copy it to your clipboard. (ctrl+c on your keyboard).
-
Go back to your NodeRed editor and in the upper right corner is the cake layer icon, click on it. Then click import and then click clipboard
-
You should now see the following dialog window: click in the center of the dialog and paste the information from your clipboard. (ctrl+v). Make sure the new flow button is pressed before you import. Your screen should now look something like the following, which a new tab called WCS Flow
-
Now we need to update a couple of the nodes, with information that was provided earlier in IoT Workshop.
- Make sure you have the credentials information from your DashDB service. This can be access from your BlueMix dashboard, by clicking on the service: You should see the manage page for that instance of the dashDB service Now click on the Service Credentials link on the left side. Once the page loads, there is an option for View Credentials. You will need to copy the HostName, Username and Password in the next step.
- Now go back to NodeRed and make sure you are in the WCS flow.
Click on the Current Temp node. This is a DashDB node, so we need to make sure the setting are configured properly. You should see something like:
If you see the "Server" information from the IoT lab. Select it. If you don't see an option for the "Server" information from the IoT Lab, you will need to add the information. Click on the pencil icon to set up the connection information. You should see something like Once you fill in the values it should look similar to: Click the update button then click on the Done button. Your dashDB node should now have the proper information to connect to the service instance. - Now double click on the IoT Change Color node. We need to make sure the connection information is correct. Like from workshop 1, enter the appropriate values.
- The final step is to double click on the STSA-CONV node. This is the Watson Conversation node, that connects to the conversation you just created above. Provide the Username, password and Workspace values from above. Click Done when completed. You are done updating the NodeRed Flows for WCS Click the DEPLOY button at the top of the screen.
-
The next step is to create a sample application that connects to your NodeRed flow. When you click on the button below, you will be taken to bluemix DevOps page. This will automatically create a new application for you, via the DevOps ToolChain. If you are not logged on to BlueMix you will need to logon.
You will see a screen like the following: Click the deploy button, after about 1 minute or less, your screen will change to something like the following: Click on the Deliver tile Then you should see something like the following: Once the message in the deploy tile has changed to finished from Deploy running, click on the Last Executed Results This will take you to the newly created applications. Your screen should now look like: Click on the Runtime link on the left and your screen should change, then click on environment tab in the middle of the screen. It should look like the following: In the CONVERSATION_URL value change the "xxxxxx" to the hostname of your NodeRed application. This comes from the NodeRed url that where you are creating your NodeRed flow. So something like "STSAWorkshops-xx.mybluemix.net", do not include "/red/# Click the Save button. The application will restart. Click on the Visit App URL. This is at the top of the page. You will get an error message. That is okay. You need to add webclient to the end of the browsers URL. Your screen should now look like the following:
- You can now ask Watson questions about the temperature.
- What is the current temperature in Celsius
- What is the temperature
- What is the current temperature in fahrenheit
- Change the background color to blue
-
In the event you are not able to complete the workshop in enough time, we have provided a DevOps toolchain that will allow for you to quickly get a completed lab setup. Follow the instructions below to install a completed workshop 2 within BlueMix.