2023-10-10 20:47:32 +08:00
|
|
|
|
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 21:52:13 +08:00
|
|
|
|
|
2023-11-08 15:28:01 +08:00
|
|
|
|
class DealChat(Act):
|
2023-11-08 10:03:40 +08:00
|
|
|
|
def __init__(self):
|
|
|
|
|
super().__init__()
|
2023-10-17 16:28:36 +08:00
|
|
|
|
|
2023-10-25 22:12:15 +08:00
|
|
|
|
def _update(self) -> ptree.common.Status:
|
2023-10-25 10:34:24 +08:00
|
|
|
|
# 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 21:52:13 +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}')
|
|
|
|
|
#
|
|
|
|
|
# self.create_sub_task(goal)
|
|
|
|
|
# else:
|
|
|
|
|
answer = ask_llm(chat)
|
|
|
|
|
answer_split = answer.split("---")
|
|
|
|
|
sentence = answer_split[0].strip()
|
|
|
|
|
goal = None
|
|
|
|
|
if len(answer_split) > 1:
|
|
|
|
|
goal = answer_split[1].strip()
|
|
|
|
|
|
|
|
|
|
print(f'{sentence}')
|
|
|
|
|
if goal:
|
2023-11-09 08:47:57 +08:00
|
|
|
|
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)
|
2023-11-09 21:52:13 +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)
|