Files changed (1) hide show
  1. app.py +27 -1
app.py CHANGED
@@ -18,6 +18,32 @@ def my_custom_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.
@@ -55,7 +81,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
18
  """
19
  return "What magic will you build ?"
20
 
21
+ @tool
22
+ def analyze_text_sentiment(text: str) -> str:
23
+ """A tool that analyzes the sentiment of provided text.
24
+ Args:
25
+ text: The text to analyze
26
+ """
27
+ try:
28
+ # Using a simple free API (Text Processing)
29
+ url = "http://text-processing.com/api/sentiment/"
30
+ payload = {"text": text}
31
+ response = requests.post(url, data=payload)
32
+ data = response.json()
33
+
34
+ if response.status_code != 200:
35
+ return "Error analyzing sentiment"
36
+
37
+ label = data['label']
38
+ probability = data['probability']
39
+ return (f"Sentiment Analysis:\n"
40
+ f"Sentiment: {label}\n"
41
+ f"Positive: {probability['positive']:.2f}\n"
42
+ f"Negative: {probability['negative']:.2f}\n"
43
+ f"Neutral: {probability['neutral']:.2f}")
44
+ except Exception as e:
45
+ return f"Error analyzing sentiment: {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.
 
81
 
82
  agent = CodeAgent(
83
  model=model,
84
+ tools=[final_answer,analyze_text_sentiment], ## add your tools here (don't remove final answer)
85
  max_steps=6,
86
  verbosity_level=1,
87
  grammar=None,