From 2869cbcd83fd7b219adf9f317afdf86ea3014d0b Mon Sep 17 00:00:00 2001 From: MiyabiTane Date: Tue, 16 Aug 2022 19:58:39 +0900 Subject: [PATCH 1/4] support mebo --- chaplus_ros/README.md | 30 +++++++++++++++++------ chaplus_ros/apikey.json | 5 +++- chaplus_ros/sample/simple_example.launch | 28 +++++++++++++++++++++ chaplus_ros/scripts/chaplus_ros.py | 31 +++++++++++++++++++++++- 4 files changed, 85 insertions(+), 9 deletions(-) create mode 100644 chaplus_ros/sample/simple_example.launch diff --git a/chaplus_ros/README.md b/chaplus_ros/README.md index 5bfb2c77a..21025d707 100644 --- a/chaplus_ros/README.md +++ b/chaplus_ros/README.md @@ -1,18 +1,21 @@ chaplus_ros =========== -ROS package for https://www.chaplus.jp/ +ROS package for mebo: https://mebo.work/ ## Tutorials -1) Obtain API keys for chaplus service, go to https://www.chaplus.jp/api +1. Please Download the [apikey.json](https://drive.google.com/file/d/1tAT_WQqCMqvtbM0-CSTomWjwMP4jcOi9/view?usp=sharing) for JSK users and replace `` `rospack find chaplus_ros`/apikey.json `` with it. -You can also create account via https://chaplus.work and reqeust [beta program](https://forms.gle/DQWXdXzUH4MnE5wv6) +2. You can try the sample launch with the following command. -2) Put API key as json file under `` `rospack find chaplus_ros`/apikey.json `` - ``` - {"apikey": "0123456789"} - ``` + ``` + $ roslaunch chaplus_ros simple_example.launch + ``` + + This sample subscribes `/speech_to_text [speech_recognition_msgs/SpeechRecognitionCandidates]` and publishes `/robotsound_jp [sound_play/SoundRequest]` + +3. optional) If you want to get new agent, please reference https://qiita.com/maKunugi/items/14f1b82a2c0b6fa5c202 ## Interface @@ -78,3 +81,16 @@ Please access https://a3rt.recruit.co.jp/product/talkAPI/registered/ and enter y ``` roslaunch chaplus_ros google_example.launch chatbot_engine:=A3RT ``` + +### Chaplus + +Reference: https://www.chaplus.jp/. Note that support ends on August 31, 2022. + +1) Obtain API keys for chaplus service, go to https://www.chaplus.jp/api + +You can also create account via https://chaplus.work and reqeust [beta program](https://forms.gle/DQWXdXzUH4MnE5wv6) + +2) Put API key as json file under `` `rospack find chaplus_ros`/apikey.json `` + ``` + {"apikey": "0123456789"} + ``` diff --git a/chaplus_ros/apikey.json b/chaplus_ros/apikey.json index 926d22bd8..00dae1f77 100644 --- a/chaplus_ros/apikey.json +++ b/chaplus_ros/apikey.json @@ -1,2 +1,5 @@ {"apikey": "0123456789", -"apikey_a3rt": "abcdefgh"} +"apikey_a3rt": "abcdefgh", +"apikey_mebo": "apikey", +"agentid_mebo": "agentid", +"uid_mebo": "user"} diff --git a/chaplus_ros/sample/simple_example.launch b/chaplus_ros/sample/simple_example.launch new file mode 100644 index 000000000..c593b3a38 --- /dev/null +++ b/chaplus_ros/sample/simple_example.launch @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + chatbot_engine: $(arg chatbot_engine) + use_sample: $(arg use_sample) + + + + diff --git a/chaplus_ros/scripts/chaplus_ros.py b/chaplus_ros/scripts/chaplus_ros.py index d8df7c096..90165d2b3 100755 --- a/chaplus_ros/scripts/chaplus_ros.py +++ b/chaplus_ros/scripts/chaplus_ros.py @@ -87,6 +87,13 @@ def __init__(self): self.apikey = apikey_json['apikey_a3rt'] self.endpoint = "https://api.a3rt.recruit.co.jp/talk/v1/smalltalk" + elif self.chatbot_engine=="Mebo": + self.headers = {'content-type': 'application/json'} + self.url = "https://api-mebo.dev/api" + self.apikey = apikey_json['apikey_mebo'] + self.agentid = apikey_json['agentid_mebo'] + self.uid = apikey_json['uid_mebo'] + else: rospy.logerr("please use chatbot_engine Chaplus or A3RT") sys.exit(1) @@ -141,8 +148,30 @@ def topic_cb(self, msg): best_response = "ごめんなさい、よくわからないです" rospy.loginfo("a3rt: returns best response {}".format(best_response)) + #use Mebo + elif self.chatbot_engine == "Mebo": + try: + rospy.loginfo("received {}".format(msg.data)) + self.data = json.dumps( + {'api_key': self.apikey, + 'agent_id': self.agentid, + 'utterance': msg.data, + 'uid': self.uid + }) + response = requests.post(self.url, headers=self.headers, data=self.data, timeout=(3.0, 7.5)) + response_json = response.json() + if 'bestResponse' not in response_json: + best_response = "ごめんなさい、よくわからないです" + else: + best_response = response_json['bestResponse']['utterance'] + except Exception as e: + rospy.logerr("Failed to reqeust url={}, headers={}, data={}".format( + self.url, self.headers, self.data)) + rospy.logerr(e) + best_response = "ごめんなさい、よくわからないです" + rospy.loginfo("mebo: returns best response {}".format(best_response)) else: - rospy.logerr("please use chatbot_engine Chaplus or A3RT") + rospy.logerr("please use chatbot_engine Chaplus or A3RT or Mebo") if response_json is not None: # convert to string for print out From dc5baf6ab094b36fd8c66393c965034a60cf2839 Mon Sep 17 00:00:00 2001 From: MiyabiTane Date: Tue, 16 Aug 2022 20:05:21 +0900 Subject: [PATCH 2/4] change default param --- chaplus_ros/scripts/chaplus_ros.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaplus_ros/scripts/chaplus_ros.py b/chaplus_ros/scripts/chaplus_ros.py index 90165d2b3..1c7424a6d 100755 --- a/chaplus_ros/scripts/chaplus_ros.py +++ b/chaplus_ros/scripts/chaplus_ros.py @@ -52,7 +52,7 @@ class ChaplusROS(object): def __init__(self): - self.chatbot_engine = rospy.get_param("~chatbot_engine", "Chaplus") + self.chatbot_engine = rospy.get_param("~chatbot_engine", "Mebo") self.use_sample = rospy.get_param("~use_sample", True) # please write your apikey to chaplus_ros/apikey.json r = rospkg.RosPack() From 4fc8e34af439a340cdd190f16bb66e064e28f6dd Mon Sep 17 00:00:00 2001 From: MiyabiTane Date: Fri, 19 Aug 2022 13:51:41 +0900 Subject: [PATCH 3/4] include simple_example.launch in google_example.launch --- chaplus_ros/README.md | 34 ++++++++-- chaplus_ros/sample/google_example.launch | 80 ++++++++++++++---------- chaplus_ros/sample/simple_example.launch | 28 --------- 3 files changed, 75 insertions(+), 67 deletions(-) delete mode 100644 chaplus_ros/sample/simple_example.launch diff --git a/chaplus_ros/README.md b/chaplus_ros/README.md index 21025d707..d209cba84 100644 --- a/chaplus_ros/README.md +++ b/chaplus_ros/README.md @@ -5,17 +5,41 @@ ROS package for mebo: https://mebo.work/ ## Tutorials -1. Please Download the [apikey.json](https://drive.google.com/file/d/1tAT_WQqCMqvtbM0-CSTomWjwMP4jcOi9/view?usp=sharing) for JSK users and replace `` `rospack find chaplus_ros`/apikey.json `` with it. +1. optional) If you want to get new agent, please reference https://qiita.com/maKunugi/items/14f1b82a2c0b6fa5c202 -2. You can try the sample launch with the following command. +2. For JSK Users, please download the [apikey.json](https://drive.google.com/file/d/1tAT_WQqCMqvtbM0-CSTomWjwMP4jcOi9/view?usp=sharing) + +3. Please start the sample launch with the following command. ``` - $ roslaunch chaplus_ros simple_example.launch + $ roslaunch chaplus_ros google_example.launch chaplus_apikey_file:=${HOME}/Downloads/apikey.json ``` - This sample subscribes `/speech_to_text [speech_recognition_msgs/SpeechRecognitionCandidates]` and publishes `/robotsound_jp [sound_play/SoundRequest]` -3. optional) If you want to get new agent, please reference https://qiita.com/maKunugi/items/14f1b82a2c0b6fa5c202 +4. You can try several conversations using `rostopic pub` command. Here is an example of sending "おはよう". + + ``` + $ rostopic pub -1 /speech_to_text speech_recognition_msgs/SpeechRecognitionCandidates "transcript: + - 'おはよう' + confidence: + - 0" + ``` + The reply from the bot can be checked using `rostopic echo` command. + ``` + $ rostopic echo /robotsound_jp + ``` + + You can also check the replies from the bot by looking the log of launch file. Here is an example, + ``` + [INFO] [1660883369.681670]: received おはよう + [INFO] [1660883370.392226]: mebo: returns best response おはようございます! + [INFO] [1660883399.459653]: received お話しよう + [INFO] [1660883404.919770]: mebo: returns best response あー、久しぶりにおしゃべりしたいですね。楽しみにしています。 + [INFO] [1660883419.081326]: received 何色が好き? + [INFO] [1660883423.183745]: mebo: returns best response 私の好きな色は緑です。気持ちが落ち着きますよね。 + [INFO] [1660883440.504536]: received 緑いいですね。私は白が好きです。 + [INFO] [1660883444.164753]: mebo: returns best response なんだか癒されそうですね。 + ``` ## Interface diff --git a/chaplus_ros/sample/google_example.launch b/chaplus_ros/sample/google_example.launch index e4d07b44d..a665e79f1 100644 --- a/chaplus_ros/sample/google_example.launch +++ b/chaplus_ros/sample/google_example.launch @@ -1,39 +1,50 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + chatbot_engine: $(arg chatbot_engine) use_sample: $(arg use_sample) + chaplus_apikey_file: $(arg chaplus_apikey_file) diff --git a/chaplus_ros/sample/simple_example.launch b/chaplus_ros/sample/simple_example.launch deleted file mode 100644 index c593b3a38..000000000 --- a/chaplus_ros/sample/simple_example.launch +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - chatbot_engine: $(arg chatbot_engine) - use_sample: $(arg use_sample) - - - - From 729f4a246f0173a577374c88d99220237bf3a31b Mon Sep 17 00:00:00 2001 From: MiyabiTane Date: Fri, 19 Aug 2022 15:24:44 +0900 Subject: [PATCH 4/4] update README.md --- chaplus_ros/README.md | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/chaplus_ros/README.md b/chaplus_ros/README.md index d209cba84..0b8869b63 100644 --- a/chaplus_ros/README.md +++ b/chaplus_ros/README.md @@ -26,19 +26,41 @@ ROS package for mebo: https://mebo.work/ ``` The reply from the bot can be checked using `rostopic echo` command. ``` - $ rostopic echo /robotsound_jp + $ roopic echo --filter "print(m.arg)" /robotsound_jp + or + $ rostopic echo /robotsound_jp | ascii2uni -a U -q ``` - You can also check the replies from the bot by looking the log of launch file. Here is an example, + Here is an example of conversations. ``` - [INFO] [1660883369.681670]: received おはよう - [INFO] [1660883370.392226]: mebo: returns best response おはようございます! - [INFO] [1660883399.459653]: received お話しよう - [INFO] [1660883404.919770]: mebo: returns best response あー、久しぶりにおしゃべりしたいですね。楽しみにしています。 - [INFO] [1660883419.081326]: received 何色が好き? - [INFO] [1660883423.183745]: mebo: returns best response 私の好きな色は緑です。気持ちが落ち着きますよね。 - [INFO] [1660883440.504536]: received 緑いいですね。私は白が好きです。 - [INFO] [1660883444.164753]: mebo: returns best response なんだか癒されそうですね。 + # terminal 1 + $ rostopic pub -1 /speech_to_text speech_recognition_msgs/SpeechRecognitionCandidates "transcript: + - 'おはよう' + confidence: + - 0" + + $ rostopic pub -1 /speech_to_text speech_recognition_msgs/SpeechRecognitionCandidates "transcript: + - 'お話しよう' + confidence: + - 0" + + $ rostopic pub -1 /speech_to_text speech_recognition_msgs/SpeechRecognitionCandidates "transcript: + - '何色が好き?' + confidence: + - 0" + + $ rostopic pub -1 /speech_to_text speech_recognition_msgs/SpeechRecognitionCandidates "transcript: + - '良いですね。私は白が好きです。' + confidence: + - 0" + ``` + ``` + # termial 2 + $ roopic echo --filter "print(m.arg)" /robotsound_jp + おはようございます! + あー、久しぶりにおしゃべりしたいですね。楽しみにしています。 + 私の好きな色は緑です。気持ちが落ち着きますよね。 + 私も好きです。気持ちが落ち着く気がしますから。 ``` ## Interface