File size: 2,306 Bytes
400d942
 
 
 
 
 
 
 
 
 
 
63f4142
400d942
 
 
 
 
63f4142
400d942
 
63f4142
400d942
 
 
 
63f4142
400d942
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63f4142
400d942
 
 
 
 
63f4142
400d942
 
63f4142
400d942
 
 
 
 
 
 
63f4142
 
400d942
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import re
import requests
from markdownify import markdownify
from requests.exceptions import RequestException
from smolagents import CodeAgent, DuckDuckGoSearchTool, FinalAnswerTool, HfApiModel, Tool, tool, VisitWebpageTool, ToolCallingAgent, LiteLLMModel
from huggingface_hub import login
import os
import openai

os.environ['SAMBANOVA_API_KEY'] = os.getenv('sambanova_token')
model = LiteLLMModel(
    model_id="sambanova/Qwen2.5-Coder-32B-Instruct",
    max_tokens=2096,
    temperature=0.1,
    num_ctx=8192
)

# Creating a tool for visiting web pages
class WebpageVisitorTool(Tool):
    name = "webpage_visitor"
    description = "This tool visits a web page and returns its content in Markdown format."

    inputs = {
        "url": {
            "type": "string",
            "description": "URL of the web page to visit.",
        }
    }

    output_type = "string"

    def forward(self, url: str) -> str:
        try:
            # Send a GET request to the URL
            response = requests.get(url)
            response.raise_for_status()  # Raise an exception for bad status codes

            # Convert the HTML content to Markdown
            markdown_content = markdownify(response.text).strip()

            # Remove multiple line breaks
            markdown_content = re.sub(r"\n{3,}", "\n\n", markdown_content)

            return markdown_content

        except RequestException as e:
            return f"Error fetching the webpage: {str(e)}"
        except Exception as e:
            return f"An unexpected error occurred: {str(e)}"

# Creating a web agent
web_agent = CodeAgent(
    tools=[DuckDuckGoSearchTool(), WebpageVisitorTool()],
    model=model,
    max_steps=10,
    name="web_search_agent",
    description="Performs web search"
)

# Creating a manager agent
manager_agent = CodeAgent(
    tools=[],
    model=model,
    managed_agents=[web_agent],
    additional_authorized_imports=["time", "numpy", "pandas"]
)

# Running the system
answer = manager_agent.run("If language model training continues to scale at the current pace until 2030, what will be the electrical power consumption in GW required to power the largest training runs by 2030? What would this correspond to, compared to some countries? Please provide a source for any numbers used.")
print(answer)