Core structures#
Conditioning Parser#
genai_monitor.structures.conditioning_parsers.base.BaseConditioningParser
#
Bases: ABC
Base class for conditioning parsers.
Use it to create custom conditioning parsers, not available natively in the library.
'parse_func_arguments' is the core method that needs to be overwritten by the subclasses.
parse_conditioning
#
Parse the execution parameters of a function into a Conditioning object.
Inspects the signature of the function and passed arguments/keyword arguments.
PARAMETER | DESCRIPTION |
---|---|
method
|
The method
TYPE:
|
*args
|
Arguments of the method.
DEFAULT:
|
**kwargs
|
Keyword arguments of the method.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
Conditioning
|
A Conditioning object parsed constructed based on the execution of the method. |
RAISES | DESCRIPTION |
---|---|
NotJsonableError
|
when the parsed arguments cannot be serialized to json. |
Source code in src/genai_monitor/structures/conditioning_parsers/base.py
parse_func_arguments
abstractmethod
#
Core function to be overwritten in subclasses.
Parse func arguments and convert into a jsonable object - the parsing and conversion approach may vary depending on the type of func arguments.
PARAMETER | DESCRIPTION |
---|---|
*args
|
Arguments of the method.
DEFAULT:
|
**kwargs
|
Keyword arguments of the method.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
Jsonable
|
Parsed parameters that can be serialized to json. |
Source code in src/genai_monitor/structures/conditioning_parsers/base.py
Output Parser#
genai_monitor.structures.output_parsers.base.BaseModelOutputParser
#
Bases: ABC
, Generic[T]
Abstract class for converting between sample and model output types.
model_output_to_bytes
abstractmethod
#
Converts the model output to a byte representation.
PARAMETER | DESCRIPTION |
---|---|
model_output
|
The model output to convert.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bytes
|
The byte representation of the model output. |
Source code in src/genai_monitor/structures/output_parsers/base.py
bytes_to_model_output
abstractmethod
#
Converts a byte representation back into model output.
PARAMETER | DESCRIPTION |
---|---|
databytes
|
The byte representation of the model output.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
T
|
The model output reconstructed from the byte representation. |
Source code in src/genai_monitor/structures/output_parsers/base.py
get_model_output_hash
#
Calculates the hash value of the given data.
PARAMETER | DESCRIPTION |
---|---|
data
|
The data to calculate the hash value for.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The hash value of the data. |
Source code in src/genai_monitor/structures/output_parsers/base.py
get_base_type_hash
#
Calculate the hash of the base data type stored in the model output.
PARAMETER | DESCRIPTION |
---|---|
model_output
|
The model outuput to extract the base type from.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The data in model output as one of the base supported types. |
Source code in src/genai_monitor/structures/output_parsers/base.py
model_output_to_base_type
#
Get the base type to calculate the hash upon.
PARAMETER | DESCRIPTION |
---|---|
model_output
|
The output of the model to extract the data from
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
BaseType
|
One of the base data types supported in the system |
Source code in src/genai_monitor/structures/output_parsers/base.py
get_sample_from_model_output
#
Converts the model output to a sample.
PARAMETER | DESCRIPTION |
---|---|
model_output
|
The model output to convert to a sample.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Sample
|
The sample created from the model output. |
Source code in src/genai_monitor/structures/output_parsers/base.py
get_model_output_from_sample
#
Converts the sample to model output.
PARAMETER | DESCRIPTION |
---|---|
sample
|
The sample to convert to model output.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
T
|
The model output created from the sample. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
if the data of a sample is empty |
Source code in src/genai_monitor/structures/output_parsers/base.py
Persistency Manager#
genai_monitor.structures.persistency_manager.PersistencyManager
#
Manager for saving and loading model outputs in binary format to disk.
Source code in src/genai_monitor/structures/persistency_manager.py
configure
#
Configures the persistency manager.
PARAMETER | DESCRIPTION |
---|---|
config
|
The configuration object specifying the parameters of PersistencyManager.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the configuration file cannot be loaded. |
Source code in src/genai_monitor/structures/persistency_manager.py
save_sample
#
Saves the sample data to a binary file.
PARAMETER | DESCRIPTION |
---|---|
sample
|
The sample to save.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the sample data is None. |
ValueError
|
If the sample ID is None. |
ValueError
|
If the PersistencyManager is disabled. |
Source code in src/genai_monitor/structures/persistency_manager.py
load_sample
#
Loads the binary file for the given sample.
PARAMETER | DESCRIPTION |
---|---|
sample
|
The sample to load.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bytes
|
The binary data from the file. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the PersistencyManager is disabled. |
ValueError
|
If the sample ID is None. |
FileNotFoundError
|
If the binary file for the sample ID is not found. |
ValueError
|
If the PersistencyManager has not been configured. |
Source code in src/genai_monitor/structures/persistency_manager.py
save_bytes_to_disk
#
Saves the bytes to a binary file.
PARAMETER | DESCRIPTION |
---|---|
data
|
The bytes to save.
TYPE:
|
filename
|
The name of the file to save the bytes to.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the PersistencyManager is disabled. |
Source code in src/genai_monitor/structures/persistency_manager.py
load_bytes_from_disk
#
Loads the bytes from a binary file.
PARAMETER | DESCRIPTION |
---|---|
filename
|
The name of the file to load the bytes from.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bytes
|
The bytes from the file. |
RAISES | DESCRIPTION |
---|---|
FileNotFoundError
|
If the file is not found. |
Source code in src/genai_monitor/structures/persistency_manager.py
is_configured
#
Checks if the PersistencyManager has been configured.
RETURNS | DESCRIPTION |
---|---|
bool
|
Boolean indicating if the PersistencyManager has been configured. |
save_artifact
#
Saves the artifact data to a binary file.
PARAMETER | DESCRIPTION |
---|---|
artifact
|
The artifact to save.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the artifact ID is None. |
ValueError
|
If the PersistencyManager is disabled. |
Source code in src/genai_monitor/structures/persistency_manager.py
load_artifact
#
Loads the binary file for the given artifact.
PARAMETER | DESCRIPTION |
---|---|
artifact
|
The artifact to load.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bytes
|
The binary data from the file. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the PersistencyManager is disabled. |
ValueError
|
If the artifact ID is None. |
FileNotFoundError
|
If the binary file for the artifact ID is not found. |
ValueError
|
If the PersistencyManager has not been configured. |
Source code in src/genai_monitor/structures/persistency_manager.py
save_conditioning
#
Saves the conditioning data to a binary file.
PARAMETER | DESCRIPTION |
---|---|
conditioning
|
The conditioning to save.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the conditioning ID is None. |
ValueError
|
If the PersistencyManager is disabled. |
Source code in src/genai_monitor/structures/persistency_manager.py
load_conditioning
#
Loads the binary file for the given conditioning.
PARAMETER | DESCRIPTION |
---|---|
conditioning
|
The conditioning to load.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dict
|
The binary data from the file. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the PersistencyManager is disabled. |
ValueError
|
If the conditioning ID is None. |
FileNotFoundError
|
If the binary file for the conditioning ID is not found. |
ValueError
|
If the PersistencyManager has not been configured. |
Source code in src/genai_monitor/structures/persistency_manager.py
Runtime Manager#
genai_monitor.structures.runtime_manager.RuntimeManager
#
Class for managing runtime data.
ATTRIBUTE | DESCRIPTION |
---|---|
user_id |
The user ID.
TYPE:
|
version |
The runtime version identifier.
TYPE:
|
latest_sample |
The most recently created sample.
TYPE:
|
artifacts_for_next_sample |
Collection of artifacts to be associated with the next sample.
TYPE:
|