Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,21 +11,21 @@ from tools.web_search import DuckDuckGoSearchTool
|
|
| 11 |
|
| 12 |
from Gradio_UI import GradioUI
|
| 13 |
|
| 14 |
-
# Example
|
| 15 |
@tool
|
| 16 |
def my_custom_tool(arg1: str, arg2: int) -> str:
|
| 17 |
-
"""A tool
|
| 18 |
|
| 19 |
Args:
|
| 20 |
-
arg1:
|
| 21 |
-
arg2:
|
| 22 |
"""
|
| 23 |
return "What magic will you build ?"
|
| 24 |
|
| 25 |
-
#
|
| 26 |
@tool
|
| 27 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 28 |
-
"""
|
| 29 |
|
| 30 |
Args:
|
| 31 |
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
|
@@ -37,21 +37,21 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 37 |
except Exception as e:
|
| 38 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 39 |
|
| 40 |
-
# Instantiate the FinalAnswerTool (required)
|
| 41 |
final_answer = FinalAnswerTool()
|
| 42 |
|
| 43 |
-
#
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
# Instantiate local tools for web search and webpage visits
|
| 47 |
search_tool = DuckDuckGoSearchTool() # Defined in tools/web_search.py
|
|
|
|
|
|
|
| 48 |
visit_tool = VisitWebpageTool() # Defined in tools/visit_webpage.py
|
| 49 |
|
| 50 |
# Define the model configuration using HfApiModel
|
| 51 |
model = HfApiModel(
|
| 52 |
max_tokens=2096,
|
| 53 |
temperature=0.5,
|
| 54 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct', #
|
| 55 |
custom_role_conversions=None,
|
| 56 |
)
|
| 57 |
|
|
@@ -59,16 +59,15 @@ model = HfApiModel(
|
|
| 59 |
with open("prompts.yaml", 'r') as stream:
|
| 60 |
prompt_templates = yaml.safe_load(stream)
|
| 61 |
|
| 62 |
-
# Create the CodeAgent, including
|
| 63 |
agent = CodeAgent(
|
| 64 |
model=model,
|
| 65 |
tools=[
|
| 66 |
final_answer, # Must remain included.
|
| 67 |
search_tool, # Enables web search.
|
| 68 |
visit_tool, # Enables webpage visits.
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
image_generation_tool # Enables image generation via a Hub tool.
|
| 72 |
],
|
| 73 |
max_steps=6,
|
| 74 |
verbosity_level=1,
|
|
|
|
| 11 |
|
| 12 |
from Gradio_UI import GradioUI
|
| 13 |
|
| 14 |
+
# Example Tool (non-functioning): provided purely as a template.
|
| 15 |
@tool
|
| 16 |
def my_custom_tool(arg1: str, arg2: int) -> str:
|
| 17 |
+
"""Example Tool: A non-functional tool provided as a template.
|
| 18 |
|
| 19 |
Args:
|
| 20 |
+
arg1: The first argument.
|
| 21 |
+
arg2: The second argument.
|
| 22 |
"""
|
| 23 |
return "What magic will you build ?"
|
| 24 |
|
| 25 |
+
# Working Tool: Fetches the current local time in a specified timezone.
|
| 26 |
@tool
|
| 27 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 28 |
+
"""Working Tool: Fetches the current local time in a specified timezone.
|
| 29 |
|
| 30 |
Args:
|
| 31 |
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
|
|
|
| 37 |
except Exception as e:
|
| 38 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 39 |
|
| 40 |
+
# Instantiate the FinalAnswerTool (required for returning final answers)
|
| 41 |
final_answer = FinalAnswerTool()
|
| 42 |
|
| 43 |
+
# Instantiate working local tools:
|
| 44 |
+
# Web Search Tool: Uses DuckDuckGo to perform a web search.
|
|
|
|
|
|
|
| 45 |
search_tool = DuckDuckGoSearchTool() # Defined in tools/web_search.py
|
| 46 |
+
|
| 47 |
+
# Webpage Visit Tool: Visits a URL and converts its content to Markdown.
|
| 48 |
visit_tool = VisitWebpageTool() # Defined in tools/visit_webpage.py
|
| 49 |
|
| 50 |
# Define the model configuration using HfApiModel
|
| 51 |
model = HfApiModel(
|
| 52 |
max_tokens=2096,
|
| 53 |
temperature=0.5,
|
| 54 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # Adjust if this model is overloaded.
|
| 55 |
custom_role_conversions=None,
|
| 56 |
)
|
| 57 |
|
|
|
|
| 59 |
with open("prompts.yaml", 'r') as stream:
|
| 60 |
prompt_templates = yaml.safe_load(stream)
|
| 61 |
|
| 62 |
+
# Create the CodeAgent, including our working tools and the example tool.
|
| 63 |
agent = CodeAgent(
|
| 64 |
model=model,
|
| 65 |
tools=[
|
| 66 |
final_answer, # Must remain included.
|
| 67 |
search_tool, # Enables web search.
|
| 68 |
visit_tool, # Enables webpage visits.
|
| 69 |
+
get_current_time_in_timezone, # Working tool for time queries.
|
| 70 |
+
my_custom_tool, # Example (non-functioning) tool.
|
|
|
|
| 71 |
],
|
| 72 |
max_steps=6,
|
| 73 |
verbosity_level=1,
|