Fixed up talking and coordination

This commit is contained in:
Dave Niewinski 2024-01-05 16:35:48 +00:00
parent 8f6df2a411
commit 139ae55590
2 changed files with 17 additions and 8 deletions

View File

@ -6,19 +6,28 @@ from openai_ros.srv import Completion, CompletionResponse
import re
import num2words
trigger_strings = ["hey glados", "hey glass", "hey glad us", "hey glades", "hey glads", "hey glad"]
def replace_numbers(text):
return re.sub(r"(\d+)", lambda x: num2words.num2words(int(x.group(0))), text)
def callback(msg):
global chat_service, pub
resp = chat_service(msg.data, 1.0)
text = resp.text.replace('\n', ' ') # Remove line-breaks
text = re.sub(r"\((.*?)\)", " ", text) # Remove anything in brackets
text = replace_numbers(text) # Make digits into text
text = re.sub(' +', ' ', text) # Unnecessary white space
for s in trigger_strings:
if s in msg.data.lower():
text = msg.data.lower()
text = text.replace("hey glados", "")
text = text.replace("hey glass", "")
pub.publish(text)
resp = chat_service(text, 1.0)
text = resp.text.replace('\n', ' ') # Remove line-breaks
text = re.sub(r"\((.*?)\)", " ", text) # Remove anything in brackets
text = replace_numbers(text) # Make digits into text
text = re.sub(' +', ' ', text) # Unnecessary white space
pub.publish(text)
break
def main():
global chat_service, pub