Spaces:
Build error
Build error
Download tools/rss_get_papers.py from kodinD/kodin_agent: direct link, hf CLI and curl.
- Browser
- Download file 2.06 kB
-
https://huggingface.co/spaces/kodinD/kodin_agent/resolve/main/tools/rss_get_papers.py
- Command line
-
hf download hf://spaces/kodinD/kodin_agent/tools/rss_get_papers.py
-
curl -L -o rss_get_papers.py https://huggingface.co/spaces/kodinD/kodin_agent/resolve/main/tools/rss_get_papers.py
2.06 kB
| import re | |
| from typing import Any, Optional | |
| from smolagents.tools import Tool | |
| import requests | |
| import markdownify | |
| import smolagents | |
| from tools.feed_processor import DailyHFRSSParser, RSSFeedProcessor | |
| class HFDaylyPapperTool(Tool): | |
| name = "get_actual_ai_news" | |
| description = "Return actual news about AI today." | |
| output_type = "string" | |
| inputs = {'number': {'type': 'integer', 'description': 'How much paper you want research.'}} | |
| def __init__(self, max_results=10, **kwargs): | |
| super().__init__() | |
| self.rss_processor = RSSFeedProcessor() | |
| self.rss_processor.register_feed( | |
| "HuggingFace Daily pappers", | |
| "https://jamesg.blog/hf-papers.xml", | |
| DailyHFRSSParser(), | |
| ) | |
| def forward(self, number: int) -> str: | |
| try: | |
| from markdownify import markdownify | |
| from smolagents.utils import truncate_content | |
| except ImportError as e: | |
| raise ImportError( | |
| "You must install packages `markdownify` and `requests` to run this tool: for instance run `pip install markdownify requests`." | |
| ) from e | |
| try: | |
| response = self.rss_processor.get_latest_articles(["HuggingFace Daily pappers"], number)[0] | |
| result = "" | |
| for article in response: | |
| result+=self.pretty_str_paper(article) | |
| markdown_content = markdownify(result).strip() | |
| markdown_content = re.sub(r"\n{3,}", "\n\n", markdown_content) | |
| return truncate_content(markdown_content, 10000) | |
| except Exception as e: | |
| return f"An unexpected error occurred: {str(e)}" | |
| def pretty_str_paper(self, article): | |
| return f"*{article.title}*\n" \ | |
| f"_Источник_: {article.source}\n" \ | |
| f"_Авторы_: {article.authors}\n" \ | |
| f"_Опубликовано_: {article.published}\n" \ | |
| f"_Описание_: {article.summary}\n\n" |