To use the AI to automate the browser to do some task
What we need for the major.
Python: The programming language to run the tools Conda: The easy way to setup Python enviornment Ollama: The Local env to run AI model Qwen2.5: The AI model we are going to use Browser-use: The framework for run the
Got to Conda website https://docs.conda.io/projects/conda/en/latest/user-guide/getting-started.html#before-you-start
Follow instruction to install Miniforge https://conda-forge.org/download
Go to Ollama website https://ollama.com/download
Download the installer https://ollama.com/download/OllamaSetup.exe
Open the terminal
Start ollama
ollama serve
Pull AI model
ollama pull qwen2.5:7b
Check AI model installed
ollama list
pip install browser-use
pip install langchain_ollama
playwright install
create a file main.py
and put the below code
from langchain_ollama import ChatOllama
from browser_use import Agent
from pydantic import SecretStr
from dotenv import load_dotenv
load_dotenv()
import asyncio
# Initialize the model
llm=ChatOllama(model="qwen2.5:7b", num_ctx=32000)
async def main():
agent = Agent(
task=(
'1. Go to https://www.reddit.com/r/LocalLLaMA'
"2. Search for 'browser use' in the search bar"
'3. Click search'
'4. Call done'
),
llm=llm,
max_actions_per_step=1,
tool_calling_method="json_schema",
max_failures=6,
use_vision=False
)
result = await agent.run()
print(result)
asyncio.run(main())
and run python main.py
For other model https://docs.browser-use.com/customize/supported-models#supported-models