-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_custom_cache.py
More file actions
65 lines (55 loc) · 2.12 KB
/
Copy pathtest_custom_cache.py
File metadata and controls
65 lines (55 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
"""
Test that CustomForecaster.run_research correctly caches results across instances.
"""
import asyncio
import os
from custom_forecaster import CustomForecaster
from forecasting_tools import MetaculusQuestion
class DummyQuestion(MetaculusQuestion):
def __init__(self, page_url: str, question_text: str) -> None:
self.page_url = page_url
self.question_text = question_text
self.background_info = ""
self.resolution_criteria = ""
self.fine_print = ""
self.unit_of_measure = None
self.open_upper_bound = True
self.open_lower_bound = True
self.upper_bound = None
self.lower_bound = None
async def test_cache() -> None:
# Ensure no real API calls fall back to empty string research
# First fetch should miss cache
question = DummyQuestion("http://example.com/q1", "Will X happen?")
bot1 = CustomForecaster(
research_reports_per_question=1,
predictions_per_research_report=1,
use_research_summary_to_forecast=False,
publish_reports_to_metaculus=False,
folder_to_save_reports_to=None,
skip_previously_forecasted_questions=True,
forecaster_description="",
forecaster_name="",
llms={"default": "openrouter/openai/o4-mini"},
)
print("Fetching research first time (expected miss)...")
result1 = await bot1.run_research(question)
# Second fetch on a new instance should hit cache
bot2 = CustomForecaster(
research_reports_per_question=1,
predictions_per_research_report=1,
use_research_summary_to_forecast=False,
publish_reports_to_metaculus=False,
folder_to_save_reports_to=None,
skip_previously_forecasted_questions=True,
forecaster_description="",
forecaster_name="",
llms={"default": "openrouter/openai/o4-mini"},
)
print("Fetching research second time (expected hit)...")
result2 = await bot2.run_research(question)
print(f"Result1 == Result2: {result1 == result2}")
print(f"Research output: {result1!r}")
if __name__ == "__main__":
asyncio.run(test_cache())