From 18c20eb03de183a0311be5ffe21f53ec4edf1b87 Mon Sep 17 00:00:00 2001 From: Marco Perini Date: Wed, 1 May 2024 23:33:42 +0200 Subject: [PATCH] docs: refactor models docstrings --- scrapegraphai/models/azure_openai.py | 18 ++++++++--------- scrapegraphai/models/gemini.py | 19 ++++++++---------- scrapegraphai/models/groq.py | 19 ++++++++---------- scrapegraphai/models/hugging_face.py | 15 +++++--------- scrapegraphai/models/ollama.py | 18 ++++++++--------- scrapegraphai/models/openai.py | 18 ++++++++--------- scrapegraphai/models/openai_itt.py | 29 ++++++++-------------------- scrapegraphai/models/openai_tts.py | 28 ++++++++------------------- 8 files changed, 61 insertions(+), 103 deletions(-) diff --git a/scrapegraphai/models/azure_openai.py b/scrapegraphai/models/azure_openai.py index 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 AzureChatOpenAI class 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 parameters super().__init__(**llm_config) diff --git a/scrapegraphai/models/gemini.py b/scrapegraphai/models/gemini.py index 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 ChatGoogleGenerativeAI class 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. + + Args: + llm_config (dict): Configuration parameters for the language model (e.g., model="gemini-pro") + """ 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. - such as model="gemini-pro" and api_key - """ - # Initialize the superclass (ChatOpenAI) with provided config parameters super().__init__(**llm_config) diff --git a/scrapegraphai/models/groq.py b/scrapegraphai/models/groq.py index 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 ChatGroq class 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. + + Args: + llm_config (dict): Configuration parameters for the language model (e.g., model="llama3-70b-8192") + """ 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. - such as model="llama3-70b-8192" and api_key - """ - # Initialize the superclass (ChatOpenAI) with provided config parameters super().__init__(**llm_config) \ No newline at end of file diff --git a/scrapegraphai/models/hugging_face.py b/scrapegraphai/models/hugging_face.py index 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 ChatHuggingFace class 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.py index 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 ChatOllama class 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. + + Args: + llm_config (dict): Configuration parameters for the language model. + """ 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. - """ - # Initialize the superclass (ChatOllama) with provided config parameters super().__init__(**llm_config) diff --git a/scrapegraphai/models/openai.py b/scrapegraphai/models/openai.py index 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 ChatOpenAI class 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. + + 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 (ChatOpenAI) with provided config parameters super().__init__(**llm_config) diff --git a/scrapegraphai/models/openai_itt.py b/scrapegraphai/models/openai_itt.py index 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 HumanMessage class 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.py index 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 OpenAI class 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 model self.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,