Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions examples/oolong_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
"""
Example: An example from the Oolong Benchmark from the RLM paper: https://arxiv.org/abs/2512.24601v1
"""

import os
import sys
from itertools import islice

from dotenv import load_dotenv

from rlm import RLM
from rlm.logger import RLMLogger

load_dotenv()

try:
from datasets import load_dataset
except ImportError:
print(
"Please install the 'datasets' library to run this example. Run `uv pip install datasets`"
)
sys.exit(1)


def load_oolong_row(index: int = 1) -> dict:
"""Load a single row from the Oolong benchmark."""
streaming_ds = load_dataset("oolongbench/oolong-real", "toy_dnd", split="test", streaming=True)
row = next(islice(streaming_ds, index, index + 1))
return row
Comment on lines +25 to +29

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def load_oolong_row(index: int = 1) -> dict:
"""Load a single row from the Oolong benchmark."""
streaming_ds = load_dataset("oolongbench/oolong-real", "toy_dnd", split="test", streaming=True)
row = next(islice(streaming_ds, index, index + 1))
return row
def cp1252_fix(row: dict | str) -> dict | str:
"""Fixes cp1252 encoding issues in dataset rows."""
if isinstance(row, dict):
for key, value in row.items():
if isinstance(value, str):
row[key] = value.encode('cp1252','replace').decode('cp1252')
else:
row = row.encode('cp1252','replace').decode('cp1252')
return row
def load_oolong_row(index: int = 1) -> dict:
"""Load a single row from the Oolong benchmark."""
streaming_ds = load_dataset("oolongbench/oolong-real", "toy_dnd", split="test", streaming=True)
row = next(islice(streaming_ds, index, index + 1))
return cp1252_fix(row)

Thanks for sharing this example! I noticed that cp1252 decoding is broken on windows, so here's a quick fix for that.



def main():
api_key = os.environ.get("OPENAI_API_KEY")
if not api_key:
raise ValueError("OPENAI_API_KEY environment variable is not set.")

# Load benchmark data
row = load_oolong_row(index=1)
context = row["context_window_text"]
question = row["question"]
expected_answer = row["answer"]

print(f"Question: {question}")
print(f"Expected answer: {expected_answer}")
print("-" * 50)

# Create logger
logger = RLMLogger(log_dir="./logs")

# Create RLM instance
rlm = RLM(
backend="openai",
backend_kwargs={
"model_name": "gpt-5-mini",
"api_key": api_key,
},
environment="local",
max_iterations=30,
logger=logger,
verbose=True,
)

# Run completion with context and question
result = rlm.completion(prompt=context, root_prompt=question)

print("-" * 50)
print(f"RLM Response: {result.response}")
print(f"Expected: {expected_answer}")

# Simple validation (exact match or contained)
is_correct = (
expected_answer.lower() in result.response.lower()
or result.response.lower() in expected_answer.lower()
)
print(f"Match: {is_correct}")


if __name__ == "__main__":
main()