|
1 | 1 | import os |
| 2 | +import random |
| 3 | +import string |
2 | 4 |
|
3 | 5 | from dotenv import load_dotenv |
4 | 6 |
|
|
7 | 9 |
|
8 | 10 | load_dotenv() |
9 | 11 |
|
10 | | -logger = RLMLogger(log_dir="./logs") |
| 12 | +# Generate a large text file with a hidden secret number |
| 13 | +secret_number = random.randint(100_000_000, 999_999_999) |
| 14 | +filler_lines = ["".join(random.choices(string.ascii_lowercase + " ", k=120)) for _ in range(50_000)] |
| 15 | +insert_at = random.randint(len(filler_lines) // 3, 2 * len(filler_lines) // 3) |
| 16 | +filler_lines.insert(insert_at, f"SECRET_NUMBER={secret_number}") |
| 17 | +haystack = "\n".join(filler_lines) |
11 | 18 |
|
12 | 19 | rlm = RLM( |
13 | | - backend="portkey", # or "openai", etc. |
| 20 | + backend="openai", |
14 | 21 | backend_kwargs={ |
15 | | - "model_name": "@openai/gpt-5-nano", |
16 | | - "api_key": os.getenv("PORTKEY_API_KEY"), |
| 22 | + "model_name": "gpt-5-nano", |
| 23 | + "api_key": os.getenv("OPENAI_API_KEY"), |
17 | 24 | }, |
18 | 25 | environment="local", |
19 | | - environment_kwargs={}, |
20 | | - max_depth=1, |
21 | | - logger=logger, |
22 | | - verbose=True, # For printing to console with rich, disabled by default. |
| 26 | + max_iterations=10, |
| 27 | + logger=RLMLogger(log_dir="./logs"), |
| 28 | + verbose=True, |
23 | 29 | ) |
24 | 30 |
|
25 | | -result = rlm.completion("Print me the first 5 powers of two, each on a newline.") |
| 31 | +result = rlm.completion( |
| 32 | + "The context contains ~50k lines of random text with a single line " |
| 33 | + "matching the pattern SECRET_NUMBER=<digits>. Find and return ONLY the " |
| 34 | + f"numeric value.\n\n{haystack}" |
| 35 | +) |
26 | 36 |
|
27 | | -print(result) |
| 37 | +print(f"\nModel found: {result.response}") |
| 38 | +print(f"Actual number: {secret_number}") |
| 39 | +print(f"Correct: {str(secret_number) in result.response}") |
0 commit comments