MCPcopy Create free account
hub / github.com/LYX0501/DiscussNav / Completion_Estimation_Experts

Class Completion_Estimation_Experts

DiscussNav.py:234–290  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

232 return observe_results
233
234class Completion_Estimation_Experts:
235 def summarize_observation(self, curr_observe, landmarks):
236 direction_id = int(curr_observe.split("Navigable Viewpoint")[0].replace("Direction","").replace("(lower position indicates down stairs)","").replace("(higher position indicates up stairs)","").strip())
237 directions = ["Front, range(right 0 to right 30)", "Font Right, range(right 30 to right 60)", "Right, range(right 60 to right 90)", "Right, range(right 90 to right 120)", "Rear Right, range(right 120 to right 150)", "Rear Right, range(right 150 to right 180)",
238 "Rear Left, range(left 180 to left 150)", "Rear Left, range(left 150 to left 120)", "Left, range(left 120 to left 90)", "Left, range(left 90 to left 60)", "Front Left, range(left 60 to left 30)", "Front Left, range(left 30 to left 0)"]
239 direction = directions[direction_id]
240 curr_observe = "Scene Description"+curr_observe.split("Scene Description")[1]
241 prompt = [
242 {"role": "system", "content": "You are a trajectory summary expert. Your task is to simplify environment description as short and clear as possible."},
243 {"role": "user", "content": f"Given Environment Description \"{curr_observe}\", Summarization:"}
244 ]
245
246 return f"Direction {direction} " + gpt_response(prompt, "gpt-4", 1)[0]["message"]["content"]
247
248 def summarize_thought(self, thought):
249 prompt = [
250 {"role": "system", "content": "You are a trajectory summary expert. Your task is to simplify navigation thought process as short and clear as possible."},
251 {"role": "user", "content": f"Given Thought Process \"{thought}\", Summarization:"}
252 ]
253
254 return gpt_response(prompt, "gpt-4", 1)[0]["message"]["content"]
255
256 def save_history(self, next_vp, thought, curr_observe, nav_history, landmarks):
257 curr_observe = self.summarize_observation(curr_observe, landmarks)
258 thought = self.summarize_thought(thought)
259 nav_history.append({
260 "viewpoint": next_vp,
261 "observation": curr_observe,
262 "thought": thought
263 })
264
265 return nav_history
266
267 def review_history(self, nav_history):
268 nav_history_str = " -> ".join(["Step "+str(idx+1)+" Observation: "+item["observation"]+" Thought: "+item["thought"] for idx, item in enumerate(nav_history)])
269 logger.info("History: "+nav_history_str)
270
271 return nav_history_str
272
273 def estimate_completion(self, actions, landmarks, history_traj):
274 prompt = [
275 {"role": "system", "content": "You are a completion estimation expert. Your task is to estimate what actions in the instruction have been executed based on navigation history and landmarks. \
276 All actions in the instruction are given following the temporal order. Your answer includes two parts: \"Thought\" and \"Executed Actions\". \
277 In the \"Thought\", you must follow procedures to analyze as detailed as possible what actions have been executed: \
278 (1) What given landmarks of actions have appeared in the navigation history? \
279 (2) Analyze the direction change at each step in the navigation history. \
280 (3) Estimate each action in the instruction based on each step in the navigation history to check their completion. \
281 In the \"Executed Actions\", you must only write down actions that have been executed without other words. \
282 You must strictly refer original actions in the given instruction to estimate."},
283 {"role": "user", "content": f"Given Navigation History \"{history_traj}\" and Landmarks \"{landmarks}\", estimate what actions in instruction \"{actions}\" have been executed."}
284 ]
285 response = gpt_response(prompt, "gpt-4", 1)[0]["message"]["content"]
286 if "Executed Actions" in response:
287 logger.info("Executed Actions "+response)
288 return response.split("Executed Actions")[1].strip()
289 else:
290 return response
291

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected