API Reference
Platform APIs
- Models
- Functions
- Observability
- Knowledge base
- Datasets
- Other
Observability
Save To Dataset
Save all generation spans to the dataset
POST
/
spans
/
{span_id}
/
save_examples
Copy
Ask AI
from datetime import datetime, timezone
from opperai import Opper
import time
opper = Opper(http_bearer="YOUR_API_KEY")
# First, create a function to get a dataset_id and then create a span with generation data
created_function = opper.functions.create(
name=f"content_generator_{int(time.time())}",
description="Generates high-quality content based on prompts",
instructions="Generate clear, engaging content based on the provided prompt. Use proper structure and include relevant examples.",
model="openai/gpt-4o-mini",
)
print(f"Created function with ID: {created_function.id}")
# Create a span with generation data that can be saved to dataset
created_span = opper.spans.create(
name="content_generation_task",
start_time=datetime.now(timezone.utc),
type="generation",
input="Write a brief introduction to renewable energy",
output="Renewable energy represents one of the most promising solutions to our growing environmental challenges. Unlike fossil fuels, renewable energy sources such as solar, wind, and hydroelectric power generate electricity without producing harmful emissions. These technologies not only help reduce our carbon footprint but also provide sustainable, long-term energy security for communities worldwide.",
meta={
"model": "gpt-4o-mini",
"function_id": created_function.id,
"quality_score": 8.5,
},
)
print(f"Created span with ID: {created_span.id}")
# Save successful generation spans to dataset for training
try:
dataset_entry = opper.spans.save_to_dataset(span_id=created_span.id)
print("ā
Successfully saved span to dataset!")
print(f"Dataset ID: {dataset_entry.dataset_id}")
print(f"Dataset Entry ID: {dataset_entry.dataset_entry_id}")
print(f"Input: {dataset_entry.input[:100]}...")
print(f"Output: {dataset_entry.output[:100]}...")
if dataset_entry.expected:
print(f"Expected: {dataset_entry.expected[:100]}...")
if dataset_entry.comment:
print(f"Comment: {dataset_entry.comment}")
print("\nš This data can now be used for:")
print("- Fine-tuning models")
print("- Evaluation benchmarks")
print("- Few-shot examples")
print("- Quality analysis")
except Exception as e:
print(f"ā Failed to save to dataset: {e}")
print("Possible reasons:")
print("- Span contains no generation data")
print("- Span is not completed")
print("- No associated function found")
Copy
Ask AI
{
"dataset_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"dataset_entry_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"input": "<string>",
"output": "<string>",
"expected": "<string>",
"comment": "<string>"
}
Authorizations
Bearer authentication header of the form Bearer <token>
, where <token>
is your auth token.
Path Parameters
Response
201
application/json
Successful Response
The response is of type object
.
Copy
Ask AI
from datetime import datetime, timezone
from opperai import Opper
import time
opper = Opper(http_bearer="YOUR_API_KEY")
# First, create a function to get a dataset_id and then create a span with generation data
created_function = opper.functions.create(
name=f"content_generator_{int(time.time())}",
description="Generates high-quality content based on prompts",
instructions="Generate clear, engaging content based on the provided prompt. Use proper structure and include relevant examples.",
model="openai/gpt-4o-mini",
)
print(f"Created function with ID: {created_function.id}")
# Create a span with generation data that can be saved to dataset
created_span = opper.spans.create(
name="content_generation_task",
start_time=datetime.now(timezone.utc),
type="generation",
input="Write a brief introduction to renewable energy",
output="Renewable energy represents one of the most promising solutions to our growing environmental challenges. Unlike fossil fuels, renewable energy sources such as solar, wind, and hydroelectric power generate electricity without producing harmful emissions. These technologies not only help reduce our carbon footprint but also provide sustainable, long-term energy security for communities worldwide.",
meta={
"model": "gpt-4o-mini",
"function_id": created_function.id,
"quality_score": 8.5,
},
)
print(f"Created span with ID: {created_span.id}")
# Save successful generation spans to dataset for training
try:
dataset_entry = opper.spans.save_to_dataset(span_id=created_span.id)
print("ā
Successfully saved span to dataset!")
print(f"Dataset ID: {dataset_entry.dataset_id}")
print(f"Dataset Entry ID: {dataset_entry.dataset_entry_id}")
print(f"Input: {dataset_entry.input[:100]}...")
print(f"Output: {dataset_entry.output[:100]}...")
if dataset_entry.expected:
print(f"Expected: {dataset_entry.expected[:100]}...")
if dataset_entry.comment:
print(f"Comment: {dataset_entry.comment}")
print("\nš This data can now be used for:")
print("- Fine-tuning models")
print("- Evaluation benchmarks")
print("- Few-shot examples")
print("- Quality analysis")
except Exception as e:
print(f"ā Failed to save to dataset: {e}")
print("Possible reasons:")
print("- Span contains no generation data")
print("- Span is not completed")
print("- No associated function found")
Copy
Ask AI
{
"dataset_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"dataset_entry_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"input": "<string>",
"output": "<string>",
"expected": "<string>",
"comment": "<string>"
}
Assistant
Responses are generated using AI and may contain mistakes.