mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-26 15:49:42 +02:00
Merge branch 'feature-browser-tool' into 'mgx_ops'
Feature browser tool See merge request pub/MetaGPT!186
This commit is contained in:
commit
4dfe8524a1
6 changed files with 553 additions and 246 deletions
|
|
@ -2,6 +2,7 @@ from __future__ import annotations
|
|||
|
||||
import inspect
|
||||
import json
|
||||
import re
|
||||
import traceback
|
||||
from typing import Callable, Literal, Tuple
|
||||
|
||||
|
|
@ -87,6 +88,23 @@ class RoleZero(Role):
|
|||
"RoleZero.ask_human": self.ask_human,
|
||||
"RoleZero.reply_to_human": self.reply_to_human,
|
||||
}
|
||||
self.tool_execution_map.update(
|
||||
{
|
||||
f"Browser.{i}": getattr(self.browser, i)
|
||||
for i in [
|
||||
"click",
|
||||
"close_tab",
|
||||
"go_back",
|
||||
"go_forward",
|
||||
"goto",
|
||||
"hover",
|
||||
"press",
|
||||
"scroll",
|
||||
"tab_focus",
|
||||
"type",
|
||||
]
|
||||
}
|
||||
)
|
||||
# can be updated by subclass
|
||||
self._update_tool_execution()
|
||||
return self
|
||||
|
|
@ -125,7 +143,14 @@ class RoleZero(Role):
|
|||
available_commands=tool_info,
|
||||
instruction=self.instruction.strip(),
|
||||
)
|
||||
context = self.llm.format_msg(self.rc.memory.get(self.memory_k) + [UserMessage(content=prompt)])
|
||||
memory = self.rc.memory.get(self.memory_k)
|
||||
if not self.browser.is_empty_page:
|
||||
pattern = re.compile(r"Command Browser\.(\w+) executed")
|
||||
for index, msg in zip(range(len(memory), 0, -1), memory[::-1]):
|
||||
if pattern.match(msg.content):
|
||||
memory.insert(index, UserMessage(cause_by="browser", content=await self.browser.view()))
|
||||
break
|
||||
context = self.llm.format_msg(memory + [UserMessage(content=prompt)])
|
||||
# print(*context, sep="\n" + "*" * 5 + "\n")
|
||||
async with ThoughtReporter(enable_llm_stream=True):
|
||||
self.command_rsp = await self.llm.aask(context, system_msgs=self.system_msg)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue