From 044f599ae67bcb1d9b06d466b839fd7fa1fdf86a Mon Sep 17 00:00:00 2001 From: Akshay Priyadarshi Date: Fri, 10 Jan 2025 19:52:03 +0000 Subject: [PATCH] Update documentation Update documentation to use gemini, ollama, qwen --- customize/langchain-models.mdx | 132 ++++++++++++++++++++++++++++++++- 1 file changed, 128 insertions(+), 4 deletions(-) diff --git a/customize/langchain-models.mdx b/customize/langchain-models.mdx index c45fa98..988e698 100644 --- a/customize/langchain-models.mdx +++ b/customize/langchain-models.mdx @@ -108,13 +108,137 @@ AZURE_OPENAI_ENDPOINT=https://your-endpoint.openai.azure.com/ AZURE_OPENAI_KEY= ``` -## Coming soon +### Gemini +Get your API key from https://aistudio.google.com/apikey +Make sure to use browser-use>=0.1.18 + +And add the variable: + +```bash .env +GEMINI_API_KEY= +``` + +Subsequently, you can use the model as following: + +```python +import asyncio +import os + +from dotenv import load_dotenv +from langchain_google_genai import ChatGoogleGenerativeAI +from pydantic import SecretStr + +from browser_use import Agent + +load_dotenv() +api_key = os.getenv('GEMINI_API_KEY') +if not api_key: + raise ValueError('GEMINI_API_KEY is not set') + +llm = ChatGoogleGenerativeAI(model='gemini-2.0-flash-exp', api_key=SecretStr(api_key)) + + +async def run_search(): + agent = Agent( + task=( + 'Go to url r/LocalLLaMA subreddit and search for "browser use" in the search bar and click on the first post and find the funniest comment' + ), + llm=llm, + max_actions_per_step=4, + tool_call_in_content=False, + ) + + await agent.run(max_steps=25) + + +if __name__ == '__main__': + asyncio.run(run_search()) + +``` + +### Qwen + +Check [Qwen example](https://github.com/browser-use/browser-use/blob/main/examples/qwen.py) +```python +import asyncio +import os + +from langchain_ollama import ChatOllama + +from browser_use import Agent + + +async def run_search(): + 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=ChatOllama( + # model='qwen2.5:32b-instruct-q4_K_M', + # model='qwen2.5:14b', + model='qwen2.5:latest', + num_ctx=128000, + ), + max_actions_per_step=1, + tool_call_in_content=False, + ) + + await agent.run() + + +if __name__ == '__main__': + asyncio.run(run_search()) +``` + +### Ollama + +Check [llama example](https://github.com/browser-use/browser-use/blob/main/examples/ollama.py) + +```python +import os + +# Optional: Disable telemetry +# os.environ["ANONYMIZED_TELEMETRY"] = "false" + +# Optional: Set the OLLAMA host to a remote server +# os.environ["OLLAMA_HOST"] = "http://x.x.x.x:11434" + +import asyncio +from browser_use import Agent +from langchain_ollama import ChatOllama + + +async def run_search() -> str: + agent = Agent( + task="Search for a 'browser use' post on the r/LocalLLaMA subreddit and open it.", + llm=ChatOllama( + model="qwen2.5:32b-instruct-q4_K_M", + num_ctx=32000, + ), + ) + + result = await agent.run() + return result + + +async def main(): + result = await run_search() + print("\n\n", result) + + +if __name__ == "__main__": + asyncio.run(main()) +``` + +### granite3.1 + +Coming soon (Sorry, we are working on it) -- Gemini - Groq - DeepSeek - Github -- Ollama -- QWen