diff --git a/robowaiter/algos/navigate/navigator/AEM.py b/robowaiter/algos/explore/AEM.py similarity index 97% rename from robowaiter/algos/navigate/navigator/AEM.py rename to robowaiter/algos/explore/AEM.py index fd7c945..4a9f315 100644 --- a/robowaiter/algos/navigate/navigator/AEM.py +++ b/robowaiter/algos/explore/AEM.py @@ -7,15 +7,14 @@ import grpc from explore import Explore -sys.path.append('./') -sys.path.append('../') +sys.path.append('/') +sys.path.append('../navigate/') import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.axes_grid1 import make_axes_locatable -import GrabSim_pb2_grpc -import GrabSim_pb2 +from robowaiter.proto import GrabSim_pb2_grpc, GrabSim_pb2 channel = grpc.insecure_channel('localhost:30001', options=[ ('grpc.max_send_message_length', 1024 * 1024 * 1024), diff --git a/robowaiter/algos/navigate/navigator/__init__.py b/robowaiter/algos/explore/__init__.py similarity index 100% rename from robowaiter/algos/navigate/navigator/__init__.py rename to robowaiter/algos/explore/__init__.py diff --git a/robowaiter/algos/navigate/navigator/apf.py b/robowaiter/algos/explore/apf.py similarity index 100% rename from robowaiter/algos/navigate/navigator/apf.py rename to robowaiter/algos/explore/apf.py diff --git a/robowaiter/algos/navigate/navigator/discretize_map.py b/robowaiter/algos/explore/discretize_map.py similarity index 100% rename from robowaiter/algos/navigate/navigator/discretize_map.py rename to robowaiter/algos/explore/discretize_map.py diff --git a/robowaiter/algos/navigate/navigator/explore.py b/robowaiter/algos/explore/explore.py similarity index 100% rename from robowaiter/algos/navigate/navigator/explore.py rename to robowaiter/algos/explore/explore.py diff --git a/robowaiter/algos/navigate/navigator/map_5.pkl b/robowaiter/algos/explore/map_5.pkl similarity index 100% rename from robowaiter/algos/navigate/navigator/map_5.pkl rename to robowaiter/algos/explore/map_5.pkl diff --git a/robowaiter/algos/navigate/navigator/navigate.py b/robowaiter/algos/explore/navigate.py similarity index 100% rename from robowaiter/algos/navigate/navigator/navigate.py rename to robowaiter/algos/explore/navigate.py diff --git a/robowaiter/algos/navigate/navigator/pathsmoothing.py b/robowaiter/algos/explore/pathsmoothing.py similarity index 100% rename from robowaiter/algos/navigate/navigator/pathsmoothing.py rename to robowaiter/algos/explore/pathsmoothing.py diff --git a/robowaiter/algos/navigate/navigator/readme.md b/robowaiter/algos/explore/readme.md similarity index 100% rename from robowaiter/algos/navigate/navigator/readme.md rename to robowaiter/algos/explore/readme.md diff --git a/robowaiter/algos/navigate/navigator/rrt.py b/robowaiter/algos/explore/rrt.py similarity index 100% rename from robowaiter/algos/navigate/navigator/rrt.py rename to robowaiter/algos/explore/rrt.py diff --git a/robowaiter/algos/navigate/navigator/rrt_star.py b/robowaiter/algos/explore/rrt_star.py similarity index 100% rename from robowaiter/algos/navigate/navigator/rrt_star.py rename to robowaiter/algos/explore/rrt_star.py diff --git a/robowaiter/algos/navigate/navigator/test.py b/robowaiter/algos/explore/test.py similarity index 100% rename from robowaiter/algos/navigate/navigator/test.py rename to robowaiter/algos/explore/test.py diff --git a/robowaiter/behavior_lib/act/DealChat.py b/robowaiter/behavior_lib/act/DealChat.py index 564e20b..3e40165 100644 --- a/robowaiter/behavior_lib/act/DealChat.py +++ b/robowaiter/behavior_lib/act/DealChat.py @@ -2,22 +2,7 @@ import py_trees as ptree from robowaiter.behavior_lib._base.Act import Act from robowaiter.llm_client.ask_llm import ask_llm -fixed_answers = { - "测试VLM:做一杯咖啡": - ''' - 测试VLM:做一杯咖啡 - --- - {"At(Coffee,Bar)"} - ''' - , - "测试VLN:前往桌子": - ''' - 测试VLN:前往桌子 - --- - {"At(Robot,Table)"} - ''' - , -} + class DealChat(Act): def __init__(self): super().__init__() @@ -27,20 +12,32 @@ class DealChat(Act): chat = self.scene.state['chat_list'].pop() # 判断是否是测试 - if chat in fixed_answers.keys(): - sentence,goal = fixed_answers[chat].split("---") - sentence = sentence.strip() - goal = goal.strip() - print(f'机器人回答:{sentence}') + # 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: goal = eval(goal) print(f'goal:{goal}') self.create_sub_task(goal) - else: - answer = ask_llm(chat) - print(f"机器人回答:{answer}") - if self.scene.show_bubble: - self.scene.chat_bubble(f"机器人回答:{answer}") + + if self.scene.show_bubble: + self.scene.chat_bubble(f"{answer}") return ptree.common.Status.RUNNING diff --git a/robowaiter/llm_client/ask_llm.py b/robowaiter/llm_client/ask_llm.py index 4644b6b..27a0fab 100644 --- a/robowaiter/llm_client/ask_llm.py +++ b/robowaiter/llm_client/ask_llm.py @@ -1,7 +1,8 @@ import requests import urllib3 - +from robowaiter.utils import get_root_path +from robowaiter.llm_client.single_round import single_round ######################################## # 该文件实现了与大模型的简单通信 ######################################## @@ -9,30 +10,13 @@ import urllib3 # 忽略https的安全性警告 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) +root_path = get_root_path() +# load test questions + + def ask_llm(question): - url = "https://45.125.46.134:25344/v1/chat/completions" - headers = {"Content-Type": "application/json"} - data = { - "model": "RoboWaiter", - "messages": [ - { - "role": "system", - "content": "你是一个机器人服务员:RoboWaiter. 你的职责是为顾客提供对话及具身服务。" - }, - { - "role": "user", - "content": question - } - ] - } - - response = requests.post(url, headers=headers, json=data, verify=False) - - if response.status_code == 200: - result = response.json() - return result['choices'][0]['message']['content'].strip() - else: - return "大模型请求失败:", response.status_code + ans = single_round(question) + return ans if __name__ == '__main__': diff --git a/robowaiter/llm_client/single_round.py b/robowaiter/llm_client/single_round.py new file mode 100644 index 0000000..518826a --- /dev/null +++ b/robowaiter/llm_client/single_round.py @@ -0,0 +1,43 @@ + +import requests +import urllib3 +######################################## +# 该文件实现了与大模型的简单通信 +######################################## + +# 忽略https的安全性警告 +urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) + + +def single_round(question): + url = "https://45.125.46.134:25344/v1/chat/completions" + headers = {"Content-Type": "application/json"} + data = { + "model": "RoboWaiter", + "messages": [ + { + "role": "system", + "content": "你是一个机器人服务员:RoboWaiter. 你的职责是为顾客提供对话及具身服务。" + }, + { + "role": "user", + "content": question + } + ] + } + + response = requests.post(url, headers=headers, json=data, verify=False) + + if response.status_code == 200: + result = response.json() + return result['choices'][0]['message']['content'].strip() + else: + return "大模型请求失败:", response.status_code + + +if __name__ == '__main__': + question = ''' + python中如何通过类名字符串的方式来代替isinstance的作用 + ''' + + print(single_round(question)) \ No newline at end of file diff --git a/robowaiter/llm_client/test_questions.txt b/robowaiter/llm_client/test_questions.txt new file mode 100644 index 0000000..404ed06 --- /dev/null +++ b/robowaiter/llm_client/test_questions.txt @@ -0,0 +1,14 @@ + "测试VLM:做一杯咖啡": + ''' + 测试VLM:做一杯咖啡 + --- + {"At(Coffee,Bar)"} + ''' + , + "测试VLN:前往桌子": + ''' + 测试VLN:前往桌子 + --- + {"At(Robot,Table)"} + ''' + , \ No newline at end of file diff --git a/robowaiter/robot/bracket_ptml.ptml b/robowaiter/robot/bracket_ptml.ptml index 2554792..ae237e0 100644 --- a/robowaiter/robot/bracket_ptml.ptml +++ b/robowaiter/robot/bracket_ptml.ptml @@ -1,7 +1,4 @@ selector -// selector -// cond HasMap() -// act ExploreEnv() { sequence { @@ -15,4 +12,4 @@ selector { act SubTaskPlaceHolder() -} cond At(Talb,ea)} \ No newline at end of file +} cond At(Talb,ea)}} \ No newline at end of file diff --git a/robowaiter/utils/__init__.py b/robowaiter/utils/__init__.py index af2a9db..45f0125 100644 --- a/robowaiter/utils/__init__.py +++ b/robowaiter/utils/__init__.py @@ -1,5 +1,12 @@ - +import os from robowaiter.utils import * from robowaiter.utils import * + + + +def get_root_path(): + return os.path.abspath( + os.path.join(__file__, "../..") + )