Skip to content

Commit

Permalink
Merge pull request #91 from ibmtjbot/refactor/assistant
Browse files Browse the repository at this point in the history
Refactor/assistant
  • Loading branch information
jweisz authored Jun 13, 2018
2 parents 36d1aea + 0b052f1 commit c8cf7c1
Show file tree
Hide file tree
Showing 16 changed files with 159 additions and 75 deletions.
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# IBM TJBot
<img src="images/tjbot.jpg" width="85%">

[IBM Watson Maker Kits](http://ibm.biz/mytjbot) are a collection of DIY open source templates to build things with [Watson](https://www.ibm.com/watson/developercloud/services-catalog.html) in a fun and easy way. [IBM TJBot](http://ibm.biz/mytjbot) is the first maker kit in the collection. You can 3D print or laser cut the robot body, then use one of our [recipes](recipes) to bring him to life!
[IBM Watson Maker Kits](http://ibm.biz/mytjbot) are a collection of DIY open source templates to build things with [Watson](https://www.ibm.com/watson/products-services/) in a fun and easy way. [IBM TJBot](http://ibm.biz/mytjbot) is the first maker kit in the collection. You can 3D print or laser cut the robot body, then use one of our [recipes](recipes) to bring him to life!

In addition, you can unleash your own creativity and create new recipes that bring TJBot to life using any of the available [Watson services](https://www.ibm.com/watson/developercloud/services-catalog.html)!
In addition, you can unleash your own creativity and create new recipes that bring TJBot to life using any of the available [Watson services](https://www.ibm.com/watson/products-services/)!

**TJBot only works with a Raspberry Pi.**

Expand Down Expand Up @@ -45,7 +45,7 @@ Just run that command to download and install TJBot:
curl -sL http://ibm.biz/tjbot-bootstrap | sudo sh -
```

[Recipes](recipes) are step-by-step instructions to bring your TJBot to life with [Watson](https://www.ibm.com/watson/developercloud/services-catalog.html).
[Recipes](recipes) are step-by-step instructions to bring your TJBot to life with [Watson](https://www.ibm.com/watson/products-services/).

We have provided three initial [recipes](recipes) for you:

Expand All @@ -56,18 +56,12 @@ We have provided three initial [recipes](recipes) for you:
After checking out our sample recipes, we encourage you to take a look at [featured recipes](featured) created by members of our community.

# Contribute to TJBot
TJBot is an open source project designed to make it fun and easy to interact with [Watson](https://www.ibm.com/watson/developercloud/services-catalog.html). We’d love to see what you can make with him. Here are some ideas to get you started.
TJBot is an open source project designed to make it fun and easy to interact with [Watson](https://www.ibm.com/watson/products-services/). We’d love to see what you can make with him!

- **Visual recognition**. Make TJBot recognize your face using the [Watson Visual Recognition](https://www.ibm.com/watson/developercloud/visual-recognition.html) service and the Raspberry Pi Camera.
- **IoT**. Let TJBot control your smart home devices using the [Watson IoT platform](https://www.ibm.com/internet-of-things/platform/watson-iot-platform/).
- **Connected robots**. Program multiple TJBots to chat with each other!

If you would like your own recipe included in our [featured recipe](featured) list, please [send us email](mailto:[email protected]) with a link to your repository and a demo video.
If you would like your own recipe included in our [featured recipe](featured) list, please [open an issue](../../issues) with a link to your repository and a demo video.

# About TJBot
[TJBot](http://ibm.biz/mytjbot) was affectionately named after Thomas J. Watson, the first Chairman and CEO of IBM. TJBot was created by [Maryam Ashoori](https://github.com/maryamashoori) at IBM Research as an experiment to find the best practices in the design and implementation of cognitive objects. He was born on November 9, 2016 via [this blog post](https://www.ibm.com/blogs/research/2016/11/calling-makers-meet-tj-bot/).

Feel free to [contact the team](mailto:[email protected]) with any questions (except technical issues). For technical issues, please create an [issue](https://github.com/ibmtjbot/tjbot/issues) instead.

# License
This project uses the [Apache License Version 2.0](LICENSE) software license.
2 changes: 1 addition & 1 deletion bootstrap/tests/test.camera.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016 IBM Corp. All Rights Reserved.
* Copyright 2016-2018 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/tests/test.led.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016 IBM Corp. All Rights Reserved.
* Copyright 2016-2018 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/tests/test.servo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016 IBM Corp. All Rights Reserved.
* Copyright 2016-2018 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/tests/test.speaker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016 IBM Corp. All Rights Reserved.
* Copyright 2016-2018 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
14 changes: 7 additions & 7 deletions recipes/README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@

# Recipes
Recipes are step by step instructions to help you connect your TJBot to [Watson](https://www.ibm.com/watson/developercloud/services-catalog.html).
Recipes are step by step instructions to help you connect your TJBot to [Watson](https://www.ibm.com/watson/products-services/).

The recipes are designed to be run on a Raspberry Pi. You can either run one of our sample recipes below, or create your own recipe that brings your ideas to life using [Watson](https://www.ibm.com/watson/developercloud/services-catalog.html)!
The recipes are designed to be run on a Raspberry Pi. You can either run one of our sample recipes below, or create your own recipe that brings your ideas to life using [Watson](https://www.ibm.com/watson/products-services/)!

### [Speech to Text](speech_to_text)
> Use your voice to control TJBot's LED with Watson [[instructables](http://www.instructables.com/id/Use-Your-Voice-to-Control-a-Light-With-Watson/)]
This receipe lets you control the [8mm NeoPixel RGB led](https://www.adafruit.com/products/1734) using voice commands. It uses the [Watson Speech to Text API](https://www.ibm.com/watson/developercloud/speech-to-text.html).
This receipe lets you control the [8mm NeoPixel RGB led](https://www.adafruit.com/products/1734) using voice commands. It uses the [Watson Speech to Text](https://www.ibm.com/watson/services/speech-to-text/) API.

[![link to a full video for use voice to control LED](https://img.youtube.com/vi/Wvnh7ie3D6o/0.jpg)](https://www.youtube.com/watch?v=Wvnh7ie3D6o)

### [Sentiment Analysis](sentiment_analysis)
> Make TJBot respond to emotions with Watson [[instructables](http://www.instructables.com/id/Make-Your-Robot-Respond-to-Emotions-Using-Watson/)]
This recipe shines TJBot's [8mm NeoPixel RGB LED](https://www.adafruit.com/products/1734) different colors based on the emotions present in Twitter for a given keyword. It uses [Watson Tone Analyzer](http://www.ibm.com/watson/developercloud/tone-analyzer.html) and the [Twitter API](https://dev.twitter.com/overview/api).
This recipe shines TJBot's [8mm NeoPixel RGB LED](https://www.adafruit.com/products/1734) different colors based on the emotions present in Twitter for a given keyword. It uses [Watson Tone Analyzer](https://www.ibm.com/watson/services/tone-analyzer/) and the [Twitter API](https://dev.twitter.com/overview/api).

<img src="../images/sentiment.png" width="50%">

### [Conversation](conversation)
> Build a talking robot with Watson [[instructables](http://www.instructables.com/id/Build-a-Talking-Robot-With-Watson-and-Raspberry-Pi/)]
This recipe demonstrates how to use the [Watson Speech to Text](https://www.ibm.com/watson/developercloud/speech-to-text.html), [Watson Text to Speech](https://www.ibm.com/watson/developercloud/text-to-speech.html), and [Watson Conversation](https://www.ibm.com/watson/developercloud/conversation.html) services to build a talking chatbot.
This recipe demonstrates how to use the [Watson Speech to Text](https://www.ibm.com/watson/services/speech-to-text/), [Watson Text to Speech](https://www.ibm.com/watson/services/text-to-speech/), and [Watson Assistant](https://www.ibm.com/watson/services/conversation/) services to build a talking chatbot.

<img src="../images/conversation.png" width="50%">

## Featured Recipes
Check out the [featured TJBot recipes](../featured) created by members of our community.

## Contributing Your Own Recipes
TJBot is an open source project designed to make it fun and easy to interact with [Watson](https://www.ibm.com/watson/developercloud/services-catalog.html).
TJBot is an open source project designed to make it fun and easy to interact with [Watson](https://www.ibm.com/watson/products-services/).

If you would like your own recipe included in our [featured recipe](../featured) list, please [send us email](mailto:[email protected]) with a link to your repository and a demo video.
If you would like your own recipe included in our [featured recipe](../featured) list, please [open an issue](../../../issues) and provide a link to your repository and a demo video.

For guidelines on contributing to the TJBot project, please refer to the [contribution guide](../CONTRIBUTING.md).

Expand Down
10 changes: 5 additions & 5 deletions recipes/conversation/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Conversation
> Chat with TJBot!
This recipe uses the [Watson Conversation](https://www.ibm.com/watson/developercloud/conversation.html) and [Watson Text to Speech](https://www.ibm.com/watson/developercloud/text-to-speech.html) services to turn TJ into a chatting robot.
This recipe uses the [Watson Assistant](https://www.ibm.com/watson/services/conversation/) and [Watson Text to Speech](https://www.ibm.com/watson/services/text-to-speech/) services to turn TJ into a chatting robot.

## Hardware
This recipe requires a TJBot with a microphone and a speaker.
Expand All @@ -14,9 +14,9 @@ Next, go to the `recipes/conversation` folder and install the dependencies.
$ cd tjbot/recipes/conversation
$ npm install

Create instances of the [Watson Conversation](https://www.ibm.com/watson/developercloud/conversation.html) and [Watson Text to Speech](https://www.ibm.com/watson/developercloud/text-to-speech.html) services and note the authentication credentials.
Create instances of the [Watson Assistant](https://www.ibm.com/watson/services/conversation/) and [Watson Text to Speech](https://www.ibm.com/watson/services/text-to-speech/) services and note the authentication credentials.

Import the `workspace-sample.json` file into the Watson Conversation service and note the workspace ID.
Import the `workspace-sample.json` file into the Watson Assistant service and note the workspace ID.

Make a copy the default configuration file and update it with the Watson service credentials and the conversation workspace ID.

Expand All @@ -31,8 +31,8 @@ Run!
> Note the `sudo` command. Root user access is required to run TJBot recipes.
# Watson Services
- [Watson Conversation](https://www.ibm.com/watson/developercloud/conversation.html)
- [Watson Text to Speech](https://www.ibm.com/watson/developercloud/text-to-speech.html)
- [Watson Assistant](https://www.ibm.com/watson/services/conversation/)
- [Watson Text to Speech](https://www.ibm.com/watson/services/text-to-speech/)

# License
This project is licensed under Apache 2.0. Full license text is available in [LICENSE](../../LICENSE).
Expand Down
33 changes: 21 additions & 12 deletions recipes/conversation/config.default.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
/*
User-specific configuration
** IMPORTANT NOTE ********************
* Please ensure you do not interchange your username and password.
* Hint: Your username is the lengthy value ~ 36 digits including a hyphen
* Hint: Your password is the smaller value ~ 12 characters
*/
* User-specific configuration
* IMPORTANT NOTES:
* Please ensure you do not interchange your username and password.
* Your username is the longer value: 36 digits, including hyphens
* Your password is the smaller value: 12 characters
*/

exports.conversationWorkspaceId = ''; // replace with the workspace identifier of your conversation
exports.workspaceId = ''; // replace with the workspace identifier of your conversation

// Set this to false if your TJBot does not have a camera.
exports.hasCamera = true;

// Create the credentials object for export
exports.credentials = {};

// Watson Conversation
// https://www.ibm.com/watson/developercloud/conversation.html
exports.credentials.conversation = {
// Watson Assistant
// https://www.ibm.com/watson/services/conversation/
exports.credentials.assistant = {
password: '',
username: ''
};

// Watson Speech to Text
// https://www.ibm.com/watson/developercloud/speech-to-text.html
// https://www.ibm.com/watson/services/speech-to-text/
exports.credentials.speech_to_text = {
password: '',
username: ''
};

// Watson Text to Speech
// https://www.ibm.com/watson/developercloud/text-to-speech.html
// https://www.ibm.com/watson/services/text-to-speech/
exports.credentials.text_to_speech = {
password: '',
username: ''
};

// Watson Visual Recognition
// https://www.ibm.com/watson/services/visual-recognition/
exports.credentials.visual_recognition = {
api_key: ''
};
104 changes: 93 additions & 11 deletions recipes/conversation/conversation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016 IBM Corp. All Rights Reserved.
* Copyright 2016-2018 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,10 +21,13 @@ var config = require('./config');
var credentials = config.credentials;

// obtain user-specific config
var WORKSPACEID = config.conversationWorkspaceId;
var WORKSPACEID = config.workspaceId;

// these are the hardware capabilities that TJ needs for this recipe
var hardware = ['microphone', 'speaker'];
var hardware = ['microphone', 'speaker', 'led', 'servo', 'camera'];
if (config.hasCamera == false) {
hardware = ['microphone', 'speaker', 'led', 'servo'];
}

// set up TJBot's configuration
var tjConfig = {
Expand All @@ -37,21 +40,100 @@ var tjConfig = {
var tj = new TJBot(hardware, tjConfig, credentials);

console.log("You can ask me to introduce myself or tell you a joke.");
console.log("Try saying, \"" + tj.configuration.robot.name + ", please introduce yourself\" or \"" + tj.configuration.robot.name + ", who are you?\"");
console.log("Try saying, \"" + tj.configuration.robot.name + ", please introduce yourself\" or \"" + tj.configuration.robot.name + ", what can you do?\"");
console.log("You can also say, \"" + tj.configuration.robot.name + ", tell me a joke!\"");

// listen for utterances with our attentionWord and send the result to
// the Conversation service
// the Assistant service
tj.listen(function(msg) {
// check to see if they are talking to TJBot
if (msg.startsWith(tj.configuration.robot.name)) {
if (msg.toLowerCase().startsWith(tj.configuration.robot.name.toLowerCase())) {
// remove our name from the message
var turn = msg.toLowerCase().replace(tj.configuration.robot.name.toLowerCase(), "");

// send to the conversation service
tj.converse(WORKSPACEID, turn, function(response) {
// speak the result
tj.speak(response.description);

var utterance = msg.toLowerCase();

// send to the assistant service
tj.converse(WORKSPACEID, utterance, function(response) {
var spoken = false;

// check if an intent to control the bot was found
if (response.object.intents != undefined) {
var intent = response.object.intents[0];
if (intent != undefined && intent.intent != undefined) {
switch (intent.intent) {
case "lower-arm":
tj.speak(response.description);
tj.lowerArm();
spoken = true;
break;
case "raise-arm":
tj.speak(response.description);
tj.raiseArm();
spoken = true;
break;
case "wave":
tj.speak(response.description);
tj.wave();
spoken = true;
break;
case "greeting":
tj.speak(response.description);
tj.wave();
spoken = true;
break;
case "shine":
var misunderstood = false;
if (response.object.entities != undefined) {
var entity = response.object.entities[0];
if (entity != undefined && entity.value != undefined) {
var color = entity.value;
tj.speak(response.description);
tj.shine(color);
spoken = true;
} else {
misunderstood = true;
}
} else {
misunderstood = true;
}

if (misunderstood == true) {
tj.speak("I'm sorry, I didn't understand your color");
spoken = true;
}
break;
case "see":
if (config.hasCamera == false) {
tj.speak("I'm sorry, I don't have a camera so I can't see anything");
spoken = true;
} else {
tj.speak(response.description);
tj.see().then(function(objects) {
if (objects.length == 0) {
tj.speak("I'm not sure I see anything");
} else if (objects.length == 1) {
var object = objects[0].class;
tj.speak("I see " + object);
} else if (objects.length == 2) {
var objects = objects[0].class + " and " + objects[1].class;
tj.speak("I'm looking at " + objects);
} else {
var objects = objects[0].class + ", " + objects[1].class + ", and " + objects[2].class + ", and a few other things too";
tj.speak("I'm looking at " + objects);
}
});
spoken = true;
}
break;
}
}
}

// if we didn't speak a response yet, speak it now
if (spoken == false) {
tj.speak(response.description);
}
});
}
});
Loading

0 comments on commit c8cf7c1

Please sign in to comment.