Dependency injection#
Dependency Container#
genai_monitor.injectors.containers.DependencyContainer
#
Bases: DeclarativeContainer
Dependency container for the application.
wrapper_factory
class-attribute
instance-attribute
#
wrapper_factory = Singleton(provides=WrapperFactory)
wrapper_registry
class-attribute
instance-attribute
#
wrapper_registry = Singleton(
provides=WrapperRegistry,
wrapper_factory=wrapper_factory,
)
session_manager
class-attribute
instance-attribute
#
session_manager = Factory(
provides=SessionManager, database_url=url
)
db_manager
class-attribute
instance-attribute
#
db_manager = Factory(
provides=DBManager, session_manager=session_manager
)
persistency_manager
class-attribute
instance-attribute
#
persistency_manager = Singleton(
provides=PersistencyManager, path=path, enabled=enabled
)
runtime_manager
class-attribute
instance-attribute
#
runtime_manager = Singleton(provides=RuntimeManager)
artifact_wrapper_factory
class-attribute
instance-attribute
#
artifact_wrapper_factory = Singleton(
provides=ArtifactWrapperFactory
)
artifact_registry
class-attribute
instance-attribute
#
artifact_registry = Singleton(
provides=ArtifactRegistry,
artifact_wrapper_factory=artifact_wrapper_factory,
)
default_hashing_function
class-attribute
instance-attribute
#
default_hashing_function = Object(
provides=default_model_hashing_function
)
transformers_output_parser
class-attribute
instance-attribute
#
transformers_conditioning_parser
class-attribute
instance-attribute
#
transformers_hashing_function
class-attribute
instance-attribute
#
transformers_json_path
class-attribute
instance-attribute
#
transformers_json_path = Factory(
get_absolute_path,
_TRANSFORMERS_JSON_PATH,
relative_to=abspath(__file__),
)
transformers_class_def_collection
class-attribute
instance-attribute
#
transformers_class_def_collection = Factory(
from_json, json_path=transformers_json_path
)
register_transformers
class-attribute
instance-attribute
#
register_transformers = Callable(
register_class_collection,
definition_collection=transformers_class_def_collection,
registry=wrapper_registry,
db_manager=db_manager,
persistency_manager=persistency_manager,
runtime_manager=runtime_manager,
output_parser=transformers_output_parser,
conditioning_parser=transformers_conditioning_parser,
hashing_function=transformers_hashing_function,
)
openai_output_parser
class-attribute
instance-attribute
#
openai_conditioning_parser
class-attribute
instance-attribute
#
empty_model_hash
class-attribute
instance-attribute
#
providers_json_path
class-attribute
instance-attribute
#
providers_json_path = Factory(
get_absolute_path,
_PROVIDERS_JSON_PATH,
relative_to=abspath(__file__),
)
providers_class_def_collection
class-attribute
instance-attribute
#
providers_class_def_collection = Factory(
from_json, json_path=providers_json_path
)
register_providers
class-attribute
instance-attribute
#
register_providers = Callable(
register_class_collection,
definition_collection=providers_class_def_collection,
registry=wrapper_registry,
db_manager=db_manager,
persistency_manager=persistency_manager,
runtime_manager=runtime_manager,
output_parser=openai_output_parser,
conditioning_parser=openai_conditioning_parser,
hashing_function=empty_model_hash,
)
diffusers_output_parser
class-attribute
instance-attribute
#
diffusers_conditioning_parser
class-attribute
instance-attribute
#
diffusers_hashing_function
class-attribute
instance-attribute
#
diffusers_json_path
class-attribute
instance-attribute
#
diffusers_json_path = Factory(
get_absolute_path,
_DIFFUSERS_JSON_PATH,
relative_to=abspath(__file__),
)
diffusers_class_def_collection
class-attribute
instance-attribute
#
diffusers_class_def_collection = Factory(
from_json, json_path=diffusers_json_path
)
register_diffusers
class-attribute
instance-attribute
#
register_diffusers = Callable(
register_class_collection,
definition_collection=diffusers_class_def_collection,
registry=wrapper_registry,
db_manager=db_manager,
persistency_manager=persistency_manager,
runtime_manager=runtime_manager,
output_parser=diffusers_output_parser,
conditioning_parser=diffusers_conditioning_parser,
hashing_function=diffusers_hashing_function,
)
litellm_output_parser
class-attribute
instance-attribute
#
litellm_conditioning_parser
class-attribute
instance-attribute
#
litellm_json_path
class-attribute
instance-attribute
#
litellm_json_path = Factory(
get_absolute_path,
_LITELLM_JSON_PATH,
relative_to=abspath(__file__),
)
litellm_def_collection
class-attribute
instance-attribute
#
litellm_def_collection = Factory(
from_json, json_path=litellm_json_path
)
register_litellm
class-attribute
instance-attribute
#
register_litellm = Callable(
register_function_collection,
definition_collection=litellm_def_collection,
registry=wrapper_registry,
db_manager=db_manager,
persistency_manager=persistency_manager,
runtime_manager=runtime_manager,
output_parser=litellm_output_parser,
conditioning_parser=litellm_conditioning_parser,
hashing_function=get_function_full_path,
)
genai_monitor.injectors.containers.get_container
#
get_container() -> DependencyContainer
Get the dependency container.
RETURNS | DESCRIPTION |
---|---|
DependencyContainer
|
The dependency container. |
Source code in src/genai_monitor/injectors/containers.py
Registry#
genai_monitor.injectors.registry.WrapperRegistry
#
Registry for function wrappers.
This class is responsible for registering and unregistering wrappers.
ATTRIBUTE | DESCRIPTION |
---|---|
_wrapper_factory |
Factory for creating wrappers.
TYPE:
|
_registry |
Dictionary of registered wrappers.
TYPE:
|
register
#
register(
func: Callable,
db_manager: DBManager,
persistency_manager: PersistencyManager,
runtime_manager: RuntimeManager,
output_parser: BaseModelOutputParser,
conditioning_parser: BaseConditioningParser,
hashing_function: Callable[[Any], str],
max_unique_instances: int = 1,
)
Register a function with the registry.
PARAMETER | DESCRIPTION |
---|---|
func
|
The function or method to register.
TYPE:
|
db_manager
|
The database manager.
TYPE:
|
persistency_manager
|
The persistency manager.
TYPE:
|
runtime_manager
|
The runtime manager.
TYPE:
|
output_parser
|
The output parser.
TYPE:
|
conditioning_parser
|
The conditioning parser.
TYPE:
|
hashing_function
|
The hashing function.
TYPE:
|
max_unique_instances
|
The maximum number of unique sample instances for each conditioning.
TYPE:
|
Source code in src/genai_monitor/injectors/registry.py
unregister
#
Unregister a function from the registry.
PARAMETER | DESCRIPTION |
---|---|
func
|
The function to unregister.
TYPE:
|
Source code in src/genai_monitor/injectors/registry.py
get_registered_list
#
Get a list of registered functions.
RETURNS | DESCRIPTION |
---|---|
List[str]
|
A list of registered functions. |
genai_monitor.injectors.registry.ArtifactRegistry
#
Artifact registry.
ATTRIBUTE | DESCRIPTION |
---|---|
_artifact_wrapper_factory |
Factory for creating artifact wrappers.
TYPE:
|
_registry |
Dictionary of registered artifacts (both forward and backward tracking).
TYPE:
|
register
#
register(
func: Callable,
direction: str,
db_manager: DBManager,
persistency_manager: PersistencyManager,
runtime_manager: RuntimeManager,
)
Registers an artifact function or method.
PARAMETER | DESCRIPTION |
---|---|
func
|
The function or method to register.
TYPE:
|
direction
|
The direction of the artifact (either 'forward' or 'backward').
TYPE:
|
db_manager
|
The database manager.
TYPE:
|
persistency_manager
|
The persistency manager.
TYPE:
|
runtime_manager
|
The runtime manager.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the direction is not 'forward' or 'backward'. |
Source code in src/genai_monitor/injectors/registry.py
unregister
#
Removes an artifact function or method from the registry.
PARAMETER | DESCRIPTION |
---|---|
func
|
The function or method to unregister.
TYPE:
|
direction
|
The direction of the artifact (either 'forward' or 'backward').
TYPE:
|
Source code in src/genai_monitor/injectors/registry.py
Wrappers#
Inference#
genai_monitor.injectors.wrapper.MethodWrapper
#
Bases: Wrapper
Wrapper for class methods.
wrap
#
Source code in src/genai_monitor/injectors/wrapper.py
attach_artifacts_to_sample
#
Attach artifacts to a sample.
PARAMETER | DESCRIPTION |
---|---|
sample
|
The sample to attach artifacts to.
TYPE:
|
Source code in src/genai_monitor/injectors/wrapper.py
update_generation_id
#
Update the generation_id of the most recently used generation.
PARAMETER | DESCRIPTION |
---|---|
conditioning
|
The conditioning.
TYPE:
|
generation_id
|
The generation id.
TYPE:
|
Source code in src/genai_monitor/injectors/wrapper.py
genai_monitor.injectors.wrapper.FunctionWrapper
#
Bases: Wrapper
Wrapper for functions.
wrap
#
Wraps the function.
PARAMETER | DESCRIPTION |
---|---|
func
|
The function to wrap.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Callable
|
The wrapped function.
TYPE:
|
Source code in src/genai_monitor/injectors/wrapper.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
|
attach_artifacts_to_sample
#
Attach artifacts to a sample.
PARAMETER | DESCRIPTION |
---|---|
sample
|
The sample to attach artifacts to.
TYPE:
|
Source code in src/genai_monitor/injectors/wrapper.py
update_generation_id
#
Update the generation_id of the most recently used generation.
PARAMETER | DESCRIPTION |
---|---|
conditioning
|
The conditioning.
TYPE:
|
generation_id
|
The generation id.
TYPE:
|
Source code in src/genai_monitor/injectors/wrapper.py
genai_monitor.injectors.wrapper.WrapperFactory
#
Factory for creating wrappers for functions and methods.
create
staticmethod
#
create(
func: Callable,
db_manager: DBManager,
persistency_manager: PersistencyManager,
runtime_manager: RuntimeManager,
output_parser: BaseModelOutputParser,
conditioning_parser: BaseConditioningParser,
hashing_function: Callable[[Any], str],
max_unique_instances: int = 1,
) -> Union[FunctionWrapper, MethodWrapper]
Creates a wrapper for a function or method.
PARAMETER | DESCRIPTION |
---|---|
func
|
The function or method to wrap.
TYPE:
|
db_manager
|
The database manager.
TYPE:
|
persistency_manager
|
The persistency manager.
TYPE:
|
runtime_manager
|
The runtime manager.
TYPE:
|
output_parser
|
The output parser.
TYPE:
|
conditioning_parser
|
The conditioning parser.
TYPE:
|
hashing_function
|
The hashing function.
TYPE:
|
max_unique_instances
|
The maximum number of unique sample instances for each conditioning.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[FunctionWrapper, MethodWrapper]
|
The wrapper for the function or method. |
Source code in src/genai_monitor/injectors/wrapper.py
Artifacts#
genai_monitor.injectors.wrapper.ArtifactMethodWrapper
#
Bases: ArtifactWrapper
Wrapper for methods for artifact tracking.
wrap_forward
#
Wraps the function for forward artifact tracking.
PARAMETER | DESCRIPTION |
---|---|
func
|
The function to wrap.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Callable
|
The wrapped function. |
Source code in src/genai_monitor/injectors/wrapper.py
wrap_backward
#
Wraps the function for backward artifact tracking.
PARAMETER | DESCRIPTION |
---|---|
func
|
The function to wrap.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Callable
|
The wrapped function. |
Source code in src/genai_monitor/injectors/wrapper.py
genai_monitor.injectors.wrapper.ArtifactFunctionWrapper
#
Bases: ArtifactWrapper
Wrapper for functions for artifact tracking.
wrap_forward
#
Wraps the function for forward artifact tracking.
PARAMETER | DESCRIPTION |
---|---|
func
|
The function to wrap.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Callable
|
The wrapped function. |
Source code in src/genai_monitor/injectors/wrapper.py
wrap_backward
#
Wraps the function for backward artifact tracking.
PARAMETER | DESCRIPTION |
---|---|
func
|
The function to wrap.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Callable
|
The wrapped function. |
Source code in src/genai_monitor/injectors/wrapper.py
genai_monitor.injectors.wrapper.ArtifactWrapperFactory
#
Factory for creating wrappers for artifacts.
create
#
create(
func: Callable,
db_manager: DBManager,
persistency_manager: PersistencyManager,
runtime_manager: RuntimeManager,
) -> Union[ArtifactFunctionWrapper, ArtifactMethodWrapper]
Creates a wrapper for an artifact.
PARAMETER | DESCRIPTION |
---|---|
func
|
The artifact to wrap.
TYPE:
|
db_manager
|
The database manager.
TYPE:
|
persistency_manager
|
The persistency manager.
TYPE:
|
runtime_manager
|
The runtime manager.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[ArtifactFunctionWrapper, ArtifactMethodWrapper]
|
The wrapper for the artifact. |