Python scraper based on AI
Python ai-crawlerai-scrapingai-searchcrawlerdata-extractionfirecrawl-alternativelarge-language-modelllmmarkdownragscrapingscraping-pythonweb-crawlerweb-crawlersweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
fix: refactoring of merge_answer_node
Matteo Vedovati898e5a7af504
diff --git a/scrapegraphai/helpers/__init__.py b/scrapegraphai/helpers/__init__.pyindex d238f76e..4174424a 100644--- a/scrapegraphai/helpers/__init__.py+++ b/scrapegraphai/helpers/__init__.py@@ -10,3 +10,4 @@ from .generate_answer_node_prompts import template_chunks, template_no_chunks, tfrom .generate_answer_node_csv_prompts import template_chunks_csv, template_no_chunks_csv, template_merge_csvfrom .generate_answer_node_pdf_prompts import template_chunks_pdf, template_no_chunks_pdf, template_merge_pdffrom .generate_answer_node_omni_prompts import template_chunks_omni, template_no_chunk_omni, template_merge_omni+from .merge_answer_node_prompts import template_combineddiff --git a/scrapegraphai/helpers/merge_answer_node_prompts.py b/scrapegraphai/helpers/merge_answer_node_prompts.pynew file mode 100644index 00000000..b6dad71b--- /dev/null+++ b/scrapegraphai/helpers/merge_answer_node_prompts.py@@ -0,0 +1,13 @@+"""+Merge answer node prompts+"""++template_combined = """+ You are a website scraper and you have just scraped some content from multiple websites.\n+ You are now asked to provide an answer to a USER PROMPT based on the content you have scraped.\n+ You need to merge the content from the different websites into a single answer without repetitions (if there are any). \n+ The scraped contents are in a JSON format and you need to merge them based on the context and providing a correct JSON structure.\n+ OUTPUT INSTRUCTIONS: {format_instructions}\n+ USER PROMPT: {user_prompt}\n+ WEBSITE CONTENT: {website_content}+ """\ No newline at end of filediff --git a/scrapegraphai/nodes/merge_answers_node.py b/scrapegraphai/nodes/merge_answers_node.pyindex 548b7c04..eaea0184 100644--- a/scrapegraphai/nodes/merge_answers_node.py+++ b/scrapegraphai/nodes/merge_answers_node.py@@ -7,6 +7,7 @@ from langchain.prompts import PromptTemplatefrom langchain_core.output_parsers import JsonOutputParserfrom ..utils.logging import get_loggerfrom .base_node import BaseNode+from ..helpers import template_combinedclass MergeAnswersNode(BaseNode):@@ -79,18 +80,8 @@ class MergeAnswersNode(BaseNode):format_instructions = output_parser.get_format_instructions()- template_merge = """- You are a website scraper and you have just scraped some content from multiple websites.\n- You are now asked to provide an answer to a USER PROMPT based on the content you have scraped.\n- You need to merge the content from the different websites into a single answer without repetitions (if there are any). \n- The scraped contents are in a JSON format and you need to merge them based on the context and providing a correct JSON structure.\n- OUTPUT INSTRUCTIONS: {format_instructions}\n- USER PROMPT: {user_prompt}\n- WEBSITE CONTENT: {website_content}- """-prompt_template = PromptTemplate(- template=template_merge,+ template=template_combined,input_variables=["user_prompt"],partial_variables={"format_instructions": format_instructions,