Class ZCL_LLM_HTTP_CLIENT_WRAPPER
AI Generated documentation.
Overview
The zcl_llm_http_client_wrapper
class provides a wrapper for HTTP client functionality, specifically designed for LLM (Large Language Model) service communications. It encapsulates HTTP client handling, header management, and communication logging.
Public methods:
constructor
: Creates a new instance with client and provider configurationsget_client
: Creates and returns a new HTTP client wrapper instanceset_header
: Sets HTTP request headersset_url
: Sets the target URL for the requestcommunicate
: Handles HTTP POST communication including request/response handlingclose_client
: Closes the HTTP client connection
The class implements the zif_llm_http_client_wrapper
interface and provides a standardized way to handle HTTP communications with LLM providers.
Dependencies
if_http_client
: SAP standard HTTP client interfacezcx_llm_validation
: Custom exception class for validation errorszcx_llm_http_error
: Custom exception class for HTTP errorszif_llm_call_logger
: Interface for logging LLM callszllm_clnt_config
: Configuration structure for client settingszllm_providers
: Configuration structure for provider settings
Details
The class implements a robust HTTP client wrapper with several key features:
- Session Management:
flowchart LR
A[Constructor] --> B[Create HTTP Client]
B --> C[Configure Client]
C --> D[Set Headers]
D --> E[Ready for Communication]
E --> F[Close Client]
- Communication Flow:
flowchart TD
A[communicate method] --> B[Set POST Method]
B --> C[Set Content-Type]
C --> D{URL Set?}
D -->|Yes| E[Set Request URI]
D -->|No| F[Use Default URI]
E --> G[Send Request]
F --> G
G --> H[Receive Response]
H --> I[Log Call]
I --> J[Reset Request if needed]
The class includes sophisticated error handling and logging mechanisms:
- HTTP communication failures are caught and transformed into specific exceptions
- All communications are logged through the call logger implementation
- Request headers are preserved between calls while maintaining security
- Response codes >= 300 are handled with detailed error messages
- The class supports RFC destination-based communication configuration
Special attention is given to maintaining state between requests by preserving non-SAP headers while cleaning up internal ones, making it suitable for stateful communications with LLM providers.