Spaces:
Runtime error
Runtime error
Duygu Jones
commited on
Update app.py
Browse filestools output improvement
app.py
CHANGED
@@ -21,48 +21,62 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
21 |
|
22 |
@tool
|
23 |
def tavily_search(query: str) -> str:
|
24 |
-
"""A tool that performs web search using Tavily API
|
25 |
Args:
|
26 |
query: The search query to look up
|
|
|
|
|
27 |
"""
|
28 |
try:
|
29 |
client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])
|
30 |
-
search_result = client.search(query=query)
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
except Exception as e:
|
33 |
return f"Error performing search: {str(e)}"
|
34 |
|
35 |
@tool
|
36 |
def get_current_time_in_timezone(timezone: str) -> str:
|
37 |
-
"""A tool that fetches the current local time in a specified timezone.
|
38 |
Args:
|
39 |
-
timezone: A string representing a valid timezone (e.g., 'America/New_York')
|
|
|
|
|
40 |
"""
|
41 |
try:
|
42 |
-
# Create timezone object
|
43 |
tz = pytz.timezone(timezone)
|
44 |
-
# Get current time in that timezone
|
45 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
46 |
-
|
|
|
|
|
47 |
except Exception as e:
|
48 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
49 |
|
50 |
|
51 |
final_answer = FinalAnswerTool()
|
|
|
|
|
|
|
52 |
|
53 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
54 |
-
|
55 |
|
|
|
56 |
model = HfApiModel(
|
57 |
-
max_tokens=2096,
|
58 |
-
temperature=0.
|
59 |
-
model_id='
|
60 |
-
custom_role_conversions=None,
|
61 |
)
|
62 |
|
63 |
|
64 |
-
|
65 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
66 |
|
67 |
with open("prompts.yaml", 'r') as stream:
|
68 |
prompt_templates = yaml.safe_load(stream)
|
@@ -79,5 +93,5 @@ agent = CodeAgent(
|
|
79 |
prompt_templates=prompt_templates
|
80 |
)
|
81 |
|
82 |
-
|
83 |
GradioUI(agent).launch()
|
|
|
21 |
|
22 |
@tool
|
23 |
def tavily_search(query: str) -> str:
|
24 |
+
"""A tool that performs web search using Tavily API and formats the results.
|
25 |
Args:
|
26 |
query: The search query to look up
|
27 |
+
Returns:
|
28 |
+
str: A formatted summary of search results
|
29 |
"""
|
30 |
try:
|
31 |
client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])
|
32 |
+
search_result = client.search(query=query, search_depth="advanced")
|
33 |
+
|
34 |
+
# Format the results in a user-friendly way
|
35 |
+
summary = f"Here are the search results for: {query}\n\n"
|
36 |
+
for result in search_result['results'][:5]: # Top 5 results
|
37 |
+
summary += f"• {result['title']}\n"
|
38 |
+
summary += f" Summary: {result['description'][:200]}...\n\n"
|
39 |
+
|
40 |
+
return summary
|
41 |
except Exception as e:
|
42 |
return f"Error performing search: {str(e)}"
|
43 |
|
44 |
@tool
|
45 |
def get_current_time_in_timezone(timezone: str) -> str:
|
46 |
+
"""A tool that fetches and formats the current local time in a specified timezone.
|
47 |
Args:
|
48 |
+
timezone: A string representing a valid timezone (e.g., 'America/New_York', 'Asia/Tokyo')
|
49 |
+
Returns:
|
50 |
+
str: A formatted string containing the timezone and current time
|
51 |
"""
|
52 |
try:
|
|
|
53 |
tz = pytz.timezone(timezone)
|
|
|
54 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
55 |
+
# Return a more descriptive string with cleaned timezone name
|
56 |
+
city = timezone.split('/')[-1].replace('_', ' ')
|
57 |
+
return f"The current time in {city} is: {local_time}"
|
58 |
except Exception as e:
|
59 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
60 |
|
61 |
|
62 |
final_answer = FinalAnswerTool()
|
63 |
+
# Import tool from Hub
|
64 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
65 |
+
|
66 |
|
67 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
68 |
+
model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
69 |
|
70 |
+
# Model configuration
|
71 |
model = HfApiModel(
|
72 |
+
max_tokens=2096,
|
73 |
+
temperature=0.3, # Lower temperature for more consistent responses
|
74 |
+
model_id=model_id, # 'Qwen/Qwen2.5-Coder-32B-Instruct',
|
75 |
+
custom_role_conversions=None,
|
76 |
)
|
77 |
|
78 |
|
79 |
+
|
|
|
80 |
|
81 |
with open("prompts.yaml", 'r') as stream:
|
82 |
prompt_templates = yaml.safe_load(stream)
|
|
|
93 |
prompt_templates=prompt_templates
|
94 |
)
|
95 |
|
96 |
+
# Launch the Gradio interface
|
97 |
GradioUI(agent).launch()
|