Add exceptions for when the list of tools is not available.
Browse files
app.py
CHANGED
@@ -27,13 +27,16 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
27 |
## https://huggingface.co/spaces/DenverJones/First_agent_template/blob/main/app.py ## randomly select a Motivational Quote
|
28 |
|
29 |
@tool
|
30 |
-
def available_tools()-> str:
|
31 |
-
#Keep this format for the description / args / args description but feel free to modify the tool
|
32 |
"""A tool that takes no arguments but returns a list of tools available to the agent
|
33 |
Args:
|
34 |
None
|
35 |
"""
|
36 |
-
|
|
|
|
|
|
|
|
|
37 |
|
38 |
|
39 |
@tool
|
@@ -65,9 +68,14 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
65 |
except Exception as e:
|
66 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
67 |
|
68 |
-
|
69 |
final_answer = FinalAnswerTool()
|
70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
MODEL_IDS = [
|
72 |
#'https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud/',
|
73 |
#'https://jc26mwg228mkj8dw.us-east-1.aws.endpoints.huggingface.cloud/',
|
@@ -118,17 +126,12 @@ model = HfApiModel(
|
|
118 |
custom_role_conversions=None,
|
119 |
)
|
120 |
|
121 |
-
# Import tool from Hub
|
122 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True) ## https://huggingface.co/spaces/agents-course/text-to-image
|
123 |
-
|
124 |
with open("prompts.yaml", 'r') as stream:
|
125 |
prompt_templates = yaml.safe_load(stream)
|
126 |
|
127 |
-
tool_list = [final_answer, get_current_time_in_timezone, image_generation_tool, toss_a_die, available_tools]
|
128 |
-
|
129 |
agent = CodeAgent(
|
130 |
model=model,
|
131 |
-
tools=tool_list, ## add your tools here (don't remove final answer)
|
132 |
max_steps=6,
|
133 |
verbosity_level=1,
|
134 |
grammar=None,
|
@@ -138,5 +141,4 @@ agent = CodeAgent(
|
|
138 |
prompt_templates=prompt_templates
|
139 |
)
|
140 |
|
141 |
-
|
142 |
GradioUI(agent).launch()
|
|
|
27 |
## https://huggingface.co/spaces/DenverJones/First_agent_template/blob/main/app.py ## randomly select a Motivational Quote
|
28 |
|
29 |
@tool
|
30 |
+
def available_tools()-> str:
|
|
|
31 |
"""A tool that takes no arguments but returns a list of tools available to the agent
|
32 |
Args:
|
33 |
None
|
34 |
"""
|
35 |
+
try:
|
36 |
+
result = [f.name for f in tool_list]
|
37 |
+
return result
|
38 |
+
except Exception as e:
|
39 |
+
return "I do not have a list of tools that I can share."
|
40 |
|
41 |
|
42 |
@tool
|
|
|
68 |
except Exception as e:
|
69 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
70 |
|
|
|
71 |
final_answer = FinalAnswerTool()
|
72 |
|
73 |
+
# Import tool from Hub
|
74 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True) ## https://huggingface.co/spaces/agents-course/text-to-image
|
75 |
+
|
76 |
+
# Create a list of the tools available to the agent
|
77 |
+
#tool_list = [final_answer, get_current_time_in_timezone, image_generation_tool, toss_a_die, available_tools]
|
78 |
+
|
79 |
MODEL_IDS = [
|
80 |
#'https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud/',
|
81 |
#'https://jc26mwg228mkj8dw.us-east-1.aws.endpoints.huggingface.cloud/',
|
|
|
126 |
custom_role_conversions=None,
|
127 |
)
|
128 |
|
|
|
|
|
|
|
129 |
with open("prompts.yaml", 'r') as stream:
|
130 |
prompt_templates = yaml.safe_load(stream)
|
131 |
|
|
|
|
|
132 |
agent = CodeAgent(
|
133 |
model=model,
|
134 |
+
tools=[final_answer, get_current_time_in_timezone, image_generation_tool, toss_a_die, available_tools] #tool_list, ## add your tools here (don't remove final answer)
|
135 |
max_steps=6,
|
136 |
verbosity_level=1,
|
137 |
grammar=None,
|
|
|
141 |
prompt_templates=prompt_templates
|
142 |
)
|
143 |
|
|
|
144 |
GradioUI(agent).launch()
|