RoboWaiter/robowaiter/behavior_lib/act/DealChat.py

50 lines
1.3 KiB
Python
Raw Normal View History

import py_trees as ptree
2023-11-08 15:28:01 +08:00
from robowaiter.behavior_lib._base.Act import Act
2023-10-25 22:12:15 +08:00
from robowaiter.llm_client.ask_llm import ask_llm
2023-11-09 16:07:02 +08:00
2023-11-09 08:47:57 +08:00
fixed_answers = {
"测试VLM做一杯咖啡":
'''
测试VLM做一杯咖啡
---
{"At(Coffee,Bar)"}
'''
,
"测试VLN前往桌子":
'''
测试VLN前往桌子
---
{"At(Robot,Table)"}
'''
,
}
2023-11-08 15:28:01 +08:00
class DealChat(Act):
def __init__(self):
super().__init__()
2023-10-25 22:12:15 +08:00
def _update(self) -> ptree.common.Status:
# if self.scene.status?
2023-10-25 22:12:15 +08:00
chat = self.scene.state['chat_list'].pop()
2023-11-08 15:28:01 +08:00
# 判断是否是测试
2023-11-09 08:47:57 +08:00
if chat in fixed_answers.keys():
sentence,goal = fixed_answers[chat].split("---")
sentence = sentence.strip()
goal = goal.strip()
print(f'机器人回答:{sentence}')
goal = eval(goal)
print(f'goal{goal}')
2023-11-08 15:28:01 +08:00
2023-11-09 08:47:57 +08:00
self.create_sub_task(goal)
else:
answer = ask_llm(chat)
print(f"机器人回答:{answer}")
2023-11-09 17:06:34 +08:00
if self.scene.show_bubble:
self.scene.chat_bubble(f"机器人回答:{answer}")
2023-10-25 22:12:15 +08:00
return ptree.common.Status.RUNNING
2023-11-08 17:37:49 +08:00
2023-11-09 08:47:57 +08:00
def create_sub_task(self,goal):
self.scene.robot.expand_sub_task_tree(goal)