POST
/
datasets
/
{dataset_id}
/
entries
/
query
from opperai import Opper
import time

opper = Opper(http_bearer="YOUR_API_KEY")

# First, create a function and add some geography entries to query
unique_name = f"european_geography_{int(time.time())}"
created_function = opper.functions.create(
    name=unique_name,
    description="Expert in European geography and capital cities",
    instructions="Provide accurate information about European countries and their capitals.",
    model="openai/gpt-4o-mini",
)

print(f"Created function with dataset ID: {created_function.dataset_id}")

# Add some European capital entries to make the query meaningful
entries_to_add = [
    ("What is the capital of France?", "The capital of France is Paris."),
    ("What is the capital of Germany?", "The capital of Germany is Berlin."),
    ("What is the capital of Italy?", "The capital of Italy is Rome."),
    ("What is the capital of Spain?", "The capital of Spain is Madrid."),
    ("What is the capital of Portugal?", "The capital of Portugal is Lisbon."),
]

for input_text, output_text in entries_to_add:
    opper.datasets.create_entry(
        dataset_id=created_function.dataset_id, input=input_text, output=output_text
    )

print("Added European capital entries to dataset")

# Query dataset entries by similarity
entries = opper.datasets.query_entries(
    dataset_id=created_function.dataset_id, query="capital cities of Europe", limit=5
)

print(f"Found {len(entries)} similar entries:")
for entry in entries:
    print(f"Entry {entry.id}: {entry.input}")
    print(f"  Output: {entry.output}")
    print("---")
[
  {
    "id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
    "input": "Given this input, what is the output?",
    "output": "This is the output to the dataset entry",
    "expected": "This `was` the output to the dataset entry",
    "comment": "This is an example of how one can edit the output"
  }
]

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Path Parameters

dataset_id
string
required

The id of the dataset

Query Parameters

query
string
required

The query to search for

limit
integer
default:5

The limit of the entries to get

Required range: 1 <= x <= 20

Response

200
application/json

Successful Response

The response is of type QueryDatasetEntriesResponse · object[].