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= diff --git a/forecasting_tools/data_models/questions.py b/forecasting_tools/data_models/questions.py index 757e5d2..ee37fee 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( + f"Error parsing bounds from API JSON. " + f"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,