docs: refactor models docstrings

This commit is contained in:
Marco Perini 2024-05-01 23:33:42 +02:00
parent 1409797475
commit 18c20eb03d
8 changed files with 61 additions and 103 deletions

View File

@ -1,19 +1,17 @@
""" """
Azure Openai configuration wrapper AzureOpenAI Module
""" """
from langchain_openai import AzureChatOpenAI from langchain_openai import AzureChatOpenAI
class AzureOpenAI(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): 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) super().__init__(**llm_config)

View File

@ -1,20 +1,17 @@
""" """
Gemini module configuration Gemini Module
""" """
from langchain_google_genai import ChatGoogleGenerativeAI from langchain_google_genai import ChatGoogleGenerativeAI
class Gemini(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): 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) super().__init__(**llm_config)

View File

@ -1,21 +1,18 @@
""" """
Groq module configuration Groq Module
""" """
from langchain_groq import ChatGroq from langchain_groq import ChatGroq
class Groq(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): 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) super().__init__(**llm_config)

View File

@ -1,22 +1,17 @@
""" """
Module for implementing the hugginface class HuggingFace Module
""" """
from langchain_community.chat_models.huggingface import ChatHuggingFace from langchain_community.chat_models.huggingface import ChatHuggingFace
class HuggingFace(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: Args:
llm_config (dict): A configuration dictionary containing: llm_config (dict): Configuration parameters for the language model.
* 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).
""" """
def __init__(self, llm_config: dict): def __init__(self, llm_config: dict):
"""Initializes the HuggingFace chat model wrapper"""
super().__init__(**llm_config) super().__init__(**llm_config)

View File

@ -1,19 +1,17 @@
""" """
openai configuration wrapper Ollama Module
""" """
from langchain_community.chat_models import ChatOllama from langchain_community.chat_models import ChatOllama
class Ollama(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): 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) super().__init__(**llm_config)

View File

@ -1,19 +1,17 @@
""" """
openai configuration wrapper OpenAI Module
""" """
from langchain_openai import ChatOpenAI from langchain_openai import ChatOpenAI
class OpenAI(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): 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) super().__init__(**llm_config)

View File

@ -1,6 +1,5 @@
""" """
This module contains the OpenAIImageToText class, OpenAIImageToText Module
which is a subclass of ChatOpenAI that is specialized for converting images to text.
""" """
from langchain_openai import ChatOpenAI from langchain_openai import ChatOpenAI
@ -9,39 +8,27 @@ from langchain_core.messages import HumanMessage
class OpenAIImageToText(ChatOpenAI): 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: Args:
llm_config (dict): The configuration for the language model. llm_config (dict): Configuration parameters for the language model.
max_tokens (int): The maximum number of tokens to generate.
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.
""" """
def __init__(self, llm_config: dict): 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) 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. Runs the image-to-text conversion using the provided image URL.
Args: Args:
image_url (str): The URL of the image to convert to text. image_url (str): The URL of the image to convert.
Returns: Returns:
str: The generated text description of the image. str: The text description of the image.
""" """
message = HumanMessage( message = HumanMessage(
content=[ content=[

View File

@ -1,6 +1,5 @@
""" """
This module contains the OpenAITextToSpeech class, which uses OpenAI's API OpenAITextToSpeech Module
to convert text into speech.
""" """
from openai import OpenAI from openai import OpenAI
@ -8,44 +7,33 @@ from openai import OpenAI
class OpenAITextToSpeech: class OpenAITextToSpeech:
""" """
A class that uses OpenAI's API to convert text to speech. Implements a text-to-speech model using the OpenAI API.
Args:
llm_config (dict): The configuration for the language model.
Attributes: Attributes:
client (OpenAI): The OpenAI client used to interact with the API.
model (str): The model to use for text-to-speech conversion. model (str): The model to use for text-to-speech conversion.
voice (str): The voice model to use for generating speech. voice (str): The voice model to use for generating speech.
Methods: Args:
run(text): Converts the provided text to speech and returns the tts_config (dict): Configuration parameters for the text-to-speech model.
bytes of the generated speech.
""" """
def __init__(self, tts_config: dict): 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 # convert model_name to model
self.client = OpenAI(api_key=tts_config.get("api_key")) self.client = OpenAI(api_key=tts_config.get("api_key"))
self.model = tts_config.get("model", "tts-1") self.model = tts_config.get("model", "tts-1")
self.voice = tts_config.get("voice", "alloy") 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. Converts the provided text to speech and returns the bytes of the generated speech.
Args: Args:
text (str): The text to convert to speech. text (str): The text to convert to speech.
Returns:
bytes: The bytes of the generated speech audio.
""" """
response = self.client.audio.speech.create( response = self.client.audio.speech.create(
model=self.model, model=self.model,