Skip to content

Instantly share code, notes, and snippets.

@freddiefujiwara
Last active December 26, 2024 23:02
Show Gist options
  • Save freddiefujiwara/01b44199d30b33c29d5e736b8875ece3 to your computer and use it in GitHub Desktop.
Save freddiefujiwara/01b44199d30b33c29d5e736b8875ece3 to your computer and use it in GitHub Desktop.
Runs a task using AI to automate browser by browser-use
#!/usr/bin/env python
import os
import sys
import argparse
import asyncio
from langchain_openai import ChatOpenAI
from browser_use import Agent
import httpx
# "Save your OpenAI API key in a file named `.openai` in your home folder."
def set_openai_api_key():
with open(os.path.expanduser("~/.openai"), "r") as f:
os.environ["OPENAI_API_KEY"] = f.read().strip()
sys.stdout.reconfigure(encoding='utf-8')
async def main():
set_openai_api_key()
parser = argparse.ArgumentParser()
parser.add_argument('--task', type=str, default="Look for a one-way flight from Tokyo to Okinawa on Google Flights for 2 weeks from now. Tell me the cheapest one")
args = parser.parse_args()
agent = Agent(
task=args.task,
llm=ChatOpenAI(model="gpt-4o", http_async_client=httpx.AsyncClient(verify=False))
)
print(await agent.run())
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment