|
1 | 1 | from functools import partial |
2 | | -from os import environ as env |
| 2 | +from os import getenv |
3 | 3 | import typing as t |
4 | 4 |
|
5 | | -from browser_use import ChatGoogle, ChatOpenAI, ChatAnthropic |
| 5 | +from browser_use import ( |
| 6 | + ChatGoogle, |
| 7 | + ChatOpenAI, |
| 8 | + ChatAnthropic, |
| 9 | + ChatAzureOpenAI, |
| 10 | + ChatGroq, |
| 11 | + ChatOllama, |
| 12 | +) |
6 | 13 | from browser_use.llm import BaseChatModel |
7 | | -from google.genai.types import HttpOptions |
| 14 | +import orjson |
8 | 15 |
|
9 | | -ModelProvider = t.Literal["anthropic", "gemini", "openai"] |
| 16 | +__all__ = ["ModelProvider", "ChatFactory", "AGENT_INSTRUCTIONS"] |
| 17 | + |
| 18 | + |
| 19 | +ModelProvider = t.Literal[ |
| 20 | + "anthropic", "gemini", "openai", "azure_openai", "groq", "ollama" |
| 21 | +] |
10 | 22 |
|
11 | | -AI_GATEWAY_URL = env["AI_GATEWAY_URL"] |
12 | | -DEFAULT_HEADERS = { |
13 | | - "cf-aig-authorization": env["AI_GATEWAY_TOKEN"], |
14 | | -} |
| 23 | + |
| 24 | +def config(provider: ModelProvider) -> dict: |
| 25 | + return orjson.loads(getenv(f"{provider.upper()}_CONFIG", "{}")) |
15 | 26 |
|
16 | 27 |
|
17 | 28 | ChatFactory: dict[ModelProvider, t.Callable[[str, str], BaseChatModel]] = { |
18 | | - "gemini": partial( |
19 | | - ChatGoogle, |
20 | | - http_options=HttpOptions( |
21 | | - base_url=f"{AI_GATEWAY_URL}/google-ai-studio", |
22 | | - headers=DEFAULT_HEADERS, |
23 | | - ), |
24 | | - ), |
25 | | - "openai": partial( |
26 | | - ChatOpenAI, |
27 | | - base_url=f"{AI_GATEWAY_URL}/openai", |
28 | | - default_headers=DEFAULT_HEADERS, |
29 | | - ), |
30 | | - "anthropic": partial( |
31 | | - ChatAnthropic, |
32 | | - base_url=f"{AI_GATEWAY_URL}/anthropic", |
33 | | - default_headers=DEFAULT_HEADERS, |
34 | | - ), |
| 29 | + "gemini": partial(ChatGoogle, **config("gemini")), |
| 30 | + "openai": partial(ChatOpenAI, **config("openai")), |
| 31 | + "anthropic": partial(ChatAnthropic, **config("anthropic")), |
| 32 | + "azure-openai": partial(ChatAzureOpenAI, **config("azure_openai")), |
| 33 | + "groq": partial(ChatGroq, **config("groq")), |
| 34 | + "ollama": partial(ChatOllama, **config("ollama")), |
35 | 35 | } |
36 | 36 |
|
| 37 | + |
37 | 38 | AGENT_INSTRUCTIONS = """Remember, you are an agent - please keep going until the user's query is completely resolved, before ending your turn and yielding back to the user. Decompose the user's query into all required sub-requests, and confirm that each is completed. Do not stop after completing only part of the request. Only terminate your turn when you are sure that the problem is solved. You must be prepared to answer multiple queries and only finish the call once the user has confirmed they're done. |
38 | 39 |
|
39 | | -You must plan extensively in accordance with the workflow steps before making subsequent function calls, and reflect extensively on the outcomes each function call made, ensuring the user's query, and related sub-requests are completely resolved.""" |
| 40 | +You must plan extensively in accordance with the workflow steps before making subsequent function calls, and reflect extensively on the outcomes each function call made, ensuring the user's query, and related sub-requests are completely resolved. |
| 41 | +
|
| 42 | +Note that your browser will automatically: |
| 43 | +1. Download the PDF file upon viewing it. Just wait for it. You do not need to read the PDF. |
| 44 | +2. Solve CAPTCHAs or similar tests. Just wait for it.""" |
0 commit comments