Python scraper based on AI
Python ai-crawlerai-scrapingai-searchcrawlerdata-extractionfirecrawl-alternativelarge-language-modelllmmarkdownragscrapingscraping-pythonweb-crawlerweb-crawlersweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
docs: refactor models docstrings
Marco Perini18c20eb03de1
diff --git a/scrapegraphai/models/azure_openai.py b/scrapegraphai/models/azure_openai.pyindex 4a7c079b..ae47d4e6 100644--- a/scrapegraphai/models/azure_openai.py+++ b/scrapegraphai/models/azure_openai.py@@ -1,19 +1,17 @@"""-Azure Openai configuration wrapper+AzureOpenAI Module"""from langchain_openai import AzureChatOpenAIclass AzureOpenAI(AzureChatOpenAI):- """Class for wrapping openai module"""+ """+ A wrapper for the AzureChatOpenAI class that provides default configuration+ and could be extended with additional methods if needed.++ Args:+ llm_config (dict): Configuration parameters for the language model.+ """def __init__(self, llm_config: dict):- """- A wrapper for the ChatOpenAI class that provides default configuration- and could be extended with additional methods if needed.-- Args:- llm_config (dict): Configuration parameters for the language model.- """- # Initialize the superclass (AzureChatOpenAI) with provided config parameterssuper().__init__(**llm_config)diff --git a/scrapegraphai/models/gemini.py b/scrapegraphai/models/gemini.pyindex e35fd684..91632907 100644--- a/scrapegraphai/models/gemini.py+++ b/scrapegraphai/models/gemini.py@@ -1,20 +1,17 @@"""-Gemini module configuration+Gemini Module"""from langchain_google_genai import ChatGoogleGenerativeAIclass Gemini(ChatGoogleGenerativeAI):- """Class for wrapping gemini module"""+ """+ A wrapper for the Gemini class that provides default configuration+ and could be extended with additional methods if needed.- def __init__(self, llm_config: dict):- """- A wrapper for the Gemini class that provides default configuration- and could be extended with additional methods if needed.+ Args:+ llm_config (dict): Configuration parameters for the language model (e.g., model="gemini-pro")+ """- Args:- llm_config (dict): Configuration parameters for the language model.- such as model="gemini-pro" and api_key- """- # Initialize the superclass (ChatOpenAI) with provided config parameters+ def __init__(self, llm_config: dict):super().__init__(**llm_config)diff --git a/scrapegraphai/models/groq.py b/scrapegraphai/models/groq.pyindex cf2f4755..92d8f8bb 100644--- a/scrapegraphai/models/groq.py+++ b/scrapegraphai/models/groq.py@@ -1,21 +1,18 @@"""-Groq module configuration+Groq Module"""from langchain_groq import ChatGroqclass Groq(ChatGroq):- """Class for wrapping Groq module"""+ """+ A wrapper for the Groq class that provides default configuration+ and could be extended with additional methods if needed.- def __init__(self, llm_config: dict):- """- A wrapper for the Groq class that provides default configuration- and could be extended with additional methods if needed.+ Args:+ llm_config (dict): Configuration parameters for the language model (e.g., model="llama3-70b-8192")+ """- Args:- llm_config (dict): Configuration parameters for the language model.- such as model="llama3-70b-8192" and api_key- """- # Initialize the superclass (ChatOpenAI) with provided config parameters+ def __init__(self, llm_config: dict):super().__init__(**llm_config)\ No newline at end of filediff --git a/scrapegraphai/models/hugging_face.py b/scrapegraphai/models/hugging_face.pyindex d2df52d3..9696db1e 100644--- a/scrapegraphai/models/hugging_face.py+++ b/scrapegraphai/models/hugging_face.py@@ -1,22 +1,17 @@"""-Module for implementing the hugginface class+HuggingFace Module"""from langchain_community.chat_models.huggingface import ChatHuggingFaceclass HuggingFace(ChatHuggingFace):- """Provides a convenient wrapper for interacting with Hugging Face language models- designed for conversational AI applications.+ """+ A wrapper for the HuggingFace class that provides default configuration+ and could be extended with additional methods if needed.Args:- llm_config (dict): A configuration dictionary containing:- * api_key (str, optional): Your Hugging Face API key.- * model_name (str): The name of the Hugging Face LLM to load.- * tokenizer_name (str, optional): Name of the corresponding tokenizer.- * device (str, optional): Device for running the model ('cpu' by default).-+ llm_config (dict): Configuration parameters for the language model."""def __init__(self, llm_config: dict):- """Initializes the HuggingFace chat model wrapper"""super().__init__(**llm_config)diff --git a/scrapegraphai/models/ollama.py b/scrapegraphai/models/ollama.pyindex 9636a257..4bf48178 100644--- a/scrapegraphai/models/ollama.py+++ b/scrapegraphai/models/ollama.py@@ -1,19 +1,17 @@"""-openai configuration wrapper+Ollama Module"""from langchain_community.chat_models import ChatOllamaclass Ollama(ChatOllama):- """Class for wrapping ollama module"""+ """+ A wrapper for the ChatOllama class that provides default configuration+ and could be extended with additional methods if needed.- def __init__(self, llm_config: dict):- """- A wrapper for the ChatOllama class that provides default configuration- and could be extended with additional methods if needed.+ Args:+ llm_config (dict): Configuration parameters for the language model.+ """- Args:- llm_config (dict): Configuration parameters for the language model.- """- # Initialize the superclass (ChatOllama) with provided config parameters+ def __init__(self, llm_config: dict):super().__init__(**llm_config)diff --git a/scrapegraphai/models/openai.py b/scrapegraphai/models/openai.pyindex 7c76a4b1..bfd9d74c 100644--- a/scrapegraphai/models/openai.py+++ b/scrapegraphai/models/openai.py@@ -1,19 +1,17 @@"""-openai configuration wrapper+OpenAI Module"""from langchain_openai import ChatOpenAIclass OpenAI(ChatOpenAI):- """Class for wrapping openai module"""+ """+ A wrapper for the ChatOpenAI class that provides default configuration+ and could be extended with additional methods if needed.- def __init__(self, llm_config: dict):- """- A wrapper for the ChatOpenAI class that provides default configuration- and could be extended with additional methods if needed.+ Args:+ llm_config (dict): Configuration parameters for the language model.+ """- Args:- llm_config (dict): Configuration parameters for the language model.- """- # Initialize the superclass (ChatOpenAI) with provided config parameters+ def __init__(self, llm_config: dict):super().__init__(**llm_config)diff --git a/scrapegraphai/models/openai_itt.py b/scrapegraphai/models/openai_itt.pyindex 0ab8f4ef..5bbdf8ad 100644--- a/scrapegraphai/models/openai_itt.py+++ b/scrapegraphai/models/openai_itt.py@@ -1,6 +1,5 @@"""-This module contains the OpenAIImageToText class,-which is a subclass of ChatOpenAI that is specialized for converting images to text.+OpenAIImageToText Module"""from langchain_openai import ChatOpenAI@@ -9,39 +8,27 @@ from langchain_core.messages import HumanMessageclass OpenAIImageToText(ChatOpenAI):"""- A class that uses OpenAI's Chat API to convert an image to text.+ A wrapper for the OpenAIImageToText class that provides default configuration+ and could be extended with additional methods if needed.Args:- llm_config (dict): The configuration for the language model.-- Attributes:- max_tokens (int): The maximum number of tokens to generate in the response.-- Methods:- run(image_url): Runs the image-to-text conversion using the provided image URL.+ llm_config (dict): Configuration parameters for the language model.+ max_tokens (int): The maximum number of tokens to generate."""def __init__(self, llm_config: dict):- """- Initializes an instance of the OpenAIImageToText class.-- Args:- llm_config (dict): The configuration for the language model.-- """super().__init__(**llm_config, max_tokens=256)- def run(self, image_url: str):+ def run(self, image_url: str) -> str:"""Runs the image-to-text conversion using the provided image URL.Args:- image_url (str): The URL of the image to convert to text.+ image_url (str): The URL of the image to convert.Returns:- str: The generated text description of the image.-+ str: The text description of the image."""message = HumanMessage(content=[diff --git a/scrapegraphai/models/openai_tts.py b/scrapegraphai/models/openai_tts.pyindex f2227f8c..a4432398 100644--- a/scrapegraphai/models/openai_tts.py+++ b/scrapegraphai/models/openai_tts.py@@ -1,6 +1,5 @@"""-This module contains the OpenAITextToSpeech class, which uses OpenAI's API-to convert text into speech.+OpenAITextToSpeech Module"""from openai import OpenAI@@ -8,44 +7,33 @@ from openai import OpenAIclass OpenAITextToSpeech:"""- A class that uses OpenAI's API to convert text to speech.-- Args:- llm_config (dict): The configuration for the language model.+ Implements a text-to-speech model using the OpenAI API.Attributes:+ client (OpenAI): The OpenAI client used to interact with the API.model (str): The model to use for text-to-speech conversion.voice (str): The voice model to use for generating speech.- Methods:- run(text): Converts the provided text to speech and returns the- bytes of the generated speech.+ Args:+ tts_config (dict): Configuration parameters for the text-to-speech model."""def __init__(self, tts_config: dict):- """- Initializes an instance of the OpenAITextToSpeech class.-- Args:- llm_config (dict): The configuration for the language model.- model (str, optional): The model to use for text-to-speech conversion.- Defaults to "tts-1".- voice (str, optional): The voice model to use for generating speech.- Defaults to "alloy".- """# convert model_name to modelself.client = OpenAI(api_key=tts_config.get("api_key"))self.model = tts_config.get("model", "tts-1")self.voice = tts_config.get("voice", "alloy")- def run(self, text):+ def run(self, text: str) -> bytes:"""Converts the provided text to speech and returns the bytes of the generated speech.Args:text (str): The text to convert to speech.+ Returns:+ bytes: The bytes of the generated speech audio."""response = self.client.audio.speech.create(model=self.model,