|
| 1 | +""" |
| 2 | +To Use it: |
| 3 | +
|
| 4 | +Example 1: Using OpenAI (default), with default task: 'go to reddit and search for posts about browser-use' |
| 5 | +python command_line.py |
| 6 | +
|
| 7 | +Example 2: Using OpenAI with a Custom Query |
| 8 | +python command_line.py --query "go to google and search for browser-use" |
| 9 | +
|
| 10 | +Example 3: Using Anthropic's Claude Model with a Custom Query |
| 11 | +python command_line.py --query "find latest Python tutorials on Medium" --provider anthropic |
| 12 | +
|
| 13 | +""" |
1 | 14 | import os
|
2 | 15 | import sys
|
3 | 16 | import argparse
|
|
6 | 19 | # Ensure local repository (browser_use) is accessible
|
7 | 20 | sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
8 | 21 |
|
9 |
| -# Third-party imports |
10 |
| -from langchain_openai import ChatOpenAI |
| 22 | +from dotenv import load_dotenv |
11 | 23 |
|
12 |
| -# Local module imports |
13 | 24 | from browser_use import Agent
|
14 | 25 | from browser_use.browser.browser import Browser, BrowserConfig
|
15 | 26 | from browser_use.controller.service import Controller
|
16 | 27 |
|
17 | 28 |
|
| 29 | +load_dotenv() |
| 30 | + |
18 | 31 | def get_llm(provider: str):
|
19 | 32 | if provider == 'anthropic':
|
20 | 33 | from langchain_anthropic import ChatAnthropic
|
| 34 | + api_key = os.getenv("ANTHROPIC_API_KEY") |
| 35 | + if not api_key: |
| 36 | + raise ValueError("Error: ANTHROPIC_API_KEY is not set. Please provide a valid API key.") |
| 37 | + |
21 | 38 | return ChatAnthropic(
|
22 | 39 | model_name='claude-3-5-sonnet-20240620', timeout=25, stop=None, temperature=0.0
|
23 | 40 | )
|
24 | 41 | elif provider == 'openai':
|
| 42 | + from langchain_openai import ChatOpenAI |
| 43 | + api_key = os.getenv("OPENAI_API_KEY") |
| 44 | + if not api_key: |
| 45 | + raise ValueError("Error: OPENAI_API_KEY is not set. Please provide a valid API key.") |
| 46 | + |
25 | 47 | return ChatOpenAI(model='gpt-4o', temperature=0.0)
|
26 | 48 |
|
27 | 49 | else:
|
|
0 commit comments