Skip to content

Instantly share code, notes, and snippets.

@hoyin258
Created February 10, 2025 16:03
Show Gist options
  • Save hoyin258/581a03fc8ea347f6ec59102fd0ce406c to your computer and use it in GitHub Desktop.
Save hoyin258/581a03fc8ea347f6ec59102fd0ce406c to your computer and use it in GitHub Desktop.
How to setup local python env + run ollama+qwen+browser-use

Background

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

Setup Python env

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

Setup Ollama

Go to Ollama website https://ollama.com/download

Download the installer https://ollama.com/download/OllamaSetup.exe

Start Local AI Model

Open the terminal

Start ollama

ollama serve

Pull AI model

ollama pull qwen2.5:7b

Check AI model installed

ollama list

Install required program stuff

pip install browser-use
pip install langchain_ollama
playwright install

Create Python program

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

Appendix

For other model https://docs.browser-use.com/customize/supported-models#supported-models

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment