🌐 Browser-use is the easiest way to connect your AI agents with the browser. With pip (Python>=3.11):
pip install browser-use
Install Playwright:
playwright install chromium
This project demonstrates a simple example of using browser-use
to interact with an AI model.
- Python 3.11 or higher
browser-use
- Playwright (Chromium)
The following code demonstrates a basic example:
from langchain_ollama import ChatOllama
from browser_use import Agent
import asyncio
from dotenv import load_dotenv
load_dotenv()
# Initialize the model
llm=ChatOllama(model="gemma3:4b", num_ctx=32000,base_url="http://localhost:11434")
async def main():
# Create agent with the model
agent = Agent(
task="Compare the price of gpt-4o and DeepSeek-V3",
llm=llm
)
await agent.run()
asyncio.run(main())
This script initializes a ChatOllama
model and creates an Agent
object. The agent is configured to compare the prices of gpt-4o
and DeepSeek-V3
. It then runs the agent, which will interact with the model to perform the comparison.
from langchain_ollama import ChatOllama
llm = ChatOllama(
model="gemma3:4b",
temperature=1,
base_url="http://127.0.0.1:11434",
#Other args
)
messages = [
(
"system",
"You are a helpful assistant that translates English to French. Translate the user sentence.",
),
("human", "I love programming."),
]
ai_msg = llm.invoke(messages)
print(ai_msg)
This script demonstrates a simple translation task using ChatOllama
. It sets up a system message to define the assistant's role, provides a user sentence, and then invokes the model to translate the sentence. The translated message is then printed to the console.