Skip to content

Query

Core query API implementation#

genai_monitor.query.api.get_conditionings #

get_conditionings() -> List[Conditioning]
Source code in src/genai_monitor/query/api.py
def get_conditionings() -> List[Conditioning]:
    results = DBManager.search(ConditioningTable)
    return [Conditioning.from_orm(result) for result in results]

genai_monitor.query.api.get_models #

get_models() -> List[Model]
Source code in src/genai_monitor/query/api.py
def get_models() -> List[Model]:
    results = DBManager.search(ModelTable)
    return [Model.from_orm(result) for result in results]

genai_monitor.query.api.get_samples #

get_samples() -> List[Sample]
Source code in src/genai_monitor/query/api.py
def get_samples() -> List[Sample]:
    results = DBManager.search(SampleTable)
    return [Sample.from_orm(result) for result in results]

genai_monitor.query.api.get_sample_by_hash #

get_sample_by_hash(hash_value: str) -> Optional[Sample]
Source code in src/genai_monitor/query/api.py
def get_sample_by_hash(hash_value: str) -> Optional[Sample]:
    results = DBManager.search(SampleTable, filters={"hash": hash_value})
    return Sample.from_orm(results[0]) if results else None

genai_monitor.query.api.get_sample_by_id #

get_sample_by_id(sample_id: int) -> Optional[Sample]
Source code in src/genai_monitor/query/api.py
def get_sample_by_id(sample_id: int) -> Optional[Sample]:
    results = DBManager.search(SampleTable, filters={"id": sample_id})
    return Sample.from_orm(results[0]) if results else None

genai_monitor.query.api.get_conditioning_by_id #

get_conditioning_by_id(
    conditioning_id: int,
) -> Optional[Conditioning]
Source code in src/genai_monitor/query/api.py
def get_conditioning_by_id(conditioning_id: int) -> Optional[Conditioning]:
    results = DBManager.search(ConditioningTable, filters={"id": conditioning_id})
    return Conditioning.from_orm(results[0]) if results else None

genai_monitor.query.api.get_model_by_id #

get_model_by_id(model_id: int) -> Optional[Model]
Source code in src/genai_monitor/query/api.py
def get_model_by_id(model_id: int) -> Optional[Model]:
    results = DBManager.search(ModelTable, filters={"id": model_id})
    return Model.from_orm(results[0]) if results else None

genai_monitor.query.api.SampleQuery #

SampleQuery(sample: Sample)

Query interface for samples.

Source code in src/genai_monitor/query/api.py
def __init__(self, sample: Sample):
    self._sample = sample

get_conditioning #

get_conditioning() -> Optional[Conditioning]

Get the conditioning used to generate this sample.

RETURNS DESCRIPTION
Optional[Conditioning]

Optional[Conditioning]: The conditioning if it exists, None otherwise.

Source code in src/genai_monitor/query/api.py
def get_conditioning(self) -> Optional[Conditioning]:
    """Get the conditioning used to generate this sample.

    Returns:
        Optional[Conditioning]: The conditioning if it exists, None otherwise.
    """
    if not self._sample.conditioning_id:
        return None

    results = DBManager.search(ConditioningTable, filters={"id": self._sample.conditioning_id})
    return Conditioning.from_orm(results[0]) if results else None

get_model #

get_model() -> Optional[Model]

Get the generator that created this sample.

RETURNS DESCRIPTION
Optional[Model]

Optional[Model]: The generator if it exists, None otherwise.

Source code in src/genai_monitor/query/api.py
def get_model(self) -> Optional[Model]:
    """Get the generator that created this sample.

    Returns:
        Optional[Model]: The generator if it exists, None otherwise.
    """
    if not self._sample.model_id:
        return None

    results = DBManager.search(ModelTable, filters={"id": self._sample.model_id})
    return Model.from_orm(results[0]) if results else None

genai_monitor.query.api.ModelQuery #

ModelQuery(model: Model)

Query interface for generators.

Source code in src/genai_monitor/query/api.py
def __init__(self, model: Model):
    self._model = model

get_samples #

get_samples(
    conditioning: Optional[Conditioning] = None,
) -> List[Sample]

Get all samples generated by this generator.

PARAMETER DESCRIPTION
conditioning

Optional conditioning to filter samples

TYPE: Optional[Conditioning] DEFAULT: None

RETURNS DESCRIPTION
List[Sample]

List of samples

Source code in src/genai_monitor/query/api.py
def get_samples(self, conditioning: Optional[Conditioning] = None) -> List[Sample]:
    """Get all samples generated by this generator.

    Args:
        conditioning: Optional conditioning to filter samples

    Returns:
        List of samples
    """
    filters = {"model_id": self._model.id}
    if conditioning:
        filters["conditioning_id"] = conditioning.id

    results = DBManager.search(SampleTable, filters=filters)
    return [Sample.from_orm(result) for result in results]

genai_monitor.query.api.ConditioningQuery #

ConditioningQuery(conditioning: Conditioning)

Query interface for conditionings.

Source code in src/genai_monitor/query/api.py
def __init__(self, conditioning: Conditioning):
    self._conditioning = conditioning

get_samples #

get_samples() -> List[Sample]

Get all samples generated with this conditioning.

RETURNS DESCRIPTION
List[Sample]

List[Sample]: List of samples generated with this conditioning.

Source code in src/genai_monitor/query/api.py
def get_samples(self) -> List[Sample]:
    """Get all samples generated with this conditioning.

    Returns:
        List[Sample]: List of samples generated with this conditioning.
    """
    results = DBManager.search(SampleTable, filters={"conditioning_id": self._conditioning.id})
    return [Sample.from_orm(result) for result in results]