Created
January 15, 2025 06:21
-
-
Save fr0gger/4fd0d82cdb053cbebac4b5b5be486a3c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# !pip install nest_asyncio langchain_openai browser-use | |
# !playwright install | |
# Thomas Roccia | |
import json | |
import asyncio | |
import nest_asyncio | |
from langchain_openai import ChatOpenAI | |
from browser_use import Agent, SystemPrompt | |
from browser_use.browser.browser import Browser, BrowserConfig | |
nest_asyncio.apply() | |
llm = ChatOpenAI(model='gpt-4o') | |
class MySystemPrompt(SystemPrompt): | |
def important_rules(self) -> str: | |
existing_rules = super().important_rules() | |
new_rules = 'You are a system that scrolls a website and look for specific information.' | |
return f'{existing_rules}\n{new_rules}' | |
def main(): | |
agent = Agent( | |
task=( | |
"Go to grep.app and look for API keys related to OpenAI using regex sk-[a-zA-Z0-9]{32}. " | |
"Click on the .* to activate regex search, bring me the valid keys, and the associated repository name in JSON format." | |
), | |
llm=llm, | |
system_prompt_class=MySystemPrompt, | |
browser=Browser(config=BrowserConfig(headless=False)), | |
) | |
print( | |
json.dumps( | |
agent.message_manager.system_prompt.model_dump(exclude_unset=True), | |
indent=4, | |
) | |
) | |
asyncio.get_event_loop().run_until_complete(agent.run()) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment