import os import requests from requests.exceptions import RequestException import datetime from smolagents import tool headers = {'Authorization': 'Bearer ' + os.getenv('JINA_API_KEY')} @tool def scrape_page_with_jina_ai(url: str) -> str: """Scrapes content from a webpage using Jina AI's web scraping service. Args: url: The URL of the webpage to scrape. Must be a valid web address to extract content from. Returns: str: The scraped content in markdown format. """ try: print(f"Scraping Jina AI..: {url}") response = requests.get("https://r.jina.ai/" + url, headers=headers) response.raise_for_status() return response.text except RequestException as e: return f"Error scraping webpage: {str(e)}" @tool def search_facts_with_jina_ai(query: str) -> str: """Searches for facts and information using Jina AI's search service. Args: query: The search query string used to find relevant facts and information. Returns: str: The search results in markdown format containing relevant facts and information. """ try: print(f"Searching Jina AI..: {query}") response = requests.get("https://s.jina.ai/" + query, headers=headers) response.raise_for_status() return response.text except RequestException as e: return f"Error searching facts: {str(e)}"