Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- tools/citation_tool.py +9 -1
- tools/fallback_tool.py +9 -1
- tools/math_tool.py +9 -1
- tools/search_tool.py +9 -1
- tools/summarizer_tool.py +9 -1
tools/citation_tool.py
CHANGED
|
@@ -2,7 +2,15 @@ from smolagents import tool
|
|
| 2 |
|
| 3 |
@tool
|
| 4 |
def cite(input: str) -> str:
|
| 5 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
try:
|
| 7 |
answer, url = input.split("|||")
|
| 8 |
return f"{answer.strip()}\n\nSource: [{url.strip()}]({url.strip()})"
|
|
|
|
| 2 |
|
| 3 |
@tool
|
| 4 |
def cite(input: str) -> str:
|
| 5 |
+
"""
|
| 6 |
+
Takes input as 'answer ||| url' and formats a markdown citation.
|
| 7 |
+
|
| 8 |
+
Args:
|
| 9 |
+
input (str): Combined answer and URL separated by '|||'.
|
| 10 |
+
|
| 11 |
+
Returns:
|
| 12 |
+
str: Formatted citation string with markdown link.
|
| 13 |
+
"""
|
| 14 |
try:
|
| 15 |
answer, url = input.split("|||")
|
| 16 |
return f"{answer.strip()}\n\nSource: [{url.strip()}]({url.strip()})"
|
tools/fallback_tool.py
CHANGED
|
@@ -2,5 +2,13 @@ from smolagents import tool
|
|
| 2 |
|
| 3 |
@tool
|
| 4 |
def fallback(_: str) -> str:
|
| 5 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
return "I'm sorry, I couldn't find the answer to your question. Could you rephrase or try something else?"
|
|
|
|
| 2 |
|
| 3 |
@tool
|
| 4 |
def fallback(_: str) -> str:
|
| 5 |
+
"""
|
| 6 |
+
Returns a polite fallback message when no specific tool applies.
|
| 7 |
+
|
| 8 |
+
Args:
|
| 9 |
+
_ (str): Unused input string.
|
| 10 |
+
|
| 11 |
+
Returns:
|
| 12 |
+
str: Default fallback response.
|
| 13 |
+
"""
|
| 14 |
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,7 +2,15 @@ from smolagents import tool
|
|
| 2 |
|
| 3 |
@tool
|
| 4 |
def python(code: str) -> str:
|
| 5 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
try:
|
| 7 |
result = str(eval(code, {"__builtins__": {}}))
|
| 8 |
return f"Answer: {result}"
|
|
|
|
| 2 |
|
| 3 |
@tool
|
| 4 |
def python(code: str) -> str:
|
| 5 |
+
"""
|
| 6 |
+
Evaluates a math expression using sandboxed eval.
|
| 7 |
+
|
| 8 |
+
Args:
|
| 9 |
+
code (str): A simple Python expression to evaluate.
|
| 10 |
+
|
| 11 |
+
Returns:
|
| 12 |
+
str: The result of the evaluation or error message.
|
| 13 |
+
"""
|
| 14 |
try:
|
| 15 |
result = str(eval(code, {"__builtins__": {}}))
|
| 16 |
return f"Answer: {result}"
|
tools/search_tool.py
CHANGED
|
@@ -3,7 +3,15 @@ from duckduckgo_search import DDGS
|
|
| 3 |
|
| 4 |
@tool
|
| 5 |
def web_search(query: str) -> str:
|
| 6 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
with DDGS() as ddgs:
|
| 8 |
results = ddgs.text(query)
|
| 9 |
output = [f"{r['title']} - {r['href']}" for r in results[:3]]
|
|
|
|
| 3 |
|
| 4 |
@tool
|
| 5 |
def web_search(query: str) -> str:
|
| 6 |
+
"""
|
| 7 |
+
Returns top search results for a given query.
|
| 8 |
+
|
| 9 |
+
Args:
|
| 10 |
+
query (str): The search string.
|
| 11 |
+
|
| 12 |
+
Returns:
|
| 13 |
+
str: Top search results from DuckDuckGo.
|
| 14 |
+
"""
|
| 15 |
with DDGS() as ddgs:
|
| 16 |
results = ddgs.text(query)
|
| 17 |
output = [f"{r['title']} - {r['href']}" for r in results[:3]]
|
tools/summarizer_tool.py
CHANGED
|
@@ -5,7 +5,15 @@ summarizer = pipeline("summarization")
|
|
| 5 |
|
| 6 |
@tool
|
| 7 |
def summarize(input: str) -> str:
|
| 8 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
if len(input) < 50:
|
| 10 |
return input
|
| 11 |
result = summarizer(input, max_length=100, min_length=25, do_sample=False)
|
|
|
|
| 5 |
|
| 6 |
@tool
|
| 7 |
def summarize(input: str) -> str:
|
| 8 |
+
"""
|
| 9 |
+
Returns a summarized version of the input text.
|
| 10 |
+
|
| 11 |
+
Args:
|
| 12 |
+
input (str): The text to be summarized.
|
| 13 |
+
|
| 14 |
+
Returns:
|
| 15 |
+
str: Concise summary of the input.
|
| 16 |
+
"""
|
| 17 |
if len(input) < 50:
|
| 18 |
return input
|
| 19 |
result = summarizer(input, max_length=100, min_length=25, do_sample=False)
|