Upload 2 files
Browse files
.env
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
SPACE_ID=ashishabraham22/Final_Assignment_Template
|
agents.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import asyncio
|
2 |
+
import os
|
3 |
+
import sys
|
4 |
+
import logging
|
5 |
+
import random
|
6 |
+
import pandas as pd
|
7 |
+
import requests
|
8 |
+
import wikipedia as wiki
|
9 |
+
from markdownify import markdownify as to_markdown
|
10 |
+
from typing import Any
|
11 |
+
from dotenv import load_dotenv
|
12 |
+
from smolagents import InferenceClientModel, LiteLLMModel, CodeAgent, ToolCallingAgent, Tool, DuckDuckGoSearchTool
|
13 |
+
|
14 |
+
load_dotenv()
|
15 |
+
|
16 |
+
class MathSolverTool(Tool):
|
17 |
+
name="MathSolver"
|
18 |
+
description="A tool to solve mathematical problems."
|
19 |
+
inputs={"input":{"type":"string", "description":"The mathematical problem to solve."}}
|
20 |
+
output_type="string"
|
21 |
+
def forward(self,input:str):
|
22 |
+
try:
|
23 |
+
return str(eval(input, {"__builtins__": {}}))
|
24 |
+
except Exception as e:
|
25 |
+
return f"Math error: {e}"
|
26 |
+
|
27 |
+
class WikiTitleFinder(Tool):
|
28 |
+
name = "wiki_titles"
|
29 |
+
description = "Search for related Wikipedia page titles."
|
30 |
+
inputs = {"query": {"type": "string", "description": "Search query."}}
|
31 |
+
output_type = "string"
|
32 |
+
|
33 |
+
def forward(self, query: str) -> str:
|
34 |
+
results = wiki.search(query)
|
35 |
+
return ", ".join(results) if results else "No results."
|
36 |
+
|
37 |
+
class WikiContentFetcher(Tool):
|
38 |
+
name = "wiki_page"
|
39 |
+
description = "Fetch Wikipedia page content."
|
40 |
+
inputs = {"page_title": {"type": "string", "description": "Wikipedia page title."}}
|
41 |
+
output_type = "string"
|
42 |
+
|
43 |
+
def forward(self, page_title: str) -> str:
|
44 |
+
try:
|
45 |
+
return to_markdown(wiki.page(page_title).html())
|
46 |
+
except wiki.exceptions.PageError:
|
47 |
+
return f"'{page_title}' not found."
|
48 |
+
|
49 |
+
|