Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion autosurfer/agent/brain/task_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from autosurfer.agent.brain.memory import AgentMemory
from typing import Dict, Any, Optional

llm = get_llm_client("openai")
from autosurfer.config import Config

llm = get_llm_client(getattr(Config, "LLM_PROVIDER", "openai"))


def next_action(objective: str, ui_elements: list, memory: Optional[AgentMemory] = None, page_context: Optional[Dict[str, Any]] = None) -> NextActions:
Expand Down
2 changes: 2 additions & 0 deletions autosurfer/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Config:
OS = "unknown"

OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
ANTHROPIC_API_KEY = os.getenv("ANTHROPIC_API_KEY")
LLM_PROVIDER = os.getenv("LLM_PROVIDER", "openai")

# BrowserBase configuration
BROWSERBASE_API_KEY = os.getenv("BROWSERBASE_API_KEY")
Expand Down
13 changes: 13 additions & 0 deletions autosurfer/llm/claude_provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from langchain_anthropic import ChatAnthropic
from autosurfer.config import Config
from autosurfer.llm.response_schema.browser_actions import NextActions

def get_claude_client():
if not Config.ANTHROPIC_API_KEY:
raise ValueError("ANTHROPIC_API_KEY environment variable is required")

anthropic_model = ChatAnthropic(
model="claude-3-7-sonnet-20250219",
temperature=0,
)
return anthropic_model.with_structured_output(NextActions)
8 changes: 7 additions & 1 deletion autosurfer/llm/client.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from langchain_openai import ChatOpenAI
from autosurfer.config import Config
from autosurfer.llm.response_schema.browser_actions import NextActions
from autosurfer.llm.claude_provider import get_claude_client
from langchain_core.utils import get_from_env


def get_llm_client(client):
def get_llm_client(client=None):
if client is None:
client = getattr(Config, "LLM_PROVIDER", "openai")

if client == "openai":
if not Config.OPENAI_API_KEY:
raise ValueError("OPENAI_API_KEY environment variable is required")
Expand All @@ -14,5 +18,7 @@ def get_llm_client(client):
temperature=0,
)
return openai_model.with_structured_output(NextActions)
elif client in ["anthropic", "claude"]:
return get_claude_client()
else:
raise ValueError(f"Unsupported LLM client: {client}")
11 changes: 11 additions & 0 deletions create_pr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import urllib.request, json, os, ssl, shutil
ctx = ssl.create_default_context(); ctx.check_hostname = False; ctx.verify_mode = ssl.CERT_NONE
token = os.environ.get("GITHUB_TOKEN")
payload = {"title": "Fix for issue #12", "body": "Closes #12\n\nImplemented automated fix.", "head": "KartavyaDikshit:fix-issue-12", "base": "main"}
req = urllib.request.Request("https://api.github.com/repos/developeranku/AutoSurfer/pulls", data=json.dumps(payload).encode(), headers={'Authorization': f'token {token}', 'Accept': 'application/vnd.github.v3+json', 'Content-Type': 'application/json'}, method='POST')
try:
with urllib.request.urlopen(req, context=ctx) as r:
print("[+] PR Created:", json.loads(r.read())['html_url'])
os.chdir("..")
shutil.rmtree("/Users/kartavyadikshit/Projects/Open Source/AutoSurfer_bounty_parallel_1", ignore_errors=True)
except Exception as e: print("[!] PR Failed:", e)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ requires-python = ">=3.11"
dependencies = [
"browserbase>=1.4.0",
"langchain>=0.3.25",
"langchain-anthropic>=0.3.0",
"langchain-community>=0.3.25",
"langchain-openai>=0.3.22",
"mss>=10.0.0",
Expand Down