kpbotla commited on
Commit
6230b38
·
verified ·
1 Parent(s): c93f6ca

Upload 5 files

Browse files
tools/citation_tool.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import tool
2
+
3
+ @tool
4
+ class CiteTool:
5
+ name = "cite"
6
+ description = "Add citation to a given answer with a valid URL."
7
+
8
+ def use(self, input: str) -> str:
9
+ try:
10
+ answer, url = input.split("|||")
11
+ return f"{answer.strip()}\n\nSource: [{url.strip()}]({url.strip()})"
12
+ except:
13
+ return "Could not format citation correctly."
tools/fallback_tool.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import tool
2
+
3
+ @tool
4
+ class FallbackTool:
5
+ name = "fallback"
6
+ description = "Handle unanswerable or unclear queries."
7
+
8
+ def use(self, _: str) -> str:
9
+ return "I'm sorry, I couldn't find the answer to your question. Could you rephrase or try something else?"
tools/math_tool.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import tool
2
+
3
+ @tool
4
+ class PythonTool:
5
+ name = "python"
6
+ description = "Execute Python code to solve math problems."
7
+
8
+ def use(self, code: str) -> str:
9
+ try:
10
+ result = str(eval(code, {"__builtins__": {}}))
11
+ return f"Answer: {result}"
12
+ except Exception as e:
13
+ return f"Error: {str(e)}"
tools/search_tool.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import tool
2
+ from duckduckgo_search import DDGS
3
+
4
+ @tool
5
+ class WebSearchTool:
6
+ name = "web_search"
7
+ description = "Search the web for up-to-date factual information."
8
+
9
+ def use(self, query: str) -> str:
10
+ with DDGS() as ddgs:
11
+ results = ddgs.text(query)
12
+ output = []
13
+ for r in results[:3]:
14
+ output.append(f"{r['title']} - {r['href']}")
15
+ return "\n".join(output) if output else "No relevant results found."
tools/summarizer_tool.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import tool
2
+ from transformers import pipeline
3
+
4
+ summarizer = pipeline("summarization")
5
+
6
+ @tool
7
+ class SummarizerTool:
8
+ name = "summarize"
9
+ description = "Summarize a long text into a short paragraph."
10
+
11
+ def use(self, input: str) -> str:
12
+ if len(input) < 50:
13
+ return input
14
+ result = summarizer(input, max_length=100, min_length=25, do_sample=False)
15
+ return result[0]['summary_text']