Spaces:
Sleeping
Sleeping
File size: 659 Bytes
e8a9836 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
from langchain.tools import tool
import requests
class NewsTools:
@tool("Search Crypto News")
def search_crypto_news(query):
"""Searches for cryptocurrency news articles based on a given query."""
url = f"https://cryptonews-api.com/api/v1/category?section=general&items=10&token=YOUR_API_KEY&q={query}"
response = requests.get(url)
if response.status_code == 200:
articles = response.json()['data']
return [{'title': article['title'], 'source': article['source_name'], 'url': article['news_url']} for article in articles]
else:
return "Error fetching news data" |