refactoring of code and documentation

This commit is contained in:
Marco Vinciguerra 2024-08-16 09:01:27 +02:00
parent 203ee2c186
commit b115f9612f
6 changed files with 39 additions and 7 deletions

View File

@ -13,8 +13,38 @@ from ..nodes import (
class CSVScraperGraph(AbstractGraph):
"""
SmartScraper is a comprehensive web scraping tool that automates the process of extracting
information from web pages using a natural language model to interpret and answer prompts.
A class representing a graph for extracting information from CSV files.
Attributes:
prompt (str): The prompt used to generate an answer.
source (str): The source of the data, which can be either a CSV
file or a directory containing multiple CSV files.
config (dict): Additional configuration parameters needed by some nodes in the graph.
Methods:
__init__ (prompt: str, source: str, config: dict, schema: Optional[BaseModel] = None):
Initializes the CSVScraperGraph with a prompt, source, and configuration.
__init__ initializes the CSVScraperGraph class. It requires the user's prompt as input,
along with the source of the data (which can be either a single CSV file or a directory
containing multiple CSV files), and any necessary configuration parameters.
Methods:
_create_graph (): Creates the graph of nodes representing the workflow for web scraping.
_create_graph generates the web scraping process workflow
represented by a directed acyclic graph.
This method is used internally to create the scraping pipeline
without having to execute it immediately. The result is a BaseGraph instance
containing nodes that fetch and process data from a source, and other helper functions.
Methods:
run () -> str: Executes the web scraping process and returns
the answer to the prompt as a string.
run runs the CSVScraperGraph class to extract information from a CSV file based
on the user's prompt. It requires no additional arguments since all necessary data
is stored within the class instance. The method fetches the relevant chunks of text or speech,
generates an answer based on these chunks, and returns this answer as a string.
"""
def __init__(self, prompt: str, source: str, config: dict, schema: Optional[BaseModel] = None):

View File

@ -41,7 +41,8 @@ class PdfScraperMultiGraph(AbstractGraph):
>>> result = search_graph.run()
"""
def __init__(self, prompt: str, source: List[str], config: dict, schema: Optional[BaseModel] = None):
def __init__(self, prompt: str, source: List[str],
config: dict, schema: Optional[BaseModel] = None):
if all(isinstance(value, str) for value in config.values()):
self.copy_config = copy(config)

View File

@ -43,7 +43,8 @@ class XMLScraperMultiGraph(AbstractGraph):
>>> result = search_graph.run()
"""
def __init__(self, prompt: str, source: List[str], config: dict, schema: Optional[BaseModel] = None):
def __init__(self, prompt: str, source: List[str],
config: dict, schema: Optional[BaseModel] = None):
if all(isinstance(value, str) for value in config.values()):
self.copy_config = copy(config)

View File

@ -188,4 +188,4 @@ def capture_function_usage(call_fn: Callable) -> Callable:
log_event("function_usage", {"function_name": function_name})
except Exception as e:
logger.debug(f"Failed to send telemetry for function usage. Encountered: {e}")
return wrapped_fn
return wrapped_fn

View File

@ -1,9 +1,9 @@
"""
Module for minimizing the code
"""
from urllib.parse import urljoin
from bs4 import BeautifulSoup
from minify_html import minify
from urllib.parse import urljoin
def cleanup_html(html_content: str, base_url: str) -> str:
"""

View File

@ -1,5 +1,5 @@
"""
convert_to_md modul
convert_to_md module
"""
from urllib.parse import urlparse
import html2text