Llm

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

Llm

OpenaAILikeLLMFactory

Bases: SingletonFactory

Factory for creating and managing OpenAI-like LLM instances.

This singleton factory creates and caches OpenAILike instances based on the provided configuration. It ensures that only one instance is created for each unique configuration.

Attributes:
  • _configuration_class (Type) –

    The configuration class used to create instances.

Source code in src/augmentation/components/llms/openai_like/llm.py
11
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
51
52
class OpenaAILikeLLMFactory(SingletonFactory):
    """
    Factory for creating and managing OpenAI-like LLM instances.

    This singleton factory creates and caches OpenAILike instances
    based on the provided configuration. It ensures that only one
    instance is created for each unique configuration.

    Attributes:
        _configuration_class: The configuration class used to create instances.
    """

    _configuration_class: Type = OpenAILikeLLMConfiguration

    @classmethod
    def _create_instance(
        cls, configuration: OpenAILikeLLMConfiguration
    ) -> OpenAILike:
        """
        Create a new OpenAILike LLM instance based on the provided configuration.

        This method extracts the necessary parameters from the configuration
        object and initializes an OpenAILike instance with the appropriate
        settings for API access and model behavior.

        Args:
            configuration: Configuration object containing API credentials
                           and model parameters

        Returns:
            A configured OpenAILike instance ready for use
        """
        return OpenAILike(
            api_base=configuration.secrets.api_base.get_secret_value(),
            api_key=configuration.secrets.api_key.get_secret_value(),
            model=configuration.name,
            max_tokens=configuration.max_tokens,
            max_retries=configuration.max_retries,
            context_window=configuration.context_window,
            logprobs=None,
            api_version="",
        )