pulkitme commited on
Commit
425dc2f
·
1 Parent(s): dddddce

simple smolagent with duck duck go search tool and youtube transcription tool

Browse files
Files changed (2) hide show
  1. app.py +33 -1
  2. test.ipynb +0 -0
app.py CHANGED
@@ -7,7 +7,39 @@ import time
7
  from google import genai
8
  from smolagents import Tool , CodeAgent, ToolCallingAgent, DuckDuckGoSearchTool, LiteLLMModel, PythonInterpreterTool, tool, DuckDuckGoSearchTool
9
  from langchain_community.document_loaders import YoutubeLoader
 
 
 
 
 
 
 
 
 
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  #client = genai.Client(api_key=os.getenv("API_KEY"))
13
  model = LiteLLMModel(model_id="gemini/gemini-2.0-flash-lite",
@@ -55,7 +87,7 @@ class BasicAgent:
55
  # )
56
 
57
  agent = CodeAgent(
58
- tools=[DuckDuckGoSearchTool(), youtube_transcription_tool],
59
  model=model,
60
  #additional_authorized_imports=["helium"],
61
  #step_callbacks=[save_screenshot],
 
7
  from google import genai
8
  from smolagents import Tool , CodeAgent, ToolCallingAgent, DuckDuckGoSearchTool, LiteLLMModel, PythonInterpreterTool, tool, DuckDuckGoSearchTool
9
  from langchain_community.document_loaders import YoutubeLoader
10
+ import re
11
+ import requests
12
+ from markdownify import markdownify
13
+ from requests.exceptions import RequestException
14
+
15
+
16
+ @tool
17
+ def visit_webpage(url: str) -> str:
18
+ """Visits a webpage at the given URL and returns its content as a markdown string.
19
 
20
+ Args:
21
+ url: The URL of the webpage to visit.
22
+
23
+ Returns:
24
+ The content of the webpage converted to Markdown, or an error message if the request fails.
25
+ """
26
+ try:
27
+ # Send a GET request to the URL
28
+ response = requests.get(url)
29
+ response.raise_for_status() # Raise an exception for bad status codes
30
+
31
+ # Convert the HTML content to Markdown
32
+ markdown_content = markdownify(response.text).strip()
33
+
34
+ # Remove multiple line breaks
35
+ markdown_content = re.sub(r"\n{3,}", "\n\n", markdown_content)
36
+
37
+ return markdown_content
38
+
39
+ except RequestException as e:
40
+ return f"Error fetching the webpage: {str(e)}"
41
+ except Exception as e:
42
+ return f"An unexpected error occurred: {str(e)}"
43
 
44
  #client = genai.Client(api_key=os.getenv("API_KEY"))
45
  model = LiteLLMModel(model_id="gemini/gemini-2.0-flash-lite",
 
87
  # )
88
 
89
  agent = CodeAgent(
90
+ tools=[DuckDuckGoSearchTool(), youtube_transcription_tool, visit_webpage],
91
  model=model,
92
  #additional_authorized_imports=["helium"],
93
  #step_callbacks=[save_screenshot],
test.ipynb CHANGED
The diff for this file is too large to render. See raw diff