zerito commited on
Commit
19cb351
·
verified ·
1 Parent(s): 8be336b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -13
app.py CHANGED
@@ -1,8 +1,7 @@
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
5
- from duckduckgo_search import ddg_search
6
 
7
  @tool
8
  def get_btc_price() -> str:
@@ -19,17 +18,15 @@ def get_btc_price() -> str:
19
 
20
  @tool
21
  def get_btc_news() -> str:
22
- """Fetches the latest Bitcoin news titles and meta descriptions."""
23
- query = "Bitcoin news"
24
- results = ddg_search(query, max_results=5) # Adjust max_results as needed
25
- if not results:
26
- return "No news found."
27
- news_list = []
28
- for result in results:
29
- title = result.get('title', 'No title')
30
- meta_description = result.get('snippet', 'No description available')
31
- news_list.append(f"**{title}**\n{meta_description}\n")
32
- return "\n".join(news_list)
33
 
34
  # Initialize the FinalAnswerTool
35
  final_answer = FinalAnswerTool()
@@ -42,6 +39,10 @@ model = HfApiModel(
42
  custom_role_conversions=None,
43
  )
44
 
 
 
 
 
45
  # Create the agent
46
  agent = CodeAgent(
47
  model=model,
 
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
 
5
 
6
  @tool
7
  def get_btc_price() -> str:
 
18
 
19
  @tool
20
  def get_btc_news() -> str:
21
+ """Fetches the latest Bitcoin news articles."""
22
+ search_query = "latest Bitcoin news"
23
+ search_results = DuckDuckGoSearchTool()(search_query)
24
+ if not search_results:
25
+ return '{"error": "Failed to fetch Bitcoin news"}'
26
+ news_titles = [result['title'] for result in search_results]
27
+ news_descriptions = [result['snippet'] for result in search_results]
28
+ news_list = "\n".join([f"**{title}**\n{description}" for title, description in zip(news_titles, news_descriptions)])
29
+ return f"Here are the latest Bitcoin news articles:\n\n{news_list}"
 
 
30
 
31
  # Initialize the FinalAnswerTool
32
  final_answer = FinalAnswerTool()
 
39
  custom_role_conversions=None,
40
  )
41
 
42
+ # Load additional tools if needed
43
+ # For example, to load an image generation tool:
44
+ # image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
45
+
46
  # Create the agent
47
  agent = CodeAgent(
48
  model=model,