Files changed (1) hide show
  1. app.py +22 -6
app.py CHANGED
@@ -18,6 +18,24 @@ 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.
@@ -47,21 +65,19 @@ custom_role_conversions=None,
47
  )
48
 
49
 
50
- # Import tool from Hub
51
- image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
52
-
53
  with open("prompts.yaml", 'r') as stream:
54
  prompt_templates = yaml.safe_load(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,
62
  planning_interval=None,
63
- name=None,
64
- description=None,
65
  prompt_templates=prompt_templates
66
  )
67
 
 
18
  """
19
  return "What magic will you build ?"
20
 
21
+ # Import tool from Hub
22
+ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
23
+
24
+ @tool
25
+ def generate_image(prompt: str) -> str:
26
+ """
27
+ Generates an image based on a text prompt.
28
+
29
+ Args:
30
+ prompt: A detailed description of the image to generate.
31
+ """
32
+ try:
33
+ result = image_generation_tool(prompt)
34
+ return f"Image successfully generated for prompt: '{prompt}'.\nResult: {result}"
35
+ except Exception as e:
36
+ return f"Error generating image: {str(e)}"
37
+
38
+
39
  @tool
40
  def get_current_time_in_timezone(timezone: str) -> str:
41
  """A tool that fetches the current local time in a specified timezone.
 
65
  )
66
 
67
 
 
 
 
68
  with open("prompts.yaml", 'r') as stream:
69
  prompt_templates = yaml.safe_load(stream)
70
+
71
 
72
  agent = CodeAgent(
73
  model=model,
74
+ tools=[final_answer, generate_image, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
75
  max_steps=6,
76
  verbosity_level=1,
77
  grammar=None,
78
  planning_interval=None,
79
+ name="Image Assistant Agent",
80
+ description="An AI agent that can generate images and fetch timezone-based current time.",
81
  prompt_templates=prompt_templates
82
  )
83