Skip to content

Class ZCL_LLM_FACTORY

AI Generated documentation.

Overview

The zcl_llm_factory class serves as a factory for creating LLM (Large Language Model) clients. It implements the zif_llm_factory interface and provides a single public method get_client to instantiate LLM clients based on specified models. The class follows the factory pattern and handles validation of model and provider configurations while enforcing authorization checks.

Key features:

  • Singleton pattern implementation (private constructor)
  • Model-based client instantiation
  • Configuration validation
  • Authorization checks
  • Dynamic provider class instantiation

Dependencies

  • Database Tables:
  • ZLLM_CLNT_CONFIG: Stores client configurations
  • ZLLM_PROVIDERS: Stores provider configurations
  • Interfaces:
  • zif_llm_factory: Factory interface
  • zif_llm_auth: Authorization interface
  • Classes:
  • zcl_llm_common: Utility class for BADI handling
  • zcx_llm_validation: Validation exception class

Details

The class implements a sophisticated factory pattern with multiple validation and configuration layers.

flowchart TD
    A[get_client] --> B{Auth Check}
    B -->|Failed| C[Auth Exception]
    B -->|Passed| D{Check Model Config}
    D -->|Not Found| E[Model Validation Exception]
    D -->|Found| F{Check Provider Config}
    F -->|Not Found| G[Provider Validation Exception]
    F -->|Found| H[Dynamic Provider Instantiation]
    H --> I[Return Client Instance]

Key implementation aspects:

  1. Authorization Layer:
  2. Initialized during class construction via BADI
  3. Performs pre-validation checks before client creation

  4. Configuration Validation:

  5. Two-step validation process checking both model and provider
  6. Uses database tables for configuration storage
  7. Throws specific validation exceptions for different error cases

  8. Dynamic Provider Instantiation:

  9. Uses dynamic method calls to create provider-specific clients
  10. Passes both client and provider configurations to the instantiated class
  11. Allows for flexible provider implementation without factory modifications

The class is designed to be extensible, allowing new providers to be added through configuration rather than code changes.