Base_output_extractor

This module contains functionality related to the the base_output_extractor module for augmentation.components.llms.core.

Base_output_extractor

BaseLlamaindexLLMOutputExtractor

Bases: ABC

Output field within TraceWithDetails is a dictionary, which structure depends on the LLM provider. This class provides an interface for extracting the text and model name from the output field of TraceWithDetails for different LLM providers. The actual extraction logic is implemented in subclasses for each specific LLM provider.

Source code in src/augmentation/components/llms/core/base_output_extractor.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class BaseLlamaindexLLMOutputExtractor(ABC):
    """Output field within `TraceWithDetails` is a dictionary, which structure
    depends on the LLM provider. This class provides an interface for extracting
    the text and model name from the output field of `TraceWithDetails` for
    different LLM providers. The actual extraction logic is implemented in
    subclasses for each specific LLM provider.
    """

    def __init__(self, configuration: LLMConfiguration):
        """Initializes the output extractor with the given configuration.

        Args:
            configuration (LLMConfiguration): The configuration for the LLM.
        """
        self.configuration = configuration

    @abstractmethod
    def get_text(cls, trace: TraceWithDetails) -> str:
        """Extracts the text from the trace.

        Args:
            trace (TraceWithDetails): The trace object containing the output.

        Returns:
            str: The extracted text.
        """
        pass

    @abstractmethod
    def get_generated_by_model(cls, trace: TraceWithDetails) -> str:
        """Extracts the model used to generate the output from the trace.

        Args:
            trace (TraceWithDetails): The trace object containing the output.

        Returns:
            str: The model name.
        """
        pass

__init__(configuration)

Initializes the output extractor with the given configuration.

Parameters:
  • configuration (LLMConfiguration) –

    The configuration for the LLM.

Source code in src/augmentation/components/llms/core/base_output_extractor.py
20
21
22
23
24
25
26
def __init__(self, configuration: LLMConfiguration):
    """Initializes the output extractor with the given configuration.

    Args:
        configuration (LLMConfiguration): The configuration for the LLM.
    """
    self.configuration = configuration

get_generated_by_model(trace) abstractmethod

Extracts the model used to generate the output from the trace.

Parameters:
  • trace (TraceWithDetails) –

    The trace object containing the output.

Returns:
  • str( str ) –

    The model name.

Source code in src/augmentation/components/llms/core/base_output_extractor.py
40
41
42
43
44
45
46
47
48
49
50
@abstractmethod
def get_generated_by_model(cls, trace: TraceWithDetails) -> str:
    """Extracts the model used to generate the output from the trace.

    Args:
        trace (TraceWithDetails): The trace object containing the output.

    Returns:
        str: The model name.
    """
    pass

get_text(trace) abstractmethod

Extracts the text from the trace.

Parameters:
  • trace (TraceWithDetails) –

    The trace object containing the output.

Returns:
  • str( str ) –

    The extracted text.

Source code in src/augmentation/components/llms/core/base_output_extractor.py
28
29
30
31
32
33
34
35
36
37
38
@abstractmethod
def get_text(cls, trace: TraceWithDetails) -> str:
    """Extracts the text from the trace.

    Args:
        trace (TraceWithDetails): The trace object containing the output.

    Returns:
        str: The extracted text.
    """
    pass