mirror of
https://github.com/VinciGit00/Scrapegraph-ai.git
synced 2026-06-23 21:00:30 +08:00
docs: refactor models docstrings
This commit is contained in:
parent
1409797475
commit
18c20eb03d
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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=[
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user