|
@@ -1,2 +1,81 @@
|
|
|
# Chrome-GPT
|
|
|
|
|
|
+利用 Langchain 和 Selenium 使 AutoGPT 代理能够控制整个 Chrome 会话。由于能够以交互方式滚动、单击和输入网页上的文本,AutoGPT 代理可以导航和操作 Web 内容。
|
|
|
+
|
|
|
+## Usage
|
|
|
+```
|
|
|
+python -m chromegpt -v -t "{your request}"
|
|
|
+
|
|
|
+```
|
|
|
+
|
|
|
+## 源码分析
|
|
|
+
|
|
|
+
|
|
|
+以 chromegpt 包的方式分发,依赖selenium和langchain ,执行命令后根据参数执行:
|
|
|
+
|
|
|
+```
|
|
|
+ if agent == "auto-gpt":
|
|
|
+ agent_obj: ChromeGPTAgent = AutoGPTAgent(
|
|
|
+ model=model, verbose=verbose, continuous=continuous
|
|
|
+ )
|
|
|
+ elif agent == "baby-agi":
|
|
|
+ agent_obj = BabyAGIAgent(model=model, verbose=verbose)
|
|
|
+ elif agent == "zero-shot":
|
|
|
+ agent_obj = ZeroShotAgent(model=model, verbose=verbose)
|
|
|
+
|
|
|
+```
|
|
|
+调用 _get_autogpt_agent 返回一个 AutoGPT agent:
|
|
|
+
|
|
|
+```
|
|
|
+ self.agent = self._get_autogpt_agent(
|
|
|
+ llm=ChatOpenAI(model_name=model, temperature=0), # type: ignore
|
|
|
+ verbose=verbose,
|
|
|
+ human_in_the_loop=not continuous,
|
|
|
+ )
|
|
|
+
|
|
|
+```
|
|
|
+
|
|
|
+注意其中 get_vectorstore 和 get_agent_tools函数:
|
|
|
+```
|
|
|
+ vectorstore = get_vectorstore()
|
|
|
+ tools = get_agent_tools()
|
|
|
+
|
|
|
+
|
|
|
+ agent = AutoGPT(
|
|
|
+ ai_name,
|
|
|
+ vectorstore.as_retriever(), # type: ignore
|
|
|
+ chain,
|
|
|
+ AutoGPTOutputParser(),
|
|
|
+ tools,
|
|
|
+ feedback_tool=human_feedback_tool,
|
|
|
+ )
|
|
|
+```
|
|
|
+
|
|
|
+get_agent_tools 实现了 from langchain.agents import Tool tool类中自定义的动作:
|
|
|
+
|
|
|
+```
|
|
|
+def get_agent_tools() -> List[BaseTool]:
|
|
|
+ """Get the tools that will be used by the AI agent."""
|
|
|
+ selenium = SeleniumWrapper()
|
|
|
+ tools: List[BaseTool] = [
|
|
|
+ Tool(
|
|
|
+ name="goto",
|
|
|
+ func=selenium.describe_website,
|
|
|
+ description="useful for when you need visit a link or a website",
|
|
|
+ args_schema=DescribeWebsiteInput,
|
|
|
+ ),
|
|
|
+ Tool(
|
|
|
+ name="click",
|
|
|
+ func=selenium.click_button_by_text,
|
|
|
+ description="useful for when you need to click a button/link",
|
|
|
+ args_schema=ClickButtonInput,
|
|
|
+ ),
|
|
|
+ ...
|
|
|
+```
|
|
|
+
|
|
|
+**综上:**
|
|
|
+
|
|
|
+1、效果炫酷,实际用途不大。
|
|
|
+
|
|
|
+2、可以自定义实现自己的动作
|
|
|
+
|