zerito commited on
Commit
abff7c0
·
verified ·
1 Parent(s): 4299885

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -1,4 +1,4 @@
1
- from smolagents import CodeAgent, HfApiModel, load_tool, tool
2
  import requests
3
  from tools.final_answer import FinalAnswerTool
4
  from Gradio_UI import GradioUI
@@ -16,6 +16,17 @@ def get_btc_price() -> str:
16
  return '{"error": "Bitcoin price not found"}'
17
  return f"The current Bitcoin price is ${price:.2f} USD."
18
 
 
 
 
 
 
 
 
 
 
 
 
19
  # Initialize the FinalAnswerTool
20
  final_answer = FinalAnswerTool()
21
 
@@ -27,14 +38,10 @@ model = HfApiModel(
27
  custom_role_conversions=None,
28
  )
29
 
30
- # Load additional tools if needed
31
- # For example, to load an image generation tool:
32
- # image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
33
-
34
  # Create the agent
35
  agent = CodeAgent(
36
  model=model,
37
- tools=[get_btc_price, final_answer], # Add your tools here
38
  max_steps=6,
39
  verbosity_level=1,
40
  grammar=None,
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
  import requests
3
  from tools.final_answer import FinalAnswerTool
4
  from Gradio_UI import GradioUI
 
16
  return '{"error": "Bitcoin price not found"}'
17
  return f"The current Bitcoin price is ${price:.2f} USD."
18
 
19
+ @tool
20
+ def get_btc_news() -> str:
21
+ """Fetches recent Bitcoin news articles using DuckDuckGo search."""
22
+ search_query = "Bitcoin news"
23
+ search_tool = DuckDuckGoSearchTool()
24
+ results = search_tool(search_query)
25
+ if not results:
26
+ return "No news articles found."
27
+ news = "\n".join([f"{i+1}. {result['title']} - {result['url']}" for i, result in enumerate(results[:5])])
28
+ return f"Recent Bitcoin News:\n{news}"
29
+
30
  # Initialize the FinalAnswerTool
31
  final_answer = FinalAnswerTool()
32
 
 
38
  custom_role_conversions=None,
39
  )
40
 
 
 
 
 
41
  # Create the agent
42
  agent = CodeAgent(
43
  model=model,
44
+ tools=[get_btc_price, get_btc_news, final_answer], # Add your tools here
45
  max_steps=6,
46
  verbosity_level=1,
47
  grammar=None,