MallikarjunSonna commited on
Commit
38abccb
·
verified ·
1 Parent(s): 670b88c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -35
app.py CHANGED
@@ -5,17 +5,19 @@ import yaml
5
  from tools.final_answer import FinalAnswerTool
6
  from Gradio_UI import GradioUI
7
 
8
- # Define tool for fetching current time in a timezone
9
  @tool
10
  def get_current_time_in_timezone(timezone: str) -> str:
11
  """
12
  Fetches the current local time in a specified timezone.
13
 
14
- Args:
15
- timezone (str): A valid timezone string (e.g., 'Asia/Kolkata', 'America/New_York').
 
16
 
17
  Returns:
18
- str: The current time in the given timezone or an error message.
 
19
  """
20
  try:
21
  tz = pytz.timezone(timezone)
@@ -24,58 +26,34 @@ def get_current_time_in_timezone(timezone: str) -> str:
24
  except Exception as e:
25
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
26
 
27
-
28
- # Define tool for AI research paper search
29
- @tool
30
- def fetch_ai_research_papers(query: str) -> str:
31
- """Fetches recent AI research papers based on the query."""
32
- search_tool = DuckDuckGoSearchTool()
33
- results = search_tool.search(f"AI research paper {query}")
34
- return f"Top AI research papers on {query}: {results}"
35
-
36
- # Define tool for AI news updates
37
- @tool
38
- def fetch_ai_news() -> str:
39
- """Fetches the latest AI news updates."""
40
- search_tool = DuckDuckGoSearchTool()
41
- results = search_tool.search("latest AI news")
42
- return f"Latest AI news updates: {results}"
43
-
44
  # Load final answer tool
45
  final_answer = FinalAnswerTool()
46
 
47
- # Define the model for human-like responses
48
  model = HfApiModel(
49
  max_tokens=2096,
50
- temperature=0.7, # Increased temperature for more human-like responses
51
  model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
52
  custom_role_conversions=None,
53
  )
54
 
55
- # Load text-to-image generation tool
56
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
57
 
58
  # Load prompt templates
59
  with open("prompts.yaml", 'r') as stream:
60
  prompt_templates = yaml.safe_load(stream)
61
 
62
- # Create the AI Assistant Agent
63
  agent = CodeAgent(
64
  model=model,
65
- tools=[
66
- final_answer,
67
- DuckDuckGoSearchTool(),
68
- get_current_time_in_timezone,
69
- fetch_ai_research_papers,
70
- fetch_ai_news,
71
- image_generation_tool
72
- ],
73
  max_steps=6,
74
  verbosity_level=1,
75
  grammar=None,
76
  planning_interval=None,
77
- name="AI Research Assistant",
78
- description="An AI assistant capable of answering queries, fetching AI research, news, generating images, and interacting naturally.",
79
  prompt_templates=prompt_templates
80
  )
81
 
 
5
  from tools.final_answer import FinalAnswerTool
6
  from Gradio_UI import GradioUI
7
 
8
+ # Define the tool correctly using @tool decorator
9
  @tool
10
  def get_current_time_in_timezone(timezone: str) -> str:
11
  """
12
  Fetches the current local time in a specified timezone.
13
 
14
+ Parameters:
15
+ timezone (str): The name of the timezone in "Continent/City" format.
16
+ Example: "Asia/Kolkata", "America/New_York".
17
 
18
  Returns:
19
+ str: The current time in the given timezone in 'YYYY-MM-DD HH:MM:SS' format,
20
+ or an error message if the timezone is invalid.
21
  """
22
  try:
23
  tz = pytz.timezone(timezone)
 
26
  except Exception as e:
27
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  # Load final answer tool
30
  final_answer = FinalAnswerTool()
31
 
32
+ # Define the model
33
  model = HfApiModel(
34
  max_tokens=2096,
35
+ temperature=0.5,
36
  model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
37
  custom_role_conversions=None,
38
  )
39
 
40
+ # Import an image generation tool from Hugging Face Hub
41
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
42
 
43
  # Load prompt templates
44
  with open("prompts.yaml", 'r') as stream:
45
  prompt_templates = yaml.safe_load(stream)
46
 
47
+ # Create the Agent with properly defined tools
48
  agent = CodeAgent(
49
  model=model,
50
+ tools=[final_answer, DuckDuckGoSearchTool(), get_current_time_in_timezone, image_generation_tool],
 
 
 
 
 
 
 
51
  max_steps=6,
52
  verbosity_level=1,
53
  grammar=None,
54
  planning_interval=None,
55
+ name="My First SmolAgent",
56
+ description="An AI assistant capable of searching, fetching time, and generating images.",
57
  prompt_templates=prompt_templates
58
  )
59