Skip to content

Commit

Permalink
docs: refactor models docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
PeriniM committed May 1, 2024
1 parent 1409797 commit 18c20eb
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 103 deletions.
18 changes: 8 additions & 10 deletions 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)
19 changes: 8 additions & 11 deletions 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.
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)
19 changes: 8 additions & 11 deletions 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.
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)
15 changes: 5 additions & 10 deletions 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)
18 changes: 8 additions & 10 deletions 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.
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)
18 changes: 8 additions & 10 deletions 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.
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)
29 changes: 8 additions & 21 deletions 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
Expand All @@ -9,39 +8,27 @@

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=[
Expand Down
28 changes: 8 additions & 20 deletions scrapegraphai/models/openai_tts.py
@@ -1,51 +1,39 @@
"""
This module contains the OpenAITextToSpeech class, which uses OpenAI's API
to convert text into speech.
OpenAITextToSpeech Module
"""

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,
Expand Down

0 comments on commit 18c20eb

Please sign in to comment.