zerito commited on
Commit
d9d9151
·
verified ·
1 Parent(s): 227f292

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -25
app.py CHANGED
@@ -1,4 +1,4 @@
1
- from smolagents import CodeAgent, HfApiModel, load_tool, tool, DuckDuckGoSearchTool
2
  import requests
3
  from tools.final_answer import FinalAnswerTool
4
  from Gradio_UI import GradioUI
@@ -17,32 +17,33 @@ def get_btc_price() -> str:
17
  return '{"error": "Bitcoin price not found"}'
18
  return f"The current Bitcoin price is ${price:.2f} USD."
19
 
20
-
21
- # Tool for fetching Bitcoin news using DuckDuckGo search
22
  @tool
23
  def get_btc_news() -> str:
24
- """Fetches the latest Bitcoin news from DuckDuckGo search."""
25
- search_query = "latest Bitcoin news"
26
- # Initialize the DuckDuckGoSearchTool
27
- search_tool = DuckDuckGoSearchTool()
28
- # Perform the search
29
- search_results = search_tool.run(search_query)
30
-
31
- # Ensure search_results is a list of articles with titles and meta descriptions
32
- try:
33
- # Process the results and extract titles and descriptions
34
- articles = []
35
- for result in search_results['RelatedTopics']:
36
- title = result.get('Text', '')
37
- description = result.get('FirstURL', '')
38
- articles.append(f"Title: {title}\nDescription: {description}\n")
39
- if articles:
40
- return "\n\n".join(articles)
41
- else:
42
- return "No relevant news found."
43
- except Exception as e:
44
- return f"Error fetching Bitcoin news: {str(e)}"
45
-
 
 
46
 
47
  # Initialize the FinalAnswerTool
48
  final_answer = FinalAnswerTool()
 
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
 
17
  return '{"error": "Bitcoin price not found"}'
18
  return f"The current Bitcoin price is ${price:.2f} USD."
19
 
20
+ # Tool for fetching Bitcoin news using NewsData.io API
 
21
  @tool
22
  def get_btc_news() -> str:
23
+ """Fetches the latest Bitcoin news from NewsData.io API."""
24
+ url = "https://newsdata.io/api/1/news"
25
+ params = {
26
+ 'apikey': 'YOUR_API_KEY', # Replace with your actual API key
27
+ 'q': 'Bitcoin',
28
+ 'category': 'crypto',
29
+ 'language': 'en',
30
+ 'country': 'us',
31
+ 'page': 1,
32
+ 'size': 5 # Number of news articles to fetch
33
+ }
34
+ response = requests.get(url, params=params)
35
+ if response.status_code != 200:
36
+ return '{"error": "Failed to fetch Bitcoin news"}'
37
+ data = response.json()
38
+ articles = data.get('results', [])
39
+ if not articles:
40
+ return "No relevant news found."
41
+ news_list = []
42
+ for article in articles:
43
+ title = article.get('title', 'No title')
44
+ description = article.get('description', 'No description')
45
+ news_list.append(f"Title: {title}\nDescription: {description}\n")
46
+ return "\n\n".join(news_list)
47
 
48
  # Initialize the FinalAnswerTool
49
  final_answer = FinalAnswerTool()