-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a local speechbot service #88
Open
emilyxzhou
wants to merge
30
commits into
develop
Choose a base branch
from
feature/local-speechbot
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
6468855
Set up Rasa service
emilyxzhou c2172c3
Set up Rasa service with temporary data
emilyxzhou f82e66f
Add bot src files to path
emilyxzhou 606f3e4
Test training and running Rasa from Python script
emilyxzhou c2e74d7
Remove Rasa server script from launch file
emilyxzhou c5c222b
Create separate script to launch Rasa server
emilyxzhou 0964d7b
Add rasa_greeter workspace
emilyxzhou ef5bfbf
Add dependencies
emilyxzhou 29cb991
Add tests
emilyxzhou b58608b
Launch rasa server with bash script
emilyxzhou 802c646
Move script to start rasa server to /scripts
emilyxzhou 4da9a9d
Merge branch 'develop' of https://github.com/interaction-lab/HARMONI …
emilyxzhou a015924
Add test
emilyxzhou 1da6989
Update rostests
emilyxzhou ee82337
Merge branch 'develop' of https://github.com/interaction-lab/HARMONI …
emilyxzhou 1984885
Update README
emilyxzhou 02aac16
Update requirements.txt
emilyxzhou 2175b48
Set harmoniResponse message value
emilyxzhou 38cf49c
Update rostests
emilyxzhou 07f526b
Update rasa version
emilyxzhou ae2c9ef
Set up chatbot pattern example
emilyxzhou 8cebccf
Use loop in chatbot example
emilyxzhou 30b2a2e
Merge branch 'develop' of https://github.com/interaction-lab/HARMONI …
emilyxzhou a1b229d
Merge branch 'develop' of https://github.com/interaction-lab/HARMONI …
emilyxzhou e4ae7f0
Set up voice-based speechbot example
emilyxzhou e378af2
Remove extra lines
emilyxzhou 6bddee3
Move rasa_example to harmoni_models
emilyxzhou 11b3213
Update script to start rasa server
emilyxzhou e63969b
Update README
emilyxzhou 4c8baf2
Ignore TTS
chrismbirmingham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
harmoni_core/harmoni_pattern/pattern_scripting/chatbot.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
[ | ||
{ | ||
"set": "setup", | ||
"steps": [ | ||
{ | ||
"microphone_default": { | ||
"action_goal": "ON", | ||
"resource_type": "sensor", | ||
"wait_for": "" | ||
} | ||
}, | ||
{ | ||
"stt_default": { | ||
"action_goal": "ON", | ||
"resource_type": "detector", | ||
"wait_for": "" | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
"set": "loop", | ||
"steps": [ | ||
{ | ||
"stt_default": { | ||
"resource_type": "detector", | ||
"wait_for": "new" | ||
} | ||
}, | ||
{ | ||
"bot_default": { | ||
"action_goal": "REQUEST", | ||
"resource_type": "service", | ||
"wait_for": "new" | ||
} | ||
}, | ||
{ | ||
"tts_default": { | ||
"action_goal": "REQUEST", | ||
"resource_type": "service", | ||
"wait_for": "new" | ||
} | ||
}, | ||
[ | ||
{ | ||
"speaker_default": { | ||
"action_goal": "DO", | ||
"resource_type": "actuator", | ||
"wait_for": "new" | ||
} | ||
} | ||
] | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Common Imports | ||
import rospy | ||
import roslib | ||
|
||
from harmoni_common_lib.constants import State | ||
from harmoni_common_lib.service_server import HarmoniServiceServer | ||
from harmoni_common_lib.service_manager import HarmoniServiceManager | ||
|
||
# Specific Imports | ||
import argparse | ||
import os | ||
import rasa | ||
import threading | ||
from harmoni_common_lib.constants import DialogueNameSpace | ||
from harmoni_bot.rasa_client import RasaClient | ||
|
||
|
||
class RasaService(HarmoniServiceManager): | ||
"""Rasa chatbot service""" | ||
|
||
def __init__(self, name, param): | ||
"""Constructor method: Initialization of variables and lex parameters + setting up""" | ||
super().__init__(name) | ||
""" Initialization of variables and parameters """ | ||
self.host = param["host"] | ||
self.port = param["port"] | ||
|
||
self.rasa_client = RasaClient( | ||
self.host, | ||
self.port | ||
) | ||
|
||
self.state = State.INIT | ||
return | ||
|
||
def request(self, input_text): | ||
"""[summary] | ||
|
||
Args: | ||
input_text (str): User request (or input text) for triggering Rasa Intent | ||
|
||
Returns: | ||
object: It contains information about the response received (bool) and response message (str) | ||
response: bool | ||
message: str | ||
""" | ||
rospy.loginfo("Start the %s request" % self.name) | ||
self.state = State.REQUEST | ||
|
||
try: | ||
rasa_response = self.rasa_client.get_rasa_response(input_text) | ||
rospy.loginfo(f"The Rasa response is {rasa_response}") | ||
self.state = State.SUCCESS | ||
except Exception as e: | ||
rospy.loginfo(f"Exception occurred: {e}") | ||
self.state = State.FAILED | ||
rasa_response = "" | ||
self.response_received = True | ||
self.result_msg = rasa_response | ||
return {"response": self.state, "message": rasa_response} | ||
|
||
|
||
def main(): | ||
"""[summary] | ||
Main function for starting HarmoniRasa service | ||
""" | ||
service_name = DialogueNameSpace.bot.name | ||
instance_id = rospy.get_param("instance_id") # "default" | ||
service_id = f"{service_name}_{instance_id}" | ||
try: | ||
rospy.init_node(service_name, log_level=rospy.INFO) | ||
params = rospy.get_param("rasa" + "/" + instance_id + "_param/") | ||
s = RasaService(service_id, params) | ||
service_server = HarmoniServiceServer(service_id, s) | ||
service_server.start_sending_feedback() | ||
rospy.spin() | ||
except rospy.ROSInterruptException: | ||
pass | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rasa==2.7.1 | ||
21 changes: 21 additions & 0 deletions
21
harmoni_dialogues/harmoni_bot/scripts/start_rasa_server.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
|
||
shopt -s dotglob | ||
shopt -s nullglob | ||
|
||
RASA_ASSISTANT=$(rosparam get /rasa/default_param/rasa_assistant) | ||
RASA_MODEL_DIR=$(rosparam get /bot_model_dir) | ||
RASA_BOTS=("$RASA_MODEL_DIR/bot/"*) | ||
|
||
found=0 | ||
for dir in "${RASA_BOTS[@]}" ; do | ||
dir=$(basename "$dir") | ||
[[ $dir = "$RASA_ASSISTANT" ]] && found=1 | ||
done | ||
|
||
if [ $found == 1 ]; then | ||
cd "$RASA_MODEL_DIR"/bot/"$RASA_ASSISTANT" || exit | ||
rasa train && rasa run | ||
else | ||
echo "Not a valid Rasa bot" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
# ! DO NOT MANUALLY INVOKE THIS setup.py, USE CATKIN INSTEAD | ||
import os | ||
|
||
from distutils.core import setup | ||
from catkin_pkg.python_setup import generate_distutils_setup | ||
|
||
# fetch values from package.xml | ||
setup_args = generate_distutils_setup( | ||
packages=['harmoni_bot'], | ||
package_dir={'': 'src'}, | ||
package_dir={ | ||
'': 'src', | ||
'harmoni_bot': os.path.join('src', 'harmoni_bot') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I know this line isn't needed. harmoni_common_lib doesn't have it and is imported the same way. |
||
}, | ||
) | ||
|
||
setup(**setup_args) |
38 changes: 38 additions & 0 deletions
38
harmoni_dialogues/harmoni_bot/src/harmoni_bot/rasa_client.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env python3 | ||
import logging | ||
import requests | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
|
||
|
||
class RasaClient: | ||
|
||
def __init__( | ||
self, | ||
host="localhost", | ||
port=5005 | ||
): | ||
self._host = host | ||
self._port = port | ||
|
||
def get_rasa_response(self, input_text): | ||
headers = { | ||
'Content-Type': 'application/json', | ||
} | ||
data = '{ "sender": "test_user", "message": "' + input_text + '", "metadata": {} }' | ||
response = requests.post(f"http://{self._host}:{self._port}/webhooks/myio/webhook", headers=headers, data=data) | ||
logging.info(f"Bot response: \n{response.text}\n") | ||
try: | ||
text = response.json()[0]["text"] | ||
except IndexError: | ||
logging.error("Warning: Bad index") | ||
text = "I didn't catch that" | ||
return text | ||
|
||
|
||
if __name__ == "__main__": | ||
rasa_client = RasaClient() | ||
r = "Let's start a conversation with the rasa bot. What would you like to say?\n->" | ||
while True: | ||
i = input(r) | ||
r = rasa_client.get_rasa_response(i) + "\n->" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- This is an example launch file for how a ROS application could use a node --> | ||
<launch> | ||
<rosparam file="$(find harmoni_bot)/config/configuration.yaml" subst_value="True"/> | ||
<param name="instance_id" value="default"/> | ||
<param name="name_bot" value="rasa"/> | ||
<param name="harmoni_bot_dir" value="$(find harmoni_bot)"/> | ||
<node pkg="harmoni_bot" type="start_rasa_server.sh" name="start_rasa_server" /> | ||
<node pkg="harmoni_bot" type="rasa_service.py" name="harmoni_bot_rasa_default" output="screen"/> | ||
|
||
<param name="test_rasa_input" value="Hello"/> | ||
<param name="rasa/default_param/rasa_assistant" value="rasa_example"/> | ||
<test test-name="test_rasa" pkg="harmoni_bot" type="rostest_rasa.py" time-limit="1000.0" /> | ||
</launch> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the Rasa version differs between the requirements (2.7.1) file and the docker images (2.4.2)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, the dockerfiles have been updated to 2.7.1 now!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good