fluxion_ai.core.modules.api_module module

fluxion_ai.modules.api_module

Provides an abstract base class for interacting with external APIs.

This module defines the ApiModule base class, which abstracts common API interaction patterns such as sending POST requests and processing responses.

class fluxion_ai.core.modules.api_module.ApiModule(endpoint: str, headers: dict = None, timeout: int = 10)[source]

Bases: ABC

Abstract base class for interacting with APIs.

This class provides common functionality for making POST requests and processing responses while allowing subclasses to define specific behavior via abstract methods.

abstractmethod execute(*args, **kwargs)[source]

Abstract method for executing the API call.

Subclasses must implement this method to define the logic for making API calls and processing the results.

Parameters:
  • *args – Positional arguments for the API call.

  • **kwargs – Keyword arguments for the API call.

Returns:

The result of the API call.

Return type:

Any

get_response(data: Dict[str, str], **kwargs) Dict[str, str][source]

Sends a POST request to the API endpoint and returns the response.

Parameters:
  • data (dict) – The data to send in the POST request.

  • **kwargs – Additional arguments to pass to the requests library.

Returns:

The parsed JSON response from the API.

Return type:

dict

Raises:

RuntimeError – If the API response contains an error key.

abstractmethod post_process(response: Dict[str, Any], full_response: bool = False)[source]

Abstract method for post-processing API responses.

Subclasses must implement this method to handle the processing of the raw response returned by the API.

Parameters:
  • response (dict) – The raw response from the API.

  • full_response (bool, optional) – Whether to return the full response or a processed subset. Defaults to False.

Returns:

The processed response data.

Return type:

Any