Python scraper based on AI
Python ai-crawlerai-scrapingai-searchcrawlerdata-extractionfirecrawl-alternativelarge-language-modelllmmarkdownragscrapingscraping-pythonweb-crawlerweb-crawlersweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
dev: implemented simpler example
Marco Perinidfcad740573b
diff --git a/examples/graph_example.py b/examples/graph_example.pyindex b6548b0f..99acdcec 100644--- a/examples/graph_example.py+++ b/examples/graph_example.py@@ -1,14 +1,17 @@-from langchain_openai import ChatOpenAIfrom yosoai.graph import SmartScraperOPENAI_API_KEY = ''-llm = ChatOpenAI(api_key=OPENAI_API_KEY, model_name="gpt-3.5-turbo", temperature=0, streaming=True)++llm_config = {+ "api_key": OPENAI_API_KEY,+ "model_name": "gpt-3.5-turbo",+}url = "https://perinim.github.io/projects/"prompt = "List me all the titles and project descriptions"-smart_scraper = SmartScraper(prompt, url, llm)-answer = smart_scraper.run()+smart_scraper = SmartScraper(prompt, url, llm_config)+answer = smart_scraper.run()print(answer)diff --git a/yosoai/graph/__init__.py b/yosoai/graph/__init__.pyindex b4e2f459..fdb9e04f 100644--- a/yosoai/graph/__init__.py+++ b/yosoai/graph/__init__.py@@ -5,4 +5,4 @@ from .get_probable_tags_node import GetProbableTagsNodefrom .generate_answer_node import GenerateAnswerNodefrom .parse_html_node import ParseHTMLNode-from .smart_scraper import SmartScraper\ No newline at end of file+from .smart_scraper_graph import SmartScraper\ No newline at end of filediff --git a/yosoai/graph/smart_scraper.py b/yosoai/graph/smart_scraper_graph.pysimilarity index 64%rename from yosoai/graph/smart_scraper.pyrename to yosoai/graph/smart_scraper_graph.pyindex a0ad9515..f2a0b761 100644--- a/yosoai/graph/smart_scraper.py+++ b/yosoai/graph/smart_scraper_graph.py@@ -7,12 +7,28 @@ from .generate_answer_node import GenerateAnswerNodefrom .parse_html_node import ParseHTMLNodeclass SmartScraper:- def __init__(self, prompt, url, llm):+ def __init__(self, prompt, url, llm_config):self.prompt = promptself.url = url- self.llm = llm+ self.llm_config = llm_config+ self.llm = self._create_llm()self.graph = self._create_graph()+ def _create_llm(self):+ # Set default values for any LLM parameters that are not provided+ llm_defaults = {+ "model_name": "gpt-3.5-turbo",+ "temperature": 0,+ "streaming": True+ }+ # Update defaults with any LLM parameters that were provided+ llm_params = {**llm_defaults, **self.llm_config}+ # Ensure the api_key is set, raise an error if it's not+ if "api_key" not in llm_params:+ raise ValueError("LLM configuration must include an 'api_key'.")+ # Create the ChatOpenAI instance with the provided and default parameters+ return ChatOpenAI(**llm_params)+def _create_graph(self):fetch_html_node = FetchHTMLNode("fetch_html")get_probable_tags_node = GetProbableTagsNode(self.llm, "get_probable_tags")