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-11-15 14:30:57 +08:00
|
|
|
|
self.chat_history = ""
|
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-16 20:48:01 +08:00
|
|
|
|
if isinstance(chat,set):
|
|
|
|
|
self.create_sub_task(chat)
|
|
|
|
|
return ptree.common.Status.RUNNING
|
|
|
|
|
|
|
|
|
|
|
2023-11-15 14:30:57 +08:00
|
|
|
|
self.chat_history += chat + '\n'
|
2023-11-08 15:28:01 +08:00
|
|
|
|
|
2023-11-15 15:24:10 +08:00
|
|
|
|
res_dict = ask_llm(chat)
|
2023-11-12 14:36:41 +08:00
|
|
|
|
answer = res_dict["Answer"]
|
2023-11-17 18:56:58 +08:00
|
|
|
|
self.scene.chat_bubble(answer) # 机器人输出对话
|
2023-11-15 14:30:57 +08:00
|
|
|
|
self.chat_history += answer + '\n'
|
|
|
|
|
|
|
|
|
|
goal = res_dict["Goal"]
|
2023-11-15 15:24:10 +08:00
|
|
|
|
if goal:
|
|
|
|
|
if "{" not in goal:
|
|
|
|
|
goal = {str(goal)}
|
|
|
|
|
else:
|
|
|
|
|
goal=eval(goal)
|
2023-11-12 14:36:41 +08:00
|
|
|
|
|
|
|
|
|
if goal is not None:
|
2023-11-09 08:47:57 +08:00
|
|
|
|
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)
|