Skip to content

Instantly share code, notes, and snippets.

@juananpe
Last active July 17, 2023 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juananpe/efbd91cbf0bf79fd93ae86106ede0d91 to your computer and use it in GitHub Desktop.
Save juananpe/efbd91cbf0bf79fd93ae86106ede0d91 to your computer and use it in GitHub Desktop.
check-2-4-4.py
from langchain.agents import initialize_agent, AgentType
from langchain.chat_models import ChatAnthropic
import asyncio
from langchain.agents.agent_toolkits import PlayWrightBrowserToolkit
from langchain.tools.playwright.utils import (
create_async_playwright_browser,
create_sync_playwright_browser, # A synchronous browser is available, though it isn't compatible with jupyter.
)
import json
from dotenv import load_dotenv
load_dotenv()
import nest_asyncio
nest_asyncio.apply()
async def go(async_browser):
async_browser = create_async_playwright_browser()
toolkit = PlayWrightBrowserToolkit.from_browser(async_browser=async_browser)
tools = toolkit.get_tools()
llm = ChatAnthropic(temperature=0) # or any other LLM, e.g., ChatOpenAI(), OpenAI()
agent_chain = initialize_agent(
tools,
llm,
agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION,
verbose=True,
)
response = await agent_chain.arun(input="Browse to https://www.w3.org/WAI and summarize the content in one sentence. Then, tell me on a scale from 0 to 1 how suitable it would be to add a link to that website using this text for the anchor: 'International Federation of Association Football (FIFA)'. Write your answer as a JSON object with the key 'suitability'. For example {'summary': 'summary of the page', 'suitability': a float number between 0 and 1}" )
print(response)
async def main():
async with create_async_playwright_browser() as playwright:
await go(playwright)
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment