From d20d135e4a74cdd55be8790d05426cb0df254783 Mon Sep 17 00:00:00 2001 From: lsabor Date: Wed, 17 Dec 2025 15:22:36 -0800 Subject: [PATCH 1/3] add support for setting METACULUS_API_BASE_URL, small fix to scaling value interpretation --- forecasting_tools/data_models/questions.py | 11 +++++++++-- forecasting_tools/helpers/metaculus_client.py | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/forecasting_tools/data_models/questions.py b/forecasting_tools/data_models/questions.py index 757e5d2..b3e464f 100644 --- a/forecasting_tools/data_models/questions.py +++ b/forecasting_tools/data_models/questions.py @@ -403,8 +403,15 @@ def _get_bounds_from_api_json( lower_bound = api_json["question"]["scaling"]["range_min"] zero_point = api_json["question"]["scaling"]["zero_point"] - assert isinstance(upper_bound, float), f"Upper bound is {upper_bound}" - assert isinstance(lower_bound, float), f"Lower bound is {lower_bound}" + try: + upper_bound = float(upper_bound) + lower_bound = float(lower_bound) + except (TypeError, ValueError): + logger.error( + "Error parsing bounds from API JSON. " + "Upper bound: {upper_bound}, Lower bound: {lower_bound}" + ) + raise return ( open_upper_bound, open_lower_bound, diff --git a/forecasting_tools/helpers/metaculus_client.py b/forecasting_tools/helpers/metaculus_client.py index 888f1c4..669cb02 100644 --- a/forecasting_tools/helpers/metaculus_client.py +++ b/forecasting_tools/helpers/metaculus_client.py @@ -38,6 +38,8 @@ logger = logging.getLogger(__name__) +API_BASE_URL = os.getenv("METACULUS_API_BASE_URL", "https://www.metaculus.com/api") + Q = TypeVar("Q", bound=MetaculusQuestion) T = TypeVar("T", bound=BaseModel) @@ -138,7 +140,7 @@ class MetaculusClient: def __init__( self, - base_url: str = "https://www.metaculus.com/api", + base_url: str = API_BASE_URL, timeout: int = 30, sleep_time_between_requests_min: float = 1.5, sleep_jitter_seconds: float = 0.5, From e7a1b858544b39280093c0fc0d7d19e709d6464a Mon Sep 17 00:00:00 2001 From: lsabor Date: Wed, 17 Dec 2025 15:25:43 -0800 Subject: [PATCH 2/3] add env var to template --- .env.template | 1 + 1 file changed, 1 insertion(+) diff --git a/.env.template b/.env.template index 741419f..d0bb0cc 100644 --- a/.env.template +++ b/.env.template @@ -13,6 +13,7 @@ ANTHROPIC_API_KEY= # Fill this in if using the Metaculus API METACULUS_TOKEN= +METACULUS_API_BASE_URL=https://www.metaculus.com/api # As of Jan 23rd 2025, only used for free semantic similarity calculation in Deduplicator, but defaults to OpenAI if not filled in HUGGINGFACE_API_KEY= From 2951a6e55a1bd6599c280714e3fc2873e682b593 Mon Sep 17 00:00:00 2001 From: Luke Sabor <32885230+lsabor@users.noreply.github.com> Date: Thu, 18 Dec 2025 07:10:22 -0800 Subject: [PATCH 3/3] add missing f string prefix Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- forecasting_tools/data_models/questions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/forecasting_tools/data_models/questions.py b/forecasting_tools/data_models/questions.py index b3e464f..ee37fee 100644 --- a/forecasting_tools/data_models/questions.py +++ b/forecasting_tools/data_models/questions.py @@ -408,8 +408,8 @@ def _get_bounds_from_api_json( lower_bound = float(lower_bound) except (TypeError, ValueError): logger.error( - "Error parsing bounds from API JSON. " - "Upper bound: {upper_bound}, Lower bound: {lower_bound}" + f"Error parsing bounds from API JSON. " + f"Upper bound: {upper_bound}, Lower bound: {lower_bound}" ) raise return (