Skip to content

Commit

Permalink
Add keyword from rosparam
Browse files Browse the repository at this point in the history
  • Loading branch information
708yamaguchi committed Jan 17, 2025
1 parent c7b7a33 commit 179ff93
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions ros_speech_recognition/scripts/llm-qwen2.5-1.5B.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self, tcp_client):
self.work_id = None

@staticmethod
def create_init_data():
def create_init_data(prompt):
return {
"request_id": "llm_001",
"work_id": "llm",
Expand All @@ -57,12 +57,12 @@ def create_init_data():
"input": "llm.utf-8.stream",
"enoutput": True,
"max_token_len": 1023,
"prompt": "あなたはユーザーアシスタントです。ユーザの入力のうち、以下の言葉に最も近いものを、単語だけで返してください。近いものがなければNoneを返してください。「サーボオン」「サーボオフ」「教示開始」「教示終了」「再生開始」「再生終了」"
"prompt": prompt
}
}

def setup(self):
init_data = self.create_init_data()
def setup(self, prompt):
init_data = self.create_init_data(prompt)
self.tcp_client.send_json(init_data)
response = self.tcp_client.receive_response()
response_data = json.loads(response)
Expand Down Expand Up @@ -159,15 +159,22 @@ def main(host, port, mode="ROS"):
try:
tcp_client.connect()
print("Setup LLM...")
llm_client.setup()
print("Setup LLM finished.")

if mode == "ROS":
# ROS topic input mode
rospy.init_node('llm_qwen2_5')
keywords = rospy.get_param("~keywords", ['おはよう', 'ご飯', '学校', 'ロボット'])
prompt = "あなたはユーザーアシスタントです。ユーザの入力のうち、以下の言葉に最も近いものを、単語だけで返してください。近いものがなければNoneを返してください。"
for keyword in keywords:
prompt += f"「{keyword}」"
llm_client.setup(prompt)
print("Setup LLM finished.")
ROSLLMBridge(llm_client)
rospy.spin()
else:
prompt = input("Enter the first prompt: ")
llm_client.setup(prompt)
print("Setup LLM finished.")
# Keyboard input mode
while True:
user_input = input("Enter your message (or 'exit' to quit): ")
Expand Down

0 comments on commit 179ff93

Please sign in to comment.