DEPRECATED: this repo is no longer actively maintained. It can still be used as reference, but may contain outdated or unpatched code.
This application shows the capabilities of Watson Assistant and Discovery services to work together to find answers on a given query. In this sample app, the user is chatting with a virtual car dashboard, giving it commands in plain English such as "Turn on the wipers," "Play me some music," or "Let's find some food." If the user makes a request and Watson Assistant is not confident in its answer (e.g. "How do I check my tire pressure?"), Discovery will search the car manual and return the most relevant results, if relevant materials exist.
This demo is a reworking of a previous one but with an OpenWhisk back-end and React front-end. OpenWhisk is IBM's "serverless" offering, allowing users to upload functions to the cloud, call them via REST API, and pay only by the millisecond of usage.
Under the hood, there are two components to this app:
- One is the front-end, which is simply static assets (HTML, CSS, and React), it uses CSS with Sass for cleaner, more maintainable source code.
- The other is the OpenWhisk actions:
- When the user inputs text, the UI sends the current context and input to the OpenWhisk sequence. These are processed by the Watson Assistant service and returned, with an output and new context. The results are sent to the next action.
- The Discovery action checks for a flag from the Watson Assistant output, and if it is present takes the original input and queries the manual with it. If there is no flag, the Watson Assistant results pass through the function unchanged. The Sequence returns the output and updated context back to the UI.
- If you don't already have an IBM Cloud account, you can sign up here
Make sure you have at least 2 services available in your IBM Cloud account.
- Clone (or fork) this repository, and go to the new directory
git clone https://github.com/watson-developer-cloud/assistant-with-discovery-openwhisk.git
cd assistant-with-discovery-openwhisk
-
Install Node.js (Versions >= 6).
-
In the root directory of your repository, install the dependencies.
npm install
Note:
If you receive the following error during npm install
:
gyp ERR! stack Error: Python executable "python" is v3.4.3, which is not supported by gyp.
gyp ERR! stack You can pass the --python switch to point to Python >= v2.5.0 & < 3.0.0.
Install Python 2.7.x and set npm to use. e.g.
npm config set python /path/to/python
Skip this section if you have downloaded the app from Watson Console and already have a
credentials.json
file
-
Create an instance of the Assistant service and get your credentials:
- Go to the Assistant page in the IBM Cloud Catalog.
- Log in to your IBM Cloud account.
- Click Create.
- Click Show to view the service credentials.
- Copy the
apikey
andiam_apikey_name
value, or copy theusername
andpassword
values if your service instance doesn't provide anapikey
. - Copy the
url
value.
-
Create an instance of the Discovery service and get your credentials:
- Go to the Discovery page in the IBM Cloud Catalog.
- Log in to your IBM Cloud account.
- Click Create.
- Click Show to view the service credentials.
- Copy the
apikey
andiam_apikey_name
value, or copy theusername
andpassword
values if your service instance doesn't provide anapikey
. - Copy the
url
value.
-
Create a
credentials.json
in the top-level directory. -
Copy the following credentials into the file, amending for the instance name, url, apikey, and username/password; which can be found on each instance in the IBM Cloud console
Example
credentials.json
file that configures the apikey and url for a Assitant and Discovery service instances
{
"discovery": [
{
"name": "Discovery-inst",
"plan": "lite",
"credentials": {
"url": "enterUrl",
"apikey": "enterApiKey",
"iam_apikey_name": "enterApiKeyName"
}
}
],
"conversation": [
{
"name": "Assistant-inst",
"plan": "free",
"credentials": {
"url": "enterUrl",
"apikey": "enterApiKey",
"iam_apikey_name": "enterApiKeyName"
}
}
]
}
Run following commands to train Watson Assistant and Discovery services:
npm run train
`
### Setting up the OpenWhisk Back-end
1. Install the Openwhisk [Command Line Interface](https://console.bluemix.net/openwhisk/learn/cli).
2. Download and install the [IBM Cloud CLI](https://console.bluemix.net/docs/cli/index.html#overview).
3. Login by running the following:
```bash
ibmcloud login
ibmcloud target --cf
-
Install jq as a dependency.
-
Run the provided shell script
create-openwhisk-actions.sh
to create your OpenWhisk actions & sequence. The syntax to do so may vary by system, but for example:
sh create-openwhisk-actions.sh
Create an optimized build of your app. During this stage, your environment variable will be inserted into App.js for use by your components.
npm run build
All that's left is to serve your static files locally. You should see the app running in a new tab!
npm start
Example commands that can be executed by the Watson Assistant service are:
turn on windshield wipers
play music
In addition to conversational commands, you can also ask questions that you would expect to have answered in your car manual. For example:
How do I check my tire pressure
How do I turn on cruise control
How do I improve fuel efficiency
How do I connect my phone to bluetooth
Licensed under Apache 2.0.