Python scraper based on AI
Python ai-crawlerai-scrapingai-searchcrawlerdata-extractionfirecrawl-alternativelarge-language-modelllmmarkdownragscrapingscraping-pythonweb-crawlerweb-crawlersweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
created rag example
Perinimb0c75dc7ed7a
diff --git a/examples/custom_graph_example.py b/examples/custom_graph_example.pyindex 3a55a5cc..080fe85f 100644--- a/examples/custom_graph_example.py+++ b/examples/custom_graph_example.py@@ -6,7 +6,7 @@ import osfrom dotenv import load_dotenvfrom scrapegraphai.models import OpenAIfrom scrapegraphai.graphs import BaseGraph-from scrapegraphai.nodes import FetchHTMLNode, ParseHTMLNode, GenerateAnswerNode, TestRagNode+from scrapegraphai.nodes import FetchHTMLNode, ParseHTMLNode, GenerateAnswerNodeload_dotenv()@@ -22,7 +22,7 @@ model = OpenAI(llm_config)# define the nodes for the graphfetch_html_node = FetchHTMLNode("fetch_html")-parse_document_node = TestRagNode(model, "parse_document")+parse_document_node = ParseHTMLNode("parse_document")generate_answer_node = GenerateAnswerNode(model, "generate_answer")# create the graph@@ -40,7 +40,7 @@ graph = BaseGraph()# execute the graph-inputs = {"user_input": "List me all the cinemas in Rome", "url": "https://www.mymovies.it/cinema/roma/"}+inputs = {"user_input": "Give me the news", "url": "https://www.ansa.it/sito/notizie/topnews/index.shtml"}result = graph.execute(inputs)# get the answer from the resultdiff --git a/examples/custom_graph_rag_example.py b/examples/custom_graph_rag_example.pynew file mode 100644index 00000000..a8015d11--- /dev/null+++ b/examples/custom_graph_rag_example.py@@ -0,0 +1,48 @@+"""+Example of custom graph using existing nodes+"""++import os+from dotenv import load_dotenv+from scrapegraphai.models import OpenAI+from scrapegraphai.graphs import BaseGraph+from scrapegraphai.nodes import FetchHTMLNode, RAGNode, GenerateAnswerNode++load_dotenv()++# Define the configuration for the language model+openai_key = os.getenv("OPENAI_APIKEY")+llm_config = {+ "api_key": openai_key,+ "model_name": "gpt-3.5-turbo",+ "temperature": 0,+ "streaming": True+}+model = OpenAI(llm_config)++# define the nodes for the graph+fetch_html_node = FetchHTMLNode("fetch_html")+rag_node = RAGNode(model, "rag")+generate_answer_node = GenerateAnswerNode(model, "generate_answer")++# create the graph+graph = BaseGraph(+ nodes={+ fetch_html_node,+ rag_node,+ generate_answer_node+ },+ edges={+ (fetch_html_node, rag_node),+ (rag_node, generate_answer_node)+ },+ entry_point=fetch_html_node+)++# execute the graph+inputs = {"user_input": "Give me all the projects with their descriptions", "url": "https://perinim.github.io/projects/"}+result = graph.execute(inputs)++# get the answer from the result+answer = result.get("answer", "No answer found.")+print(answer)diff --git a/pyproject.toml b/pyproject.tomlindex 176d322e..ba54181e 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -26,8 +26,8 @@ langchain = "0.1.6"langchain_community = "0.0.19"langchain_core = "0.1.22"langchain_openai = "0.0.5"-chromadb = "0.4.22"html2text = "2020.1.16"+faiss-cpu = "1.7.4"beautifulsoup4 = "4.12.3"pandas = "2.0.3"python-dotenv = "1.0.1"diff --git a/requirements-dev.txt b/requirements-dev.txtindex 63e96505..12d0e42f 100644--- a/requirements-dev.txt+++ b/requirements-dev.txt@@ -1,4 +1,3 @@sphinx==7.1.2sphinx-rtd-theme==2.0.0pytest==8.0.0-sentence_transformers==2.3.1diff --git a/requirements.txt b/requirements.txtindex eefb170a..e11c029a 100644--- a/requirements.txt+++ b/requirements.txt@@ -2,7 +2,7 @@ langchain==0.1.6langchain_community==0.0.19langchain_core==0.1.22langchain_openai==0.0.5-chromadb==0.4.22+faiss-cpu==1.7.4html2text==2020.1.16beautifulsoup4==4.12.3pandas==2.0.3diff --git a/scrapegraphai/helpers/nodes_metadata.py b/scrapegraphai/helpers/nodes_metadata.pyindex e5e6f243..cec408b7 100644--- a/scrapegraphai/helpers/nodes_metadata.py+++ b/scrapegraphai/helpers/nodes_metadata.py@@ -29,6 +29,18 @@ nodes_metadata = {},"returns": "Updated state with extracted data under 'parsed_document' key."},+ "RAGNode": {+ "description": """A node responsible for reducing the amount of text to be processed+ by identifying and retrieving the most relevant chunks of text based on the user's query.+ Utilizes RecursiveCharacterTextSplitter for chunking, Html2TextTransformer for HTML to text+ conversion, and a combination of FAISS and OpenAIEmbeddings for efficient information retrieval.""",+ "type": "node",+ "args": {+ "user_input": "The user's query or question guiding the retrieval.",+ "document": "The HTML content to be processed and compressed."+ },+ "returns": "Updated state with 'relevant_chunks' key containing the most relevant text chunks."+ },"GenerateAnswerNode": {"description": "Generates an answer based on the user's input and parsed document.","type": "node",diff --git a/scrapegraphai/nodes/__init__.py b/scrapegraphai/nodes/__init__.pyindex 2898fa16..c593c180 100644--- a/scrapegraphai/nodes/__init__.py+++ b/scrapegraphai/nodes/__init__.py@@ -6,6 +6,6 @@ from .conditional_node import ConditionalNodefrom .get_probable_tags_node import GetProbableTagsNodefrom .generate_answer_node import GenerateAnswerNodefrom .parse_html_node import ParseHTMLNode-from .test_rag_node import TestRagNode+from .rag_node import RAGNodefrom .text_to_speech_node import TextToSpeechNodefrom .image_to_text_node import ImageToTextNodediff --git a/scrapegraphai/nodes/test_rag_node.py b/scrapegraphai/nodes/rag_node.pysimilarity index 99%rename from scrapegraphai/nodes/test_rag_node.pyrename to scrapegraphai/nodes/rag_node.pyindex 90cc0796..db23c7d7 100644--- a/scrapegraphai/nodes/test_rag_node.py+++ b/scrapegraphai/nodes/rag_node.py@@ -15,7 +15,7 @@ from langchain_community.document_transformers import EmbeddingsRedundantFilterfrom .base_node import BaseNode-class TestRagNode(BaseNode):+class RAGNode(BaseNode):"""A node responsible for parsing HTML content from a document using specified tags.It uses BeautifulSoupTransformer for parsing, providing flexibility in extracting