Created
April 11, 2025 04:41
-
-
Save cyysky/595c459b62dd6a34013f85e118e25a73 to your computer and use it in GitHub Desktop.
Revisions
-
cyysky created this gist
Apr 11, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,77 @@ # Browser-use: Connecting AI Agents with the Browser 🌐 Browser-use is the easiest way to connect your AI agents with the browser. With pip (Python>=3.11): ```bash pip install browser-use ``` Install Playwright: ```bash playwright install chromium ``` ## Getting Started This project demonstrates a simple example of using `browser-use` to interact with an AI model. ### Requirements * Python 3.11 or higher * `browser-use` * Playwright (Chromium) ## Example Usage The following code demonstrates a basic example: ### `browser_agent.py` ```python src/main.py 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. ### `langchain_ollama_sample.py` ```python langchain_ollama_sample.py (1-17) 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.