Python scraper based on AI
Python ai-crawlerai-scrapingai-searchcrawlerdata-extractionfirecrawl-alternativelarge-language-modelllmmarkdownragscrapingscraping-pythonweb-crawlerweb-crawlersweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
dev: changed library name
PeriniM5312fcaf5534
diff --git a/amazscraper/class_creator.py b/amazscraper/class_creator.pydeleted file mode 100644index 25862333..00000000--- a/amazscraper/class_creator.py+++ /dev/null@@ -1,24 +0,0 @@-import time--base_script = '''-from langchain_core.pydantic_v1 import BaseModel, Field--class _Response(BaseModel):-'''-def create_class(data_dict: dict):- '''- This function creates a class at runtime using the values from the list.- Parameters:- data_dict- dict {- "title": str- "type": str,- "description": str- }: dictionary for describing the prompt- '''- for elem in data_dict:- global base_script- base_script = base_script + f" {elem['title']}: {elem['type']} = Field(description='{elem['description']}')\n"-- with open("./amazscraper/pydantic_class.py", "w") as f:- f.write(base_script)\ No newline at end of filediff --git a/amazscraper/request.py b/amazscraper/request.pydeleted file mode 100644index 9d06fe88..00000000--- a/amazscraper/request.py+++ /dev/null@@ -1,25 +0,0 @@-from amazscraper.getter import remover-from .class_creator import create_class-from amazscraper.class_generator import Generator---def send_request(values:list[dict]) ->dict:- """- Param:- values (list[dict]): settings of the request.- Format:- [- dict {- "title": str- "type": str,- "description": str- }- ]-- Return:- dict: the result of the request to openai- """- res = {}- create_class("TOADD")-- return res\ No newline at end of filediff --git a/docs/source/getting_started/installation.rst b/docs/source/getting_started/installation.rstindex ce916bb7..6ba6c7d9 100644--- a/docs/source/getting_started/installation.rst+++ b/docs/source/getting_started/installation.rst@@ -28,7 +28,7 @@ Clone the repository.. code-block:: bash- git clone https://github.com/VinciGit00/AmazScraper+ git clone https://github.com/VinciGit00/yoso-ai.gitcd AmazScraperCreate a virtual environmentdiff --git a/docs/source/index.rst b/docs/source/index.rstindex 7e5bce2a..004f2baf 100644--- a/docs/source/index.rst+++ b/docs/source/index.rst@@ -1,12 +1,12 @@-.. amazscraper documentation master file, created by+.. yoso-ai documentation master file, created bysphinx-quickstart on Wed Jan 31 15:38:23 2024.You can adapt this file completely to your liking, but it should at leastcontain the root `toctree` directive.-Welcome to amazscraper's documentation!+Welcome to yoso-ai's documentation!=======================================-Here you will find all the information you need to get started with the amazscraper project.+Here you will find all the information you need to get started.The following sections will guide you through the installation process and the usage of the library... toctree::diff --git a/docs/source/introduction/contributing.rst b/docs/source/introduction/contributing.rstindex 0a2d9196..0f94e5fd 100644--- a/docs/source/introduction/contributing.rst+++ b/docs/source/introduction/contributing.rst@@ -5,9 +5,9 @@ Hey, you want to contribute? Awesome!Just fork the repo, make your changes, and send me a pull request.If you're not sure if it's a good idea, open an issue and we'll discuss it.-Go and check out the `contributing guidelines <https://github.com/VinciGit00/AmazScraper/blob/main/CONTRIBUTING.md>`__ for more information.+Go and check out the `contributing guidelines <https://github.com/VinciGit00/yoso-ai/blob/main/CONTRIBUTING.md>`__ for more information.License=======This project is licensed under the Apache License, Version 2.0.-See the `LICENSE <https://github.com/VinciGit00/AmazScraper/blob/main/LICENSE>`__ file for more details.+See the `LICENSE <https://github.com/VinciGit00/yoso-ai/blob/main/LICENSE>`__ file for more details.diff --git a/docs/source/modules/amazscraper.rst b/docs/source/modules/amazscraper.rstdeleted file mode 100644index a7f55456..00000000--- a/docs/source/modules/amazscraper.rst+++ /dev/null@@ -1,45 +0,0 @@-amazscraper package-===================--Submodules-------------amazscraper.class\_creator module------------------------------------.. automodule:: amazscraper.class_creator- :members:- :undoc-members:- :show-inheritance:--amazscraper.class\_generator module--------------------------------------.. automodule:: amazscraper.class_generator- :members:- :undoc-members:- :show-inheritance:--amazscraper.getter module----------------------------.. automodule:: amazscraper.getter- :members:- :undoc-members:- :show-inheritance:--amazscraper.pydantic\_class module-------------------------------------.. automodule:: amazscraper.pydantic_class- :members:- :undoc-members:- :show-inheritance:--Module contents------------------.. automodule:: amazscraper- :members:- :undoc-members:- :show-inheritance:diff --git a/docs/source/modules/modules.rst b/docs/source/modules/modules.rstindex ecd7499f..f8c06ef8 100644--- a/docs/source/modules/modules.rst+++ b/docs/source/modules/modules.rst@@ -1,7 +1,7 @@-modules-===========+yosoai+======.. toctree:::maxdepth: 4- amazscraper+ yosoaidiff --git a/docs/source/modules/yosoai.rst b/docs/source/modules/yosoai.rstnew file mode 100644index 00000000..8544694d--- /dev/null+++ b/docs/source/modules/yosoai.rst@@ -0,0 +1,53 @@+yosoai package+==============++Submodules+----------++yosoai.class\_creator module+----------------------------++.. automodule:: yosoai.class_creator+ :members:+ :undoc-members:+ :show-inheritance:++yosoai.class\_generator module+------------------------------++.. automodule:: yosoai.class_generator+ :members:+ :undoc-members:+ :show-inheritance:++yosoai.getter module+--------------------++.. automodule:: yosoai.getter+ :members:+ :undoc-members:+ :show-inheritance:++yosoai.pydantic\_class module+-----------------------------++.. automodule:: yosoai.pydantic_class+ :members:+ :undoc-members:+ :show-inheritance:++yosoai.request module+---------------------++.. automodule:: yosoai.request+ :members:+ :undoc-members:+ :show-inheritance:++Module contents+---------------++.. automodule:: yosoai+ :members:+ :undoc-members:+ :show-inheritance:diff --git a/examples/html_scraping.py b/examples/html_scraping.pyindex a360813e..bb326687 100644--- a/examples/html_scraping.py+++ b/examples/html_scraping.py@@ -1,6 +1,6 @@import osfrom dotenv import load_dotenv-from amazscraper.class_generator import Generator+from yosoai.class_generator import Generatorload_dotenv()@@ -8,9 +8,9 @@ MY_ENV_VAR = os.getenv('API_KEY')values = [{- "title": "title",+ "title": "description","type": "str",- "description": "Title of the news"+ "description": "The description of the news"}]diff --git a/examples/value_scraping.py b/examples/value_scraping.pyindex c835114e..9d5a5296 100644--- a/examples/value_scraping.py+++ b/examples/value_scraping.py@@ -1,7 +1,7 @@import osfrom dotenv import load_dotenv-from amazscraper.getter import remover-from amazscraper.class_generator import Generator+from yosoai.getter import remover+from yosoai.class_generator import Generatorload_dotenv()@@ -11,7 +11,7 @@ values = [{"title": "title_website","type": "str",- "description": "Give me the website name"+ "description": "Find the main header title of the website"}]diff --git a/requirements.txt b/requirements.txtindex f4f700fe..439ce74a 100644--- a/requirements.txt+++ b/requirements.txt@@ -2,11 +2,12 @@ beautifulsoup4==4.12.3langchain==0.1.4langchain_core==0.1.16langchain_openai==0.0.5-python-dotenv==1.0.1Requests==2.31.0pytest==8.0.0-wheel==0.42.0tiktoken==0.5.2++python-dotenv==1.0.1+wheel==0.42.0twine==4.0.2sphinx==7.1.2sphinx-rtd-theme==2.0.0\ No newline at end of filediff --git a/setup.py b/setup.pyindex 17761856..0cab4bf3 100644--- a/setup.py+++ b/setup.py@@ -2,12 +2,12 @@from setuptools import setup, find_packagessetup(- name='amazscraper',+ name='yosoai',version='0.1.0', # MAJOR.MINOR.PATCHdescription='A web scraping library using langchain',long_description='A web scraping library using langchain but a longer description',long_description_content_type='text/markdown',- url='https://amazscraper.readthedocs.io/',+ url='https://yoso-ai.readthedocs.io/',author='Marco Vinciguerra',author_email='[email protected]',license='Apache 2.0',@@ -17,13 +17,13 @@ setup('License :: OSI Approved :: Apache Software License','Topic :: Software Development :: Scraping','Programming Language :: Python :: 3',- 'Programming Language :: Python :: 3.6',- 'Programming Language :: Python :: 3.7',- 'Programming Language :: Python :: 3.8','Programming Language :: Python :: 3.9',+ 'Programming Language :: Python :: 3.10',+ 'Programming Language :: Python :: 3.11',+ 'Programming Language :: Python :: 3.12','Operating System :: OS Independent',],- packages = ['amazscraper'],+ packages = ['yosoai'],include_package_data=True,# https://packaging.python.org/en/latest/discussions/install-requires-vs-requirements/install_requires=[@@ -31,8 +31,8 @@ setup('langchain','langchain_core','langchain_openai',- 'python-dotenv','Requests','pytest',+ 'tiktoken',])diff --git a/tests/test_amaz_scraper.py b/tests/test_yosoai.pysimilarity index 60%rename from tests/test_amaz_scraper.pyrename to tests/test_yosoai.pyindex fe9a1795..e11e8b85 100644--- a/tests/test_amaz_scraper.py+++ b/tests/test_yosoai.py@@ -1,12 +1,12 @@import pytest-from amazscraper.pydantic_class import _Response-from amazscraper.class_creator import create_class+from yosoai.pydantic_class import _Response+from yosoai.class_creator import create_classfrom langchain_openai import ChatOpenAI@pytest.fixturedef generator():values = [- {"title": "title_swebsite", "type": "str", "description": "Title of the items"},+ {"title": "title_website", "type": "str", "description": "Title of the items"},]create_class(values)return ChatOpenAI(values)@@ -18,6 +18,6 @@ def test_generator_invocation(generator):def test_response_model():# Test the Response Pydantic model- response_data = {"title_swebsite": "Test Title"}+ response_data = {"title_website": "Test Title"}response = _Response(**response_data)assert response.title_swebsite == "Test Title"\ No newline at end of filediff --git a/amazscraper/__init__.py b/yosoai/__init__.pysimilarity index 100%rename from amazscraper/__init__.pyrename to yosoai/__init__.pydiff --git a/yosoai/class_creator.py b/yosoai/class_creator.pynew file mode 100644index 00000000..9785fdb6--- /dev/null+++ b/yosoai/class_creator.py@@ -0,0 +1,28 @@+import time++def create_class(data_dict: dict):+ """+ This function creates a class at runtime using the values from the list.++ Args:+ data_dict (dict): A dictionary containing the description of the prompt.+ It should have the following keys:+ - "title" (str): The title of the field.+ - "type" (str): The type of the field.+ - "description" (str): The description of the field.++ Returns:+ None+ """++ base_script = """+from langchain_core.pydantic_v1 import BaseModel, Field++class _Response(BaseModel):+ """++ for elem in data_dict:+ base_script = base_script + f" {elem['title']}: {elem['type']} = Field(description='{elem['description']}')\n"++ with open("./pydantic_class.py", "w") as f:+ f.write(base_script)\ No newline at end of filediff --git a/amazscraper/class_generator.py b/yosoai/class_generator.pysimilarity index 80%rename from amazscraper/class_generator.pyrename to yosoai/class_generator.pyindex 2a75bfb1..136a0724 100644--- a/amazscraper/class_generator.py+++ b/yosoai/class_generator.py@@ -7,20 +7,22 @@ from langchain_core.pydantic_v1 import Fieldfrom langchain.output_parsers import PydanticOutputParserclass Generator:- def __init__(self, values:list[dict], api_key:str, temperature_param:float = 0, model_name:str = "gpt-3.5-turbo")->dict:+ def __init__(self, values: list[dict], api_key: str, temperature_param: float = 0, model_name: str = "gpt-3.5-turbo") -> dict:"""Initializes the Generator object.- Parameters:+ Args:values (list): A list of values used for class creation.+ api_key (str): The API key for accessing the language model.temperature_param (float): A parameter controlling the randomness of the language model's output.model_name (str): The name of the language model to be used (default: "gpt-3.5-turbo"). All- the possible models are avaible at the following link: https://platform.openai.com/docs/models+ the possible models are available at the following link: https://platform.openai.com/docs/modelsReturns:result_dict (dict): The result of the language model invocation, converted to a dictionary."""- create_class(values) #in future to remove++ create_class(values) # in future to removeself.parser = PydanticOutputParser(pydantic_object=_Response)diff --git a/amazscraper/getter.py b/yosoai/getter.pysimilarity index 72%rename from amazscraper/getter.pyrename to yosoai/getter.pyindex 8f46be25..ac4852c9 100644--- a/amazscraper/getter.py+++ b/yosoai/getter.py@@ -29,15 +29,15 @@ def truncate_text_tokens(text: str, model: str, encoding_name: str = EMBEDDING_E"""It creates a list of strings to create max dimension tokenizable elements- Parameters:- text (str): text to scrape- model_name (str): The name of the language model to be used (default: "gpt-3.5-turbo"). All- the possible models are available at the following link: https://platform.openai.com/docs/models- encoding_name (str):+ Args:+ text (str): The input text to be truncated into tokenizable elements.+ model (str): The name of the language model to be used.+ encoding_name (str): The name of the encoding to be used (default: EMBEDDING_ENCODING).- Returns- List[str] of elements to send the requests+ Returns:+ List[str]: A list of tokenizable elements created from the input text."""+encoding = tiktoken.get_encoding(encoding_name)max_tokens = models_tokens[model]encoded_text = encoding.encode(text)@@ -53,25 +53,27 @@ def get_function(link:str, param = HEADERS) -> str:"""It sends a GET request to the specified link with optional headers.- Parameters:- link (str): The URL to send the GET request to.- param (dict): Optional headers to include in the request. Default is HEADERS.+ Args:+ link (str): The URL to send the GET request to.+ param (dict): Optional headers to include in the request. Default is HEADERS.Returns:- str: The content of the response as a string.+ str: The content of the response as a string."""response = requests.get(url=link, headers=param)return str(response.content)def remover(file:str) -> str:- '''- This function elaborate the HTML file and remove all the not necessary tag+ """+ This function elaborates the HTML file and remove all the not necessary tag+Parameters:- file (str): the file to parse+ file (str): the file to parseReturns:- str: the parsed file- '''+ str: the parsed file+ """+res = ""isBody = Falsediff --git a/amazscraper/pydantic_class.py b/yosoai/pydantic_class.pysimilarity index 99%rename from amazscraper/pydantic_class.pyrename to yosoai/pydantic_class.pyindex e9b554d1..7af62077 100644--- a/amazscraper/pydantic_class.py+++ b/yosoai/pydantic_class.py@@ -1,4 +1,3 @@-from langchain_core.pydantic_v1 import BaseModel, Fieldclass _Response(BaseModel):diff --git a/yosoai/request.py b/yosoai/request.pynew file mode 100644index 00000000..7c71166f--- /dev/null+++ b/yosoai/request.py@@ -0,0 +1,27 @@+from .getter import remover+from .class_creator import create_class+from .class_generator import Generator++def send_request(values: list[dict]) -> dict:+ """+ Send a request to openai.++ Args:+ values (list[dict]): Settings of the request.+ Format:+ [+ {+ "title": str,+ "type": str,+ "description": str+ }+ ]++ Returns:+ dict: The result of the request to openai.+ """++ res = {}+ create_class("TOADD")++ return res\ No newline at end of file