bstraehle commited on
Commit
83a618d
·
verified ·
1 Parent(s): bba2ec8

Update tools/ai_tools.py

Browse files
Files changed (1) hide show
  1. tools/ai_tools.py +28 -0
tools/ai_tools.py CHANGED
@@ -48,6 +48,34 @@ class AITools():
48
  return response.text
49
  except Exception as e:
50
  raise RuntimeError(f"Processing failed: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
  @tool("Image Analysis Tool")
53
  def image_analysis_tool(question: str, file_path: str) -> str:
 
48
  return response.text
49
  except Exception as e:
50
  raise RuntimeError(f"Processing failed: {str(e)}")
51
+
52
+ @tool("Web Browser Tool")
53
+ def web_browser_tool(question: str, url: str) -> str:
54
+ """Given a question only, search the web to answer the question.
55
+
56
+ Args:
57
+ question (str): Question to answer
58
+
59
+ Returns:
60
+ str: Answer to the question
61
+
62
+ Raises:
63
+ RuntimeError: If processing fails"""
64
+ try:
65
+ stagehand_tool = StagehandTool(
66
+ api_key=os.environ["BROWSERBASE_API_KEY"],
67
+ project_id=os.environ["BROWSERBASE_PROJECT_ID"],
68
+ model_api_key=os.environ["ANTHROPIC_API_KEY"],
69
+ model_name=AvailableModel.CLAUDE_3_7_SONNET_LATEST
70
+ )
71
+
72
+ return result = stagehand_tool.run(
73
+ instruction=question,
74
+ url=url,
75
+ command_type="act"
76
+ )
77
+ except Exception as e:
78
+ raise RuntimeError(f"Processing failed: {str(e)}")
79
 
80
  @tool("Image Analysis Tool")
81
  def image_analysis_tool(question: str, file_path: str) -> str: