alisamak commited on
Commit
9bc6e0c
·
verified ·
1 Parent(s): 30f7e4e

adding post generation tool

Browse files
Files changed (1) hide show
  1. app.py +18 -1
app.py CHANGED
@@ -33,6 +33,23 @@ def get_current_time_in_timezone(timezone: str) -> str:
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  final_answer = FinalAnswerTool()
38
 
@@ -55,7 +72,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer,get_current_time_in_timezone], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
+ @tool
37
+ def generate_post(subject: str, max_length: int = 200) -> str:
38
+ """Generates a well-structured post about a given subject with a length limit.
39
+
40
+ Args:
41
+ subject: The topic to generate a post about.
42
+ max_length: The maximum length of the post in characters (default: 200).
43
+
44
+ Returns:
45
+ A concise, engaging post about the subject.
46
+ """
47
+ prompt = f"Write a concise and engaging social media post about {subject}. Keep it within {max_length} characters."
48
+
49
+ response = model.generate_text(prompt, max_tokens=max_length // 4) # Approx. 4 chars per token
50
+
51
+ return response[:max_length] # Ensure it doesn't exceed max_length
52
+
53
 
54
  final_answer = FinalAnswerTool()
55
 
 
72
 
73
  agent = CodeAgent(
74
  model=model,
75
+ tools=[final_answer,get_current_time_in_timezone,generate_post], ## add your tools here (don't remove final answer)
76
  max_steps=6,
77
  verbosity_level=1,
78
  grammar=None,