Skip to content

BaseLLM

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

BaseLLM

Bases: ABC

Base class for all Large Language Models (LLMs). Each specific 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/llm.py
class BaseLLM(ABC):
    """
    Base class for all Large Language Models (LLMs). Each specific 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, prompt: str):
        """
        Generates text from the LLM.

        Args:
            prompt: A string representing the prompt to generate text from.

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

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

        Args:
            prompt: A string representing the prompt to generate text from.

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

generate(prompt) abstractmethod

Generates text from the LLM.

Parameters:

Name Type Description Default
prompt str

A string representing the prompt to generate text from.

required

Returns:

Type Description

A string representing the generated text.

Source code in llmflows/llms/llm.py
@abstractmethod
def generate(self, prompt: str):
    """
    Generates text from the LLM.

    Args:
        prompt: A string representing the prompt to generate text from.

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

generate_async(prompt) abstractmethod async

Generates text from the LLM asynchronously.

Parameters:

Name Type Description Default
prompt str

A string representing the prompt to generate text from.

required

Returns:

Type Description

A string representing the generated text.

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

    Args:
        prompt: A string representing the prompt to generate text from.

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