-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add name and drink vector dbs * feat: receptionist command similarity matcher
- Loading branch information
Showing
6 changed files
with
218 additions
and
17 deletions.
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
Binary file not shown.
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,70 @@ | ||
My name is Adel and my favorite drink is cola | ||
My name is Adel and my favorite drink is iced tea | ||
My name is Adel and my favorite drink is juice pack | ||
My name is Adel and my favorite drink is milk | ||
My name is Adel and my favorite drink is orange juice | ||
My name is Adel and my favorite drink is red wine | ||
My name is Adel and my favorite drink is tropical juice | ||
My name is Angel and my favorite drink is cola | ||
My name is Angel and my favorite drink is iced tea | ||
My name is Angel and my favorite drink is juice pack | ||
My name is Angel and my favorite drink is milk | ||
My name is Angel and my favorite drink is orange juice | ||
My name is Angel and my favorite drink is red wine | ||
My name is Angel and my favorite drink is tropical juice | ||
My name is Axel and my favorite drink is cola | ||
My name is Axel and my favorite drink is iced tea | ||
My name is Axel and my favorite drink is juice pack | ||
My name is Axel and my favorite drink is milk | ||
My name is Axel and my favorite drink is orange juice | ||
My name is Axel and my favorite drink is red wine | ||
My name is Axel and my favorite drink is tropical juice | ||
My name is Charlie and my favorite drink is cola | ||
My name is Charlie and my favorite drink is iced tea | ||
My name is Charlie and my favorite drink is juice pack | ||
My name is Charlie and my favorite drink is milk | ||
My name is Charlie and my favorite drink is orange juice | ||
My name is Charlie and my favorite drink is red wine | ||
My name is Charlie and my favorite drink is tropical juice | ||
My name is Jane and my favorite drink is cola | ||
My name is Jane and my favorite drink is iced tea | ||
My name is Jane and my favorite drink is juice pack | ||
My name is Jane and my favorite drink is milk | ||
My name is Jane and my favorite drink is orange juice | ||
My name is Jane and my favorite drink is red wine | ||
My name is Jane and my favorite drink is tropical juice | ||
My name is Jules and my favorite drink is cola | ||
My name is Jules and my favorite drink is iced tea | ||
My name is Jules and my favorite drink is juice pack | ||
My name is Jules and my favorite drink is milk | ||
My name is Jules and my favorite drink is orange juice | ||
My name is Jules and my favorite drink is red wine | ||
My name is Jules and my favorite drink is tropical juice | ||
My name is Morgan and my favorite drink is cola | ||
My name is Morgan and my favorite drink is iced tea | ||
My name is Morgan and my favorite drink is juice pack | ||
My name is Morgan and my favorite drink is milk | ||
My name is Morgan and my favorite drink is orange juice | ||
My name is Morgan and my favorite drink is red wine | ||
My name is Morgan and my favorite drink is tropical juice | ||
My name is Paris and my favorite drink is cola | ||
My name is Paris and my favorite drink is iced tea | ||
My name is Paris and my favorite drink is juice pack | ||
My name is Paris and my favorite drink is milk | ||
My name is Paris and my favorite drink is orange juice | ||
My name is Paris and my favorite drink is red wine | ||
My name is Paris and my favorite drink is tropical juice | ||
My name is Robin and my favorite drink is cola | ||
My name is Robin and my favorite drink is iced tea | ||
My name is Robin and my favorite drink is juice pack | ||
My name is Robin and my favorite drink is milk | ||
My name is Robin and my favorite drink is orange juice | ||
My name is Robin and my favorite drink is red wine | ||
My name is Robin and my favorite drink is tropical juice | ||
My name is Simone and my favorite drink is cola | ||
My name is Simone and my favorite drink is iced tea | ||
My name is Simone and my favorite drink is juice pack | ||
My name is Simone and my favorite drink is milk | ||
My name is Simone and my favorite drink is orange juice | ||
My name is Simone and my favorite drink is red wine | ||
My name is Simone and my favorite drink is tropical juice |
48 changes: 48 additions & 0 deletions
48
tasks/receptionist/scripts/create_name_and_drink_vector_db.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,48 @@ | ||
import os | ||
from typing import List | ||
import rospy | ||
import rospkg | ||
from lasr_vector_databases_msgs.srv import TxtIndex, TxtIndexRequest | ||
|
||
|
||
def create_txt_file(output_path: str) -> None: | ||
"""Creates a txt file containing all permutations of | ||
"My name is <name> and my favorite drink is <drink>" | ||
Args: | ||
output_path (str): Path to the output txt file | ||
""" | ||
|
||
names: List[str] = rospy.get_param("/priors/names") | ||
drinks: List[str] = rospy.get_param("/priors/drinks") | ||
|
||
with open(output_path, "w") as f: | ||
for name in names: | ||
for drink in drinks: | ||
f.write(f"My name is {name} and my favorite drink is {drink}\n") | ||
|
||
|
||
def create_vector_db(txt_path: str, output_path: str) -> None: | ||
"""Creates a vector database from a txt file containing | ||
all permutations of "My name is <name> and my favorite drink is <drink>" | ||
Args: | ||
txt_path (str): Path to the txt file | ||
output_path (str): Path to the output vector database | ||
""" | ||
|
||
rospy.wait_for_service("lasr_faiss/txt_index") | ||
txt_index = rospy.ServiceProxy("lasr_faiss/txt_index", TxtIndex) | ||
|
||
request = TxtIndexRequest() | ||
request.txt_paths = [txt_path] | ||
request.index_paths = [output_path] | ||
request.index_factory_string = "Flat" | ||
txt_index(request) | ||
|
||
|
||
if __name__ == "__main__": | ||
data_dir = os.path.join(rospkg.RosPack().get_path("receptionist"), "data") | ||
txt_path = os.path.join(data_dir, "name_and_drink_vector_db.txt") | ||
output_path = os.path.join(data_dir, "name_and_drink.index") | ||
create_vector_db(txt_path, output_path) |
82 changes: 82 additions & 0 deletions
82
tasks/receptionist/src/receptionist/states/match_name_and_drink.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,82 @@ | ||
#!/usr/bin/env python3 | ||
import os | ||
import rospy | ||
import rospkg | ||
import smach | ||
from lasr_skills import AskAndListen, Say | ||
from lasr_vector_databases_msgs.srv import TxtQuery, TxtQueryRequest | ||
|
||
|
||
class MatchNameAndDrink(smach.State): | ||
def __init__(self): | ||
smach.State.__init__( | ||
self, | ||
outcomes=["succeeded", "failed"], | ||
input_keys=["sequence"], | ||
output_keys=["matched_name", "matched_drink", "sequence"], | ||
) | ||
|
||
self._query_service = rospy.ServiceProxy("lasr_faiss/txt_query", TxtQuery) | ||
self._text_path = os.path.join( | ||
rospkg.RosPack().get_path("receptionist"), | ||
"data", | ||
"name_and_drink_vector_db.txt", | ||
) | ||
self._index_path = os.path.join( | ||
rospkg.RosPack().get_path("receptionist"), "data", "name_and_drink.index" | ||
) | ||
|
||
def execute(self, userdata): | ||
rospy.loginfo(f"Received transcript: {userdata.sequence}") | ||
request = TxtQueryRequest() | ||
request.txt_paths = [self._text_path] | ||
request.index_paths = [self._index_path] | ||
request.query_sentence = userdata.sequence | ||
request.k = 1 | ||
response = self._query_service(request) | ||
matched_name, matched_drink = response.closest_sentences[0].split( | ||
" and my favorite drink is " | ||
) | ||
matched_name = matched_name.split("My name is ")[1] | ||
userdata.matched_name = matched_name | ||
userdata.matched_drink = matched_drink | ||
rospy.loginfo( | ||
f"Matched name: {matched_name} and matched drink: {matched_drink}" | ||
) | ||
userdata.sequence = ( | ||
f"Hello {matched_name}, I see that your favorite drink is {matched_drink}." | ||
) | ||
return "succeeded" | ||
|
||
|
||
if __name__ == "__main__": | ||
rospy.init_node("match_name_and_drink") | ||
sm = smach.StateMachine(outcomes=["succeeded", "failed"]) | ||
with sm: | ||
smach.StateMachine.add( | ||
"ASK_FOR_NAME_AND_DRINK", | ||
AskAndListen( | ||
tts_phrase="Hello, please tell me your name and favorite drink." | ||
), | ||
transitions={"succeeded": "MATCH_NAME_AND_DRINK", "failed": "failed"}, | ||
remapping={"transcribed_speech": "sequence"}, | ||
) | ||
smach.StateMachine.add( | ||
"MATCH_NAME_AND_DRINK", | ||
MatchNameAndDrink(), | ||
transitions={"succeeded": "SAY_MATCHED_NAME_AND_DRINK", "failed": "failed"}, | ||
remapping={"sequence": "sequence"}, | ||
) | ||
smach.StateMachine.add( | ||
"SAY_MATCHED_NAME_AND_DRINK", | ||
Say(), | ||
transitions={ | ||
"succeeded": "succeeded", | ||
"aborted": "failed", | ||
"preempted": "failed", | ||
}, | ||
remapping={ | ||
"text": "sequence", | ||
}, | ||
) | ||
sm.execute() |