Utility functions

Utility functions#

Module defining public utility functions of the framework.

contextgem.public.utils.image_to_base64(image_path)[source]#

Converts an image file to its Base64 encoded string representation.

Helper function that can be used when constructing Image objects.

Parameters:

image_path (str | Path) – The path to the image file to be encoded.

Returns:

A Base64 encoded string representation of the image.

Return type:

str

contextgem.public.utils.reload_logger_settings()[source]#

Reloads logger settings from environment variables.

This function should be called when environment variables related to logging have been changed after the module was imported. It re-reads the environment variables and reconfigures the logger accordingly.

Returns:

None

Example:
Reload logger settings#
import os

from contextgem import reload_logger_settings

# Initial logger settings are loaded from environment variables at import time

# Change logger level to WARNING
os.environ["CONTEXTGEM_LOGGER_LEVEL"] = "WARNING"
print("Setting logger level to WARNING")
reload_logger_settings()
# Now the logger will only show WARNING level and above messages

# Disable the logger completely
os.environ["CONTEXTGEM_DISABLE_LOGGER"] = "True"
print("Disabling the logger")
reload_logger_settings()
# Now the logger is disabled and won't show any messages

# You can re-enable the logger by setting CONTEXTGEM_DISABLE_LOGGER to "False"
# os.environ["CONTEXTGEM_DISABLE_LOGGER"] = "False"
# reload_logger_settings()