Utility functions and classes#
Module defining public utility functions and classes 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.
- 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()
- class contextgem.public.utils.JsonObjectClassStruct[source]#
Bases:
object
A base class that automatically converts class hierarchies to dictionary representations.
This class enables the use of existing class hierarchies (such as dataclasses or Pydantic models) with nested type hints as a structure definition for JsonObjectConcept. When you need to use typed class hierarchies with JsonObjectConcept, inherit from this class in all parts of your class structure.
- Example:
- Using JsonObjectClassStruct for class hierarchies#
from dataclasses import dataclass from contextgem import JsonObjectClassStruct, JsonObjectConcept @dataclass class Address(JsonObjectClassStruct): street: str city: str country: str @dataclass class Contact(JsonObjectClassStruct): email: str phone: str address: Address @dataclass class Person(JsonObjectClassStruct): name: str age: int contact: Contact # Use the class structure with JsonObjectConcept # JsonObjectClassStruct enables automatic conversion of typed class hierarchies # into the dictionary structure required by JsonObjectConcept, preserving the # type information and nested relationships between classes. JsonObjectConcept(name="person", description="Person information", structure=Person)