Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,28 +4,35 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
-
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
# Below is an example of a tool that does nothing. Amaze us with your creativity!
|
| 11 |
-
|
| 12 |
# Define a custom tool using the @tool decorator
|
| 13 |
@tool
|
| 14 |
def my_custom_tool(arg1: str, arg2: int) -> str:
|
| 15 |
"""
|
| 16 |
-
|
| 17 |
|
| 18 |
Args:
|
| 19 |
-
arg1: Questions about working with and as a Virtual Assistant. (
|
| 20 |
arg2: 200 characters.
|
| 21 |
"""
|
| 22 |
return f"Processed {arg1} with value {arg2}"
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
try:
|
| 27 |
-
#
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
# Extract relevant information from the search results
|
| 31 |
if search_results:
|
|
@@ -37,7 +44,6 @@ web_search_tool = DuckDuckGoSearchTool(arg1)
|
|
| 37 |
except Exception as e:
|
| 38 |
return f"An error occurred while searching: {str(e)}"
|
| 39 |
|
| 40 |
-
|
| 41 |
@tool
|
| 42 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 43 |
"""A tool that fetches the current local time in a specified timezone.
|
|
@@ -53,33 +59,21 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 53 |
except Exception as e:
|
| 54 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 55 |
|
| 56 |
-
|
| 57 |
final_answer = FinalAnswerTool()
|
| 58 |
model = HfApiModel(
|
| 59 |
-
max_tokens=2096,
|
| 60 |
-
temperature=0.5,
|
| 61 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 62 |
-
custom_role_conversions=None,
|
| 63 |
)
|
| 64 |
|
| 65 |
-
|
| 66 |
# Import tool from Hub
|
| 67 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 68 |
|
| 69 |
with open("prompts.yaml", 'r') as stream:
|
| 70 |
prompt_templates = yaml.safe_load(stream)
|
| 71 |
-
|
| 72 |
agent = CodeAgent(
|
| 73 |
model=model,
|
| 74 |
-
tools=[final_answer],
|
| 75 |
-
max_steps=6
|
| 76 |
-
verbosity_level=1,
|
| 77 |
-
grammar=None,
|
| 78 |
-
planning_interval=None,
|
| 79 |
-
name=None,
|
| 80 |
-
description=None,
|
| 81 |
-
prompt_templates=prompt_templates
|
| 82 |
-
)
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
GradioUI(agent).launch()
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 7 |
from Gradio_UI import GradioUI
|
| 8 |
|
|
|
|
|
|
|
| 9 |
# Define a custom tool using the @tool decorator
|
| 10 |
@tool
|
| 11 |
def my_custom_tool(arg1: str, arg2: int) -> str:
|
| 12 |
"""
|
| 13 |
+
A tool that answers customers' queries on working with and as a Virtual Assistant by searching the web and producing a snippet of the first web result in line with parameter arg2.
|
| 14 |
|
| 15 |
Args:
|
| 16 |
+
arg1: Questions about working with and as a Virtual Assistant. (For example; Why should I hire a Virtual Assistant?, What courses do I need to complete to become a Virtual Assistant?)
|
| 17 |
arg2: 200 characters.
|
| 18 |
"""
|
| 19 |
return f"Processed {arg1} with value {arg2}"
|
| 20 |
|
| 21 |
+
# Define the FAQ bot tool using web search
|
| 22 |
+
@tool
|
| 23 |
+
def faq_bot_tool(query: str) -> str:
|
| 24 |
+
"""
|
| 25 |
+
A tool that answers frequently asked questions about virtual assistants by searching the web.
|
| 26 |
+
|
| 27 |
+
Args:
|
| 28 |
+
query: The question asked by the user.
|
| 29 |
+
"""
|
| 30 |
try:
|
| 31 |
+
# Initialize the web search tool
|
| 32 |
+
web_search_tool = DuckDuckGoSearchTool()
|
| 33 |
+
|
| 34 |
+
# Perform a web search using the query
|
| 35 |
+
search_results = web_search_tool.search(query)
|
| 36 |
|
| 37 |
# Extract relevant information from the search results
|
| 38 |
if search_results:
|
|
|
|
| 44 |
except Exception as e:
|
| 45 |
return f"An error occurred while searching: {str(e)}"
|
| 46 |
|
|
|
|
| 47 |
@tool
|
| 48 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 49 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 59 |
except Exception as e:
|
| 60 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 61 |
|
|
|
|
| 62 |
final_answer = FinalAnswerTool()
|
| 63 |
model = HfApiModel(
|
| 64 |
+
max_tokens=2096,
|
| 65 |
+
temperature=0.5,
|
| 66 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 67 |
+
custom_role_conversions=None,
|
| 68 |
)
|
| 69 |
|
|
|
|
| 70 |
# Import tool from Hub
|
| 71 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 72 |
|
| 73 |
with open("prompts.yaml", 'r') as stream:
|
| 74 |
prompt_templates = yaml.safe_load(stream)
|
| 75 |
+
|
| 76 |
agent = CodeAgent(
|
| 77 |
model=model,
|
| 78 |
+
tools=[final_answer, faq_bot_tool], # Add the FAQ bot tool here
|
| 79 |
+
max_steps=6
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|