更新工具调用
This commit is contained in:
parent
8bdf5a96b4
commit
90ce854cdc
|
@ -1,21 +1,24 @@
|
||||||
import py_trees as ptree
|
import py_trees as ptree
|
||||||
from robowaiter.behavior_lib._base.Act import Act
|
from robowaiter.behavior_lib._base.Act import Act
|
||||||
|
|
||||||
from robowaiter.llm_client.multi_rounds import ask_llm,new_history
|
from robowaiter.llm_client.multi_rounds import ask_llm, new_history
|
||||||
|
import random
|
||||||
|
|
||||||
|
import spacy
|
||||||
|
|
||||||
|
nlp = spacy.load('en_core_web_lg')
|
||||||
|
|
||||||
|
|
||||||
class DealChat(Act):
|
class DealChat(Act):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.chat_history = ""
|
self.chat_history = ""
|
||||||
self.function_success = False
|
self.function_success = False
|
||||||
self.func_map = {
|
self.func_map = {"create_sub_task": self.create_sub_task, "get_object_info": self.get_object_info, "find_location": self.find_location}
|
||||||
"create_sub_task": self.create_sub_task,
|
|
||||||
"get_object_info": self.get_object_info
|
|
||||||
}
|
|
||||||
|
|
||||||
def _update(self) -> ptree.common.Status:
|
def _update(self) -> ptree.common.Status:
|
||||||
# if self.scene.status?
|
# if self.scene.status?
|
||||||
name,sentence = self.scene.state['chat_list'].pop(0)
|
name, sentence = self.scene.state['chat_list'].pop(0)
|
||||||
|
|
||||||
if name == "Goal":
|
if name == "Goal":
|
||||||
self.create_sub_task(goal=sentence)
|
self.create_sub_task(goal=sentence)
|
||||||
|
@ -26,26 +29,22 @@ class DealChat(Act):
|
||||||
|
|
||||||
history = self.scene.state["chat_history"][name]
|
history = self.scene.state["chat_history"][name]
|
||||||
self.scene.state["attention"]["customer"] = name
|
self.scene.state["attention"]["customer"] = name
|
||||||
self.scene.state["serve_state"] = {
|
self.scene.state["serve_state"] = {"last_chat_time": self.scene.time, }
|
||||||
"last_chat_time": self.scene.time,
|
|
||||||
}
|
|
||||||
|
|
||||||
function_call, response = ask_llm(sentence,history,func_map=self.func_map)
|
|
||||||
|
|
||||||
|
function_call, response = ask_llm(sentence, history, func_map=self.func_map)
|
||||||
|
|
||||||
self.scene.chat_bubble(response) # 机器人输出对话
|
self.scene.chat_bubble(response) # 机器人输出对话
|
||||||
|
|
||||||
return ptree.common.Status.RUNNING
|
return ptree.common.Status.RUNNING
|
||||||
|
|
||||||
|
def create_sub_task(self, **args):
|
||||||
def create_sub_task(self,**args):
|
|
||||||
try:
|
try:
|
||||||
goal = args['goal']
|
goal = args['goal']
|
||||||
|
|
||||||
w = goal.split(")")
|
w = goal.split(")")
|
||||||
goal_set = set()
|
goal_set = set()
|
||||||
goal_set.add(w[0] + ")")
|
goal_set.add(w[0] + ")")
|
||||||
if len(w)>1:
|
if len(w) > 1:
|
||||||
for x in w[1:]:
|
for x in w[1:]:
|
||||||
if x != "":
|
if x != "":
|
||||||
goal_set.add(x[1:] + ")")
|
goal_set.add(x[1:] + ")")
|
||||||
|
@ -55,8 +54,7 @@ class DealChat(Act):
|
||||||
|
|
||||||
self.scene.robot.expand_sub_task_tree(goal_set)
|
self.scene.robot.expand_sub_task_tree(goal_set)
|
||||||
|
|
||||||
|
def get_object_info(self, **args):
|
||||||
def get_object_info(self,**args):
|
|
||||||
try:
|
try:
|
||||||
obj = args['obj']
|
obj = args['obj']
|
||||||
|
|
||||||
|
@ -66,7 +64,52 @@ class DealChat(Act):
|
||||||
print("参数解析错误")
|
print("参数解析错误")
|
||||||
|
|
||||||
near_object = "None"
|
near_object = "None"
|
||||||
|
|
||||||
|
# 场景中现有物品
|
||||||
|
cur_things = set()
|
||||||
|
for item in self.status.objects:
|
||||||
|
cur_things.add(item.name)
|
||||||
|
# obj与现有物品进行相似度匹配
|
||||||
|
query_token = nlp(obj)
|
||||||
|
for w in self.all_loc_en:
|
||||||
|
word_token = nlp(w)
|
||||||
|
similarity = query_token.similarity(word_token)
|
||||||
|
if similarity > max_similarity:
|
||||||
|
max_similarity = similarity
|
||||||
|
similar_word = w
|
||||||
|
print("max_similarity:",max_similarity,"similar_word:",similar_word)
|
||||||
|
|
||||||
|
if similar_word: # 存在同义词说明场景中存在该物品
|
||||||
|
near_object = random.choices(list(cur_things), k=5) # 返回场景中的5个物品
|
||||||
|
|
||||||
if obj == "洗手间":
|
if obj == "洗手间":
|
||||||
near_object = "大门"
|
near_object = "大门"
|
||||||
|
|
||||||
return near_object
|
return near_object
|
||||||
|
|
||||||
|
def find_location(self, **args):
|
||||||
|
try:
|
||||||
|
location = args['obj']
|
||||||
|
self.function_success = True
|
||||||
|
except:
|
||||||
|
obj = None
|
||||||
|
print("参数解析错误")
|
||||||
|
|
||||||
|
near_location = None
|
||||||
|
# 用户咨询的地点
|
||||||
|
query_token = nlp(location)
|
||||||
|
max_similarity = 0
|
||||||
|
similar_word = None
|
||||||
|
# 到自己维护的地点列表中找同义词
|
||||||
|
for w in self.all_loc_en:
|
||||||
|
word_token = nlp(w)
|
||||||
|
similarity = query_token.similarity(word_token)
|
||||||
|
if similarity > max_similarity:
|
||||||
|
max_similarity = similarity
|
||||||
|
similar_word = w
|
||||||
|
print("similarity:", max_similarity, "similar_word:", similar_word)
|
||||||
|
# 存在同义词说明客户咨询的地点有效
|
||||||
|
if similar_word:
|
||||||
|
mp = list(self.loc_map_en[similar_word])
|
||||||
|
near_location = random.choice(mp)
|
||||||
|
return near_location
|
||||||
|
|
|
@ -30,9 +30,8 @@ all_obj = ['马克杯', '香蕉', '牙膏', '面包', '软饮料', '酸奶', 'AD
|
||||||
all_loc = ['吧台', '餐桌', '沙发', '灶台', '大门', '灯开关', '空调开关', '橱柜', '卫生间', '窗户', '音响', '休闲区', '工作台', '服务台', '收银台', '墙角',
|
all_loc = ['吧台', '餐桌', '沙发', '灶台', '大门', '灯开关', '空调开关', '橱柜', '卫生间', '窗户', '音响', '休闲区', '工作台', '服务台', '收银台', '墙角',
|
||||||
'蛋糕柜', '充电处', '冰箱', '书架']
|
'蛋糕柜', '充电处', '冰箱', '书架']
|
||||||
|
|
||||||
all_loc_en = ['bar', 'Table', 'sofa', 'stove', 'Gate', 'light switch', 'airconditioner switch', 'cabinet', 'bathroom', 'window',
|
all_loc_en = ['bar', 'Table', 'sofa', 'stove', 'Gate', 'light switch', 'airconditioner switch', 'cabinet', 'bathroom', 'window','audio', 'lounge area',
|
||||||
'audio', 'lounge area', 'workstation', 'service counter', 'cashier counter', 'corner',
|
'workstation', 'service counter', 'cashier counter', 'corner','cake display', 'ChargingStations', 'refrigerator', 'bookshelf']
|
||||||
'cake display', 'ChargingStations', 'refrigerator', 'bookshelf']
|
|
||||||
|
|
||||||
loc_map_en = {'bar': {'工作台', '服务台', '收银台', '蛋糕柜'},
|
loc_map_en = {'bar': {'工作台', '服务台', '收银台', '蛋糕柜'},
|
||||||
'Table': {'大门', '休闲区', '墙角'},
|
'Table': {'大门', '休闲区', '墙角'},
|
||||||
|
|
|
@ -124,6 +124,25 @@ class Scene:
|
||||||
with open(self.filename, 'rb') as file:
|
with open(self.filename, 'rb') as file:
|
||||||
self.map_file = pickle.load(file)
|
self.map_file = pickle.load(file)
|
||||||
|
|
||||||
|
# tool register
|
||||||
|
self.all_loc_en = ['bar', 'Table', 'sofa', 'stove', 'Gate', 'light switch', 'airconditioner switch', 'cabinet', 'bathroom', 'window', 'audio',
|
||||||
|
'lounge area', 'workstation', 'service counter', 'cashier counter', 'corner', 'cake display', 'ChargingStations',
|
||||||
|
'refrigerator', 'bookshelf']
|
||||||
|
|
||||||
|
self.loc_map_en = {'bar': {'工作台', '服务台', '收银台', '蛋糕柜'}, 'Table': {'大门', '休闲区', '墙角'},
|
||||||
|
'sofa': {'餐桌', '窗户', '音响', '休闲区', '墙角', '书架'},
|
||||||
|
'stove': {'吧台', '橱柜', '工作台', '服务台', '收银台', '蛋糕柜', '冰箱'},
|
||||||
|
'Gate': {'吧台', '灯开关', '空调开关', '卫生间', '墙角'}, 'light switch': {'大门', '空调开关', '卫生间', '墙角'},
|
||||||
|
'airconditioner switch': {'大门', '灯开关', '卫生间', '墙角'},
|
||||||
|
'cabinet': {'灶台', '吧台', '工作台', '服务台', '收银台', '蛋糕柜', '充电处', '冰箱'}, 'bathroom': {'大门', '墙角'},
|
||||||
|
'window': {'餐桌', '沙发', '休闲区'}, 'audio': {'餐桌', '沙发', '休闲区', '墙角', '书架'},
|
||||||
|
'lounge area': {'沙发', '餐桌', '墙角', '书架', '音响'}, 'workstation': {'吧台', '服务台', '收银台'},
|
||||||
|
'service counter': {'吧台', '工作台', '收银台'}, 'cashier counter': {'吧台', '工作台', '服务台'},
|
||||||
|
'corner': {'卫生间', '沙发', '灯开关', '空调开关', '音响', '休闲区', '书架'},
|
||||||
|
'cake display': {'吧台', '橱柜', '服务台', '收银台', '冰箱'},
|
||||||
|
'ChargingStations': {'吧台', '餐桌', '沙发', '休闲区', '工作台', '服务台', '收银台', '墙角', '书架'},
|
||||||
|
'refrigerator': {'吧台', '服务台', '蛋糕柜'}, 'bookshelf': {'餐桌', '沙发', '窗户', '休闲区', '墙角'}}
|
||||||
|
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
# 基类reset,默认执行仿真器初始化操作
|
# 基类reset,默认执行仿真器初始化操作
|
||||||
|
|
Loading…
Reference in New Issue