RoboWaiter/robowaiter/behavior_lib/act/DealChat.py

46 lines
1.2 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 21:52:13 +08:00
2023-11-08 15:28:01 +08:00
class DealChat(Act):
def __init__(self):
super().__init__()
2023-11-15 14:30:57 +08:00
self.chat_history = ""
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-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)
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)
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)