TierraX commited on
Commit
e26d0d8
·
verified ·
1 Parent(s): 9e8f477

Alfred Superhero Party Agent update

Browse files
Files changed (1) hide show
  1. app.py +26 -63
app.py CHANGED
@@ -1,82 +1,45 @@
1
- from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
- import datetime
3
- import requests
4
- import pytz
5
  import yaml
6
- from tools.final_answer import FinalAnswerTool
 
7
 
8
- from Gradio_UI import GradioUI
 
9
 
 
 
 
 
 
 
10
 
11
- @tool
12
- def web_search(query: str) -> str:
13
- """A tool that performs web searches using DuckDuckGo
14
- Args:
15
- query: The search query string
16
- """
17
- try:
18
- # Create instance of DuckDuckGoSearchTool
19
- search_tool = DuckDuckGoSearchTool()
20
 
21
- # Perform the search
22
- results = search_tool(query)
23
-
24
- # Print results for debugging
25
- if not results:
26
- return "No results found."
27
-
28
- # Format results as a simple string
29
- return str(results)
30
-
31
- except Exception as e:
32
- return f"Error performing search: {str(e)}"
33
-
34
- @tool
35
- def get_current_time_in_timezone(timezone: str) -> str:
36
- """A tool that fetches the current local time in a specified timezone.
37
- Args:
38
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
39
- """
40
- try:
41
- # Create timezone object
42
- tz = pytz.timezone(timezone)
43
- # Get current time in that timezone
44
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
45
- return f"The current local time in {timezone} is: {local_time}"
46
- except Exception as e:
47
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
48
-
49
-
50
- final_answer = FinalAnswerTool()
51
-
52
- # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
53
- # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
54
 
55
  model = HfApiModel(
56
- max_tokens=2096,
57
- temperature=0.5,
58
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
59
- custom_role_conversions=None,
60
  )
61
 
 
 
 
 
 
 
62
 
63
- # Import tool from Hub
64
- image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
65
-
66
- with open("prompts.yaml", 'r') as stream:
67
  prompt_templates = yaml.safe_load(stream)
68
-
69
  agent = CodeAgent(
70
  model=model,
71
- tools=[web_search, get_current_time_in_timezone, final_answer], ## add your tools here (don't remove final answer)
72
- max_steps=6,
73
- verbosity_level=1,
 
74
  grammar=None,
75
  planning_interval=None,
76
  name=None,
77
  description=None,
78
  prompt_templates=prompt_templates
79
  )
80
-
81
-
82
- GradioUI(agent).launch()
 
 
 
 
 
1
  import yaml
2
+ import os
3
+ from smolagents import GradioUI, CodeAgent, HfApiModel
4
 
5
+ # Get current directory path
6
+ CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
7
 
8
+ from tools.web_search import DuckDuckGoSearchTool as WebSearch
9
+ from tools.visit_webpage import VisitWebpageTool as VisitWebpage
10
+ from tools.suggest_menu import SimpleTool as SuggestMenu
11
+ from tools.catering_service_tool import SimpleTool as CateringServiceTool
12
+ from tools.superhero_party_theme_generator import SuperheroPartyThemeTool as SuperheroPartyThemeGenerator
13
+ from tools.final_answer import FinalAnswerTool as FinalAnswer
14
 
 
 
 
 
 
 
 
 
 
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  model = HfApiModel(
18
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
19
+ provider=None,
 
 
20
  )
21
 
22
+ web_search = WebSearch()
23
+ visit_webpage = VisitWebpage()
24
+ suggest_menu = SuggestMenu()
25
+ catering_service_tool = CateringServiceTool()
26
+ superhero_party_theme_generator = SuperheroPartyThemeGenerator()
27
+ final_answer = FinalAnswer()
28
 
29
+ with open(os.path.join(CURRENT_DIR, "prompts.yaml"), 'r') as stream:
 
 
 
30
  prompt_templates = yaml.safe_load(stream)
31
+
32
  agent = CodeAgent(
33
  model=model,
34
+ tools=[web_search, visit_webpage, suggest_menu, catering_service_tool, superhero_party_theme_generator],
35
+ managed_agents=[],
36
+ max_steps=10,
37
+ verbosity_level=2,
38
  grammar=None,
39
  planning_interval=None,
40
  name=None,
41
  description=None,
42
  prompt_templates=prompt_templates
43
  )
44
+ if __name__ == "__main__":
45
+ GradioUI(agent).launch()