from datetime import datetime, timezone
from opperai import Opper
import time
opper = Opper(http_bearer="YOUR_API_KEY")
# First, create a span and a metric to update
created_span = opper.spans.create(
name="content_quality_review",
start_time=datetime.now(timezone.utc),
type="review",
input="Please review this blog post draft for quality and accuracy.",
output="The blog post draft shows good structure and content, but could benefit from more specific examples and improved conclusion.",
meta={"content_type": "blog_post", "reviewer_id": "reviewer_456"},
)
print(f"Created span with ID: {created_span.id}")
# Create a metric to update
created_metric = opper.span_metrics.create_metric(
span_id=created_span.id,
dimension="content_quality",
value=7.5,
comment="Initial quality assessment - good but needs improvement",
)
print(f"Created metric with ID: {created_metric.id}")
print(f"Initial value: {created_metric.value}")
# Update the metric value and comment after review
updated_metric = opper.span_metrics.update_metric_spans_span_id_metrics_metric_id_patch(
span_id=created_span.id,
metric_id=created_metric.id,
value=9.2,
comment="Updated quality score after review - improved reasoning and accuracy",
)
print(f"Updated metric: {updated_metric.dimension}")
print(f"New value: {updated_metric.value}")
print(f"Updated comment: {updated_metric.comment}")
print(f"Last updated: {updated_metric.created_at}")
# Update only the dimension name
dimension_updated = (
opper.span_metrics.update_metric_spans_span_id_metrics_metric_id_patch(
span_id=created_span.id,
metric_id=created_metric.id,
dimension="content_quality_final",
)
)
print(f"\nUpdated dimension to: {dimension_updated.dimension}")