from opperai import Opper
import time
opper = Opper(http_bearer="YOUR_API_KEY")
# First, create a function and add some entries to get a dataset with data
unique_name = f"science_qa_{int(time.time())}"
created_function = opper.functions.create(
name=unique_name,
description="Science question answering assistant",
instructions="Answer science questions clearly and accurately with helpful explanations.",
model="openai/gpt-4o-mini",
)
print(f"Created function with dataset ID: {created_function.dataset_id}")
# Add a few entries to the dataset
opper.datasets.create_entry(
dataset_id=created_function.dataset_id,
input="What is photosynthesis?",
output="Photosynthesis is the process by which plants convert sunlight, carbon dioxide, and water into glucose and oxygen.",
expected="Photosynthesis is the biological process that converts light energy into chemical energy in plants.",
)
opper.datasets.create_entry(
dataset_id=created_function.dataset_id,
input="What is gravity?",
output="Gravity is the force that attracts objects toward each other, with larger objects having stronger gravitational pull.",
expected="Gravity is a fundamental force of attraction between masses.",
)
# List dataset entries with pagination
entries = opper.datasets.list_entries(
dataset_id=created_function.dataset_id, offset=0, limit=10
)
print(f"Total entries: {entries.meta.total_count}")
for entry in entries.data:
print(f"Entry {entry.id}: {entry.input[:50]}...")
print(f" Output: {entry.output[:50]}...")