kpbotla commited on
Commit
83ebbbc
·
verified ·
1 Parent(s): 79e6dea

Upload 5 files

Browse files
tools/citation_tool.py CHANGED
@@ -2,10 +2,13 @@ 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()})"
 
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()})"
tools/fallback_tool.py CHANGED
@@ -2,8 +2,11 @@ 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?"
 
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?"
tools/math_tool.py CHANGED
@@ -2,10 +2,13 @@ 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}"
 
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}"
tools/search_tool.py CHANGED
@@ -3,10 +3,13 @@ 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 = []
 
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 = []
tools/summarizer_tool.py CHANGED
@@ -5,10 +5,13 @@ 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)
 
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)