Skip to content

BaseChatLLM

This is the base module for all Chat LLM (Large Language Model) wrappers. Each specific Chat LLM should extend this base class.

BaseChatLLM

Bases: ABC

Base class for all Chat Large Language Models. Each specific Chat LLM should extend this class.

Parameters:

Name Type Description Default
model str

The model name used in the LLM class.

required
Source code in llmflows/llms/chat_llm.py
class BaseChatLLM(ABC):
    """
    Base class for all Chat Large Language Models. Each specific Chat LLM should extend
    this class.

    Args:
        model (str): The model name used in the LLM class.
    """

    def __init__(self, model: str):
        self.model = model

    @abstractmethod
    def generate(self, message_history: MessageHistory):
        """
        Generates text from the LLM.

        Args:
            message_history: A `MessageHistory` object representing the conversation
                history.

        Returns:
            A string representing the generated text.
        """

    @abstractmethod
    async def generate_async(self, message_history: MessageHistory):
        """
        Generates text from the LLM asynchronously.

        Args:
            message_history: A `MessageHistory` object representing the conversation
                history.

        Returns:
            A string representing the generated text.
        """

generate(message_history) abstractmethod

Generates text from the LLM.

Parameters:

Name Type Description Default
message_history MessageHistory

A MessageHistory object representing the conversation history.

required

Returns:

Type Description

A string representing the generated text.

Source code in llmflows/llms/chat_llm.py
@abstractmethod
def generate(self, message_history: MessageHistory):
    """
    Generates text from the LLM.

    Args:
        message_history: A `MessageHistory` object representing the conversation
            history.

    Returns:
        A string representing the generated text.
    """

generate_async(message_history) abstractmethod async

Generates text from the LLM asynchronously.

Parameters:

Name Type Description Default
message_history MessageHistory

A MessageHistory object representing the conversation history.

required

Returns:

Type Description

A string representing the generated text.

Source code in llmflows/llms/chat_llm.py
@abstractmethod
async def generate_async(self, message_history: MessageHistory):
    """
    Generates text from the LLM asynchronously.

    Args:
        message_history: A `MessageHistory` object representing the conversation
            history.

    Returns:
        A string representing the generated text.
    """