Spaces:
Paused
Paused
Miquel Farré
commited on
Commit
·
262e406
1
Parent(s):
c228837
adding planning to logs
Browse files- e2bqwen.py +6 -43
e2bqwen.py
CHANGED
|
@@ -284,48 +284,6 @@ REMEMBER TO ALWAYS CLICK IN THE MIDDLE OF THE TEXT, NOT ON THE SIDE, NOT UNDER.
|
|
| 284 |
a.write(json.dumps(output_memory))
|
| 285 |
a.close()
|
| 286 |
|
| 287 |
-
def write_memory_to_messages(self) -> List[Dict[str, Any]]:
|
| 288 |
-
"""Convert memory to messages for the model"""
|
| 289 |
-
messages = [{"role": MessageRole.SYSTEM, "content": [{"type": "text", "text": self.system_prompt}]}]
|
| 290 |
-
|
| 291 |
-
for memory_step in self.memory.steps:
|
| 292 |
-
if hasattr(memory_step, "task") and memory_step.task:
|
| 293 |
-
# Add task message if it exists
|
| 294 |
-
messages.append({
|
| 295 |
-
"role": MessageRole.USER,
|
| 296 |
-
"content": [{"type": "text", "text": memory_step.task}]
|
| 297 |
-
})
|
| 298 |
-
continue # Skip to next step after adding task
|
| 299 |
-
|
| 300 |
-
# Process model output message if it exists
|
| 301 |
-
if hasattr(memory_step, "model_output") and memory_step.model_output:
|
| 302 |
-
messages.append({
|
| 303 |
-
"role": MessageRole.ASSISTANT,
|
| 304 |
-
"content": [{"type": "text", "text": memory_step.model_output}]
|
| 305 |
-
})
|
| 306 |
-
|
| 307 |
-
# Process observations and images
|
| 308 |
-
observation_content = []
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
# Add text observations if any
|
| 312 |
-
if hasattr(memory_step, "observations") and memory_step.observations:
|
| 313 |
-
observation_content.append({"type": "text", "text": f"Observation: {memory_step.observations}"})
|
| 314 |
-
|
| 315 |
-
# Add error if present and didn't already add observations
|
| 316 |
-
if hasattr(memory_step, "error") and memory_step.error:
|
| 317 |
-
observation_content.append({"type": "text", "text": f"Error: {memory_step.error}"})
|
| 318 |
-
|
| 319 |
-
# Add user message with content if we have any
|
| 320 |
-
if observation_content:
|
| 321 |
-
messages.append({
|
| 322 |
-
"role": MessageRole.USER,
|
| 323 |
-
"content": observation_content
|
| 324 |
-
})
|
| 325 |
-
|
| 326 |
-
return messages
|
| 327 |
-
|
| 328 |
-
|
| 329 |
def write_memory_to_messages(self, summary_mode: Optional[bool] = False) -> List[Dict[str, Any]]:
|
| 330 |
"""Convert memory to messages for the model"""
|
| 331 |
messages = [{"role": MessageRole.SYSTEM, "content": [{"type": "text", "text": self.system_prompt}]}]
|
|
@@ -340,7 +298,11 @@ REMEMBER TO ALWAYS CLICK IN THE MIDDLE OF THE TEXT, NOT ON THE SIDE, NOT UNDER.
|
|
| 340 |
"content": [{"type": "text", "text": memory_step.task}]
|
| 341 |
})
|
| 342 |
continue # Skip to next step after adding task
|
| 343 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
# Process model output message if it exists
|
| 345 |
if hasattr(memory_step, "model_output") and memory_step.model_output:
|
| 346 |
messages.append({
|
|
@@ -393,6 +355,7 @@ REMEMBER TO ALWAYS CLICK IN THE MIDDLE OF THE TEXT, NOT ON THE SIDE, NOT UNDER.
|
|
| 393 |
# print(f"Created {len(messages)} messages with {image_count} image paths")
|
| 394 |
|
| 395 |
return messages
|
|
|
|
| 396 |
|
| 397 |
def take_snapshot_callback(self, memory_step: ActionStep, agent=None) -> None:
|
| 398 |
"""Callback that takes a screenshot + memory snapshot after a step completes"""
|
|
|
|
| 284 |
a.write(json.dumps(output_memory))
|
| 285 |
a.close()
|
| 286 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
def write_memory_to_messages(self, summary_mode: Optional[bool] = False) -> List[Dict[str, Any]]:
|
| 288 |
"""Convert memory to messages for the model"""
|
| 289 |
messages = [{"role": MessageRole.SYSTEM, "content": [{"type": "text", "text": self.system_prompt}]}]
|
|
|
|
| 298 |
"content": [{"type": "text", "text": memory_step.task}]
|
| 299 |
})
|
| 300 |
continue # Skip to next step after adding task
|
| 301 |
+
if hasattr(memory_step, "model_output_message_plan") and memory_step.model_output_message_plan:
|
| 302 |
+
messages.append({
|
| 303 |
+
"role": MessageRole.ASSISTANT,
|
| 304 |
+
"content": [{"type": "text", "text": memory_step.model_output_message_plan.content, "agent_state": "plan"}]
|
| 305 |
+
})
|
| 306 |
# Process model output message if it exists
|
| 307 |
if hasattr(memory_step, "model_output") and memory_step.model_output:
|
| 308 |
messages.append({
|
|
|
|
| 355 |
# print(f"Created {len(messages)} messages with {image_count} image paths")
|
| 356 |
|
| 357 |
return messages
|
| 358 |
+
|
| 359 |
|
| 360 |
def take_snapshot_callback(self, memory_step: ActionStep, agent=None) -> None:
|
| 361 |
"""Callback that takes a screenshot + memory snapshot after a step completes"""
|