Spaces:
Sleeping
Sleeping
Update app.py - added deepresearch tool and other premade tools
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ from Gradio_UI import GradioUI
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
"""A tool that does nothing yet
|
| 15 |
Args:
|
|
@@ -33,6 +33,28 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
model = HfApiModel(
|
|
@@ -51,7 +73,14 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 51 |
|
| 52 |
agent = CodeAgent(
|
| 53 |
model=model,
|
| 54 |
-
tools=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
max_steps=6,
|
| 56 |
verbosity_level=1,
|
| 57 |
grammar=None,
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
"""A tool that does nothing yet
|
| 15 |
Args:
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
+
@tool
|
| 37 |
+
def deepresearch(query: str, depth: int = 2) -> str:
|
| 38 |
+
"""A tool that performs deep research on a given topic using iterative searches.
|
| 39 |
+
Args:
|
| 40 |
+
query: The research query topic.
|
| 41 |
+
depth: The number of iterative search steps to perform (default is 2).
|
| 42 |
+
"""
|
| 43 |
+
research_results = []
|
| 44 |
+
# Perform the initial search with the provided query
|
| 45 |
+
initial_result = DuckDuckGoSearchTool(query)
|
| 46 |
+
research_results.append(f"Initial search:\n{initial_result}")
|
| 47 |
+
|
| 48 |
+
# If a deeper level of research is requested, perform additional searches
|
| 49 |
+
for i in range(1, depth):
|
| 50 |
+
#Modify the query slightly for additional detail
|
| 51 |
+
detailed_query = f"{query} analysis part {i}"
|
| 52 |
+
detailed_result = DuckDuckGoSearchTool(detailed_query)
|
| 53 |
+
research_results.append(f"Additional research (iteration {i}:\n{detailed_result}")
|
| 54 |
+
|
| 55 |
+
# Aggregate all the search results into one comprehensive answer
|
| 56 |
+
aggregated_results = "\n\n".join(research_results)
|
| 57 |
+
return f"Deep research results for '{query}':\n{aggregated_results}"
|
| 58 |
|
| 59 |
final_answer = FinalAnswerTool()
|
| 60 |
model = HfApiModel(
|
|
|
|
| 73 |
|
| 74 |
agent = CodeAgent(
|
| 75 |
model=model,
|
| 76 |
+
tools=[
|
| 77 |
+
final_answer,
|
| 78 |
+
DuckDuckGoSearchTool,
|
| 79 |
+
image_generation_tool,
|
| 80 |
+
my_custom_tool,
|
| 81 |
+
get_current_time_in_timezone
|
| 82 |
+
deepresearch
|
| 83 |
+
], ## add your tools here (don't remove final answer)
|
| 84 |
max_steps=6,
|
| 85 |
verbosity_level=1,
|
| 86 |
grammar=None,
|