Skip to content

Commit 8ac00e2

Browse files
committed
Support for custom instance pool
1 parent 1079eff commit 8ac00e2

1 file changed

Lines changed: 30 additions & 19 deletions

File tree

src/browsergym/workarena/instance.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import base64
22
import json
3+
import logging
34
import os
45
import random
56
import requests
@@ -46,23 +47,31 @@ def encrypt_instance_password(password: str) -> str:
4647

4748
def fetch_instances():
4849
"""
49-
Loads the latest instances.json from the gated Hugging Face dataset repo.
50-
Requires that the user is authenticated via huggingface-cli login
51-
or by having HUGGING_FACE_HUB_TOKEN set.
50+
Load the latest instances from either a custom pool (SNOW_INSTANCE_POOL) or the gated HF dataset.
5251
"""
53-
try:
54-
disable_progress_bars()
55-
path = hf_hub_download(
56-
repo_id=INSTANCE_REPO_ID,
57-
filename=INSTANCE_REPO_FILENAME,
58-
repo_type=INSTANCE_REPO_TYPE,
59-
)
60-
except Exception as e:
61-
raise RuntimeError(
62-
f"Could not access {INSTANCE_REPO_ID}/{INSTANCE_REPO_FILENAME}. "
63-
"Make sure you have been granted access to the gated repo and that you are "
64-
"authenticated (run `huggingface-cli login` or set HUGGING_FACE_HUB_TOKEN)."
65-
) from e
52+
pool_path = os.getenv("SNOW_INSTANCE_POOL")
53+
if pool_path:
54+
path = os.path.expanduser(pool_path)
55+
if not os.path.exists(path):
56+
raise FileNotFoundError(
57+
f"SNOW_INSTANCE_POOL points to '{pool_path}', but the file does not exist."
58+
)
59+
logging.info("Loading ServiceNow instances from custom pool: %s", path)
60+
else:
61+
try:
62+
disable_progress_bars()
63+
path = hf_hub_download(
64+
repo_id=INSTANCE_REPO_ID,
65+
filename=INSTANCE_REPO_FILENAME,
66+
repo_type=INSTANCE_REPO_TYPE,
67+
)
68+
logging.info("Loaded ServiceNow instances from the default instance pool.")
69+
except Exception as e:
70+
raise RuntimeError(
71+
f"Could not access {INSTANCE_REPO_ID}/{INSTANCE_REPO_FILENAME}. "
72+
"Make sure you have been granted access to the gated repo and that you are "
73+
"authenticated (run `huggingface-cli login` or set HUGGING_FACE_HUB_TOKEN)."
74+
) from e
6675

6776
with open(path, "r", encoding="utf-8") as f:
6877
entries = json.load(f)
@@ -93,10 +102,12 @@ def __init__(
93102
Parameters:
94103
-----------
95104
snow_url: str
96-
The URL of a SNow instance. If None, will try to get the value from the environment variable SNOW_INSTANCE_URL.
105+
The URL of a SNow instance. When omitted, the constructor first looks for SNOW_INSTANCE_URL and falls back
106+
to a random instance from the benchmark's instance pool if the environment variable is not set.
97107
snow_credentials: (str, str)
98-
The username and password used to access the SNow instance. If None, will try to get the values from the
99-
environment variables SNOW_INSTANCE_UNAME and SNOW_INSTANCE_PWD.
108+
The username and password used to access the SNow instance. When omitted, environment variables
109+
SNOW_INSTANCE_UNAME/SNOW_INSTANCE_PWD are used if set; otherwise, a random instance from the benchmark's
110+
instance pool is selected.
100111
101112
"""
102113
# try to get these values from environment variables if not provided

0 commit comments

Comments
 (0)