File size: 1,411 Bytes
9d93819
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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)}"