)
async_browser = create_async_playwright_browser()
toolkit = PlayWrightBrowserToolkit.from_browser(async_browser=async_browser)
tools = toolkit.get_tools()
tools_by_name = {tool.name: tool for tool in tools}
print(tools_by_name.keys())
navigate_tool = tools_by_name["navigate_browser"]
extract_text = tools_by_name["extract_text"]
from langchain.agents import initialize_agent, AgentType
from langchain.chat_models import ChatOpenAI
from langchain.tools import MetaphorSearchResults
llm = ChatOpenAI(model_name="gpt-4", temperature=0.7)
metaphor_tool = MetaphorSearchResults(api_wrapper=search)
agent_chain = initialize_agent([metaphor_tool, extract_text, navigate_tool], llm, agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
agent_chain.run("find me an interesting tweet about AI safety using Metaphor, then tell me the first sentence in the post. Do not finish until able to retrieve the first sentence.")
> Entering new AgentExecutor chain...
Thought: I need to find a tweet about AI safety using Metaphor Search.
Action:
```
{
  "action": "Metaphor Search Results JSON",
  "action_input": {
    "query": "interesting tweet AI safety",
    "num_results": 1
  }
}
```
{'results': [{'url': 'https://safe.ai/', 'title': 'Center for AI Safety', 'dateCreated': '2022-01-01', 'author': None, 'score': 0.18083244562149048}]}
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/tools/examples/metaphor_search.html