In this machine learning, large language model and AI tutorial, we explain how to install and run “Browser Use” Python program (library). This Python program enables you to integrate AI agents with a web browser. That is, you can define a task and an assignment for an AI agent, and the AI agent will automatically open a web browser, and complete the task. For example, you can
- Ask for the current weather at your location
- Ask to go to Amazon and to find a list of 5 best-rated laptops
- Ask to search the Internet to answer a particular question
- To write a letter on Google docs and send this letter to your family members
And many other tasks. “Browser use” is one among a number of programs for integrating AI agents with web browsers. This project is relatively new and it has great potential. In this tutorial, we explain how to install this program and how to run the agent locally by using Ollama and Qwen2.5 LLM. The YouTube tutorial is given below.
Installation Instructions
The first step is to install Ollama. Go to the Ollama website
and click on Download to download the installation file, and install Ollama by simply clicking on the installation file and by following the straightforward instructions. Then, after Ollama is installed, download the qwen2.5:14b model. To do that, open the command prompt after Ollama is installed and type
ollama pull qwen2.5:14b
After the model is installed, type
cd\
mkdir test1
cd test1
Then, type
git clone https://github.com/browser-use/browser-use
after that
cd browser-use
and after that create a Python virtual environment
python -m venv env1
env1\Scripts\activate.bat
Then install
pip install . ."[dev]"
pip install langchain_ollama
playwright install
Then, write and run the test code given below.
import os
import asyncio
from browser_use import Agent
from langchain_ollama import ChatOllama
# Another question: Go to https://aleksandarhaber.com and find the title of this website
async def run_search() -> str:
agent = Agent(
task="What is the current temperature in Boston, Massachusetts?",
llm=ChatOllama(
model="qwen2.5:7b",
num_ctx=32000,
),
max_actions_per_step=3,
tool_call_in_content=False,
)
result = await agent.run(max_steps=15)
return result
async def main():
result = await run_search()
print("\n\n", result)
if __name__ == "__main__":
asyncio.run(main())