Spaces:
Sleeping
Sleeping
Update app.py
Browse filesCreated duckduck_go_search tool and a sentiment analysis tool, updated the tools section
app.py
CHANGED
|
@@ -18,6 +18,7 @@ def my_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
|
|
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
"""A tool that fetches the current local time in a specified timezone.
|
|
@@ -34,6 +35,43 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
model = HfApiModel(
|
| 39 |
max_tokens=2096,
|
|
@@ -51,7 +89,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 51 |
|
| 52 |
agent = CodeAgent(
|
| 53 |
model=model,
|
| 54 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 55 |
max_steps=6,
|
| 56 |
verbosity_level=1,
|
| 57 |
grammar=None,
|
|
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
| 21 |
+
|
| 22 |
@tool
|
| 23 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 24 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 35 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 36 |
|
| 37 |
|
| 38 |
+
@tool
|
| 39 |
+
def duckduckgo_search(query: str) -> str:
|
| 40 |
+
"""Searches DuckDuckGo for a given query and returns the top result.
|
| 41 |
+
Args:
|
| 42 |
+
query: The search query string.
|
| 43 |
+
Returns:
|
| 44 |
+
A short summary with the top DuckDuckGo result.
|
| 45 |
+
"""
|
| 46 |
+
search_tool = DuckDuckGoSearchTool()
|
| 47 |
+
results = search_tool.run(query)
|
| 48 |
+
|
| 49 |
+
if results:
|
| 50 |
+
return f"Top search result: {results[0]['title']} - {results[0]['link']}"
|
| 51 |
+
else:
|
| 52 |
+
return "No results found."
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
@tool
|
| 56 |
+
def get_sentiment(test:str)->str:
|
| 57 |
+
"""Analyze the sentiment of the given text(Positive/Negative/Neutral)
|
| 58 |
+
|
| 59 |
+
Args:
|
| 60 |
+
text : The input text to analyse
|
| 61 |
+
|
| 62 |
+
Returns:
|
| 63 |
+
A string indicating the sentiment (Positive, Negative, or Neutral).
|
| 64 |
+
|
| 65 |
+
"""
|
| 66 |
+
text = text.lower()
|
| 67 |
+
if any(word in text_lower for word in ["good", "great", "awesome", "fantastic", "love", "happy"]):
|
| 68 |
+
return "Sentiment: Positive"
|
| 69 |
+
elif any(word in text_lower for word in ["bad", "terrible", "awful", "hate", "angry", "sad"]):
|
| 70 |
+
return "Sentiment: Negative"
|
| 71 |
+
else:
|
| 72 |
+
return "Sentiment: Neutral"
|
| 73 |
+
|
| 74 |
+
|
| 75 |
final_answer = FinalAnswerTool()
|
| 76 |
model = HfApiModel(
|
| 77 |
max_tokens=2096,
|
|
|
|
| 89 |
|
| 90 |
agent = CodeAgent(
|
| 91 |
model=model,
|
| 92 |
+
tools=[my_cutom_tool, get_current_time_in_timezone, duckduckgo_search, get_sentiment, final_answer], ## add your tools here (don't remove final answer)
|
| 93 |
max_steps=6,
|
| 94 |
verbosity_level=1,
|
| 95 |
grammar=None,
|