Output_extractor

This module contains functionality related to the the output_extractor module for augmentation.components.llms.openai_like.

Output_extractor

OpenAILikeLlamaindexLLMOutputExtractor

Bases: BaseLlamaindexLLMOutputExtractor

OpenAI Llamaindex LLM Output Extractor.

Source code in src/augmentation/components/llms/openai_like/output_extractor.py
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
class OpenAILikeLlamaindexLLMOutputExtractor(BaseLlamaindexLLMOutputExtractor):
    """OpenAI Llamaindex LLM Output Extractor."""

    def get_text(self, trace: TraceWithDetails) -> str:
        """
        Extracts the text from the trace output.

        Args:
            trace (TraceWithDetails): The trace with details.

        Returns:
            str: The extracted text.
        """
        return trace.output["text"]

    def get_generated_by_model(self, trace: TraceWithDetails) -> str:
        """
        Extracts the model name from the trace output.

        Args:
            trace (TraceWithDetails): The trace with details.

        Returns:
            str: The name of the model.
        """
        return trace.output["raw"]["model"]

get_generated_by_model(trace)

Extracts the model name from the trace output.

Parameters:
  • trace (TraceWithDetails) –

    The trace with details.

Returns:
  • str( str ) –

    The name of the model.

Source code in src/augmentation/components/llms/openai_like/output_extractor.py
31
32
33
34
35
36
37
38
39
40
41
def get_generated_by_model(self, trace: TraceWithDetails) -> str:
    """
    Extracts the model name from the trace output.

    Args:
        trace (TraceWithDetails): The trace with details.

    Returns:
        str: The name of the model.
    """
    return trace.output["raw"]["model"]

get_text(trace)

Extracts the text from the trace output.

Parameters:
  • trace (TraceWithDetails) –

    The trace with details.

Returns:
  • str( str ) –

    The extracted text.

Source code in src/augmentation/components/llms/openai_like/output_extractor.py
19
20
21
22
23
24
25
26
27
28
29
def get_text(self, trace: TraceWithDetails) -> str:
    """
    Extracts the text from the trace output.

    Args:
        trace (TraceWithDetails): The trace with details.

    Returns:
        str: The extracted text.
    """
    return trace.output["text"]

OpenAILikeLlamaindexLLMOutputExtractorFactory

Bases: Factory

Factory class to create OpenAILikeLlamaindexLLMOutputExtractor instances.

Source code in src/augmentation/components/llms/openai_like/output_extractor.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class OpenAILikeLlamaindexLLMOutputExtractorFactory(Factory):
    """Factory class to create OpenAILikeLlamaindexLLMOutputExtractor instances."""

    _configuration_class: Type = OpenAILikeLLMConfiguration

    @classmethod
    def _create_instance(
        cls, configuration: OpenAILikeLLMConfiguration
    ) -> OpenAILikeLlamaindexLLMOutputExtractor:
        """Creates an instance of OpenAILikeLlamaindexLLMOutputExtractor.

        Args:
            configuration (OpenAILikeLLMConfiguration): The configuration for the LLM.

        Returns:
            OpenAILikeLlamaindexLLMOutputExtractor: An instance of the extractor.
        """
        return OpenAILikeLlamaindexLLMOutputExtractor(configuration)