Appearance
Testing
testing.logs
is a part of the testing metrics system, designed to manage and interact with test metrics for AI projects. This provides methods for logging metrics, creating new metrics, and retrieving metric information.
Initialization
First, initialize the Modulos client
python
from modulos import Modulos
modulos = Modulos()
Methods
log_metric
Logs a metric value for a specific project.
Example:
python
modulos = Modulos()
result = modulos.testing.logs.log_metric("metric123", 42, "project456")
print(f"Logged metric: {result.id}")
Parameters:
metric_id
(str): The ID of the metric to log.value
(str | int | float): The value of the metric.project_id
(str): The ID of the project.
Returns:
TestingLog | None
: The logged metric object if successful, None otherwise. create_metric Creates a new metric for a project.
create_metric
Creates a new metric for a project.
Example:
python
modulos = Modulos()
new_metric = modulos.testing.logs.create_metric(
"Response Time",
"project456",
"float",
"Average response time in milliseconds"
print(f"Created metric: {new_metric.id}")
)
Parameters:
name
(str): The name of the new metric.project_id
(str): The ID of the project.type
(Literal["string", "integer", "float"]): The data type of the metric.description
(str): A description of the metric.
Returns:
TestingMetric | None
: The created metric object if successful, None otherwise.
get_metrics
Retrieves all metrics for a given project.
Example:
python
modulos = Modulos()
metrics = modulos.testing.logs.get_metrics("project456")
for metric in metrics:
print(f"Metric: {metric.name} (ID: {metric.id})")
Parameters:
project_id
(str): The ID of the project.
Returns:
list[TestingMetric] | None
: A list of TestingMetric objects if successful, None otherwise.
get_metric
Retrieves a specific metric by its ID for a project.
Example:
python
modulos = Modulos()
metric = modulos.testing.logs.get_metric("metric123", "project456")
if metric:
print(f"Retrieved metric: {metric.name} (Type: {metric.type})")
Parameters:
metric_id
(str): The ID of the metric to retrieve.project_id
(str): The ID of the project.
Returns:
TestingMetric | None
: The TestingMetric object if found, None otherwise.
Samples
Here's a comprehensive sample demonstrating the usage of the Logs
class:
python
modulos = Modulos()
# Create a new metric
new_metric = modulos.testing.logs.create_metric(
"Error Rate",
"project123",
"float",
"Percentage of requests resulting in errors"
)
print(f"Created new metric: {new_metric.name} (ID: {new_metric.id})")
# Log a value for the new metric
log_result = modulos.testing.logs.log_metric(new_metric.id, 0.05, "project123")
if log_result:
print(f"Logged value: {log_result.value}")
This sample demonstrates creating a new metric, logging a value for it, retrieving all metrics for a project, and then fetching the specific metric we created.