kpbotla commited on
Commit
538b711
·
verified ·
1 Parent(s): 792b439

Upload 5 files

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