|
1 | 1 | import base64 |
2 | 2 | import json |
| 3 | +import logging |
3 | 4 | import os |
4 | 5 | import random |
5 | 6 | import requests |
@@ -46,23 +47,31 @@ def encrypt_instance_password(password: str) -> str: |
46 | 47 |
|
47 | 48 | def fetch_instances(): |
48 | 49 | """ |
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. |
52 | 51 | """ |
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 |
66 | 75 |
|
67 | 76 | with open(path, "r", encoding="utf-8") as f: |
68 | 77 | entries = json.load(f) |
@@ -93,10 +102,12 @@ def __init__( |
93 | 102 | Parameters: |
94 | 103 | ----------- |
95 | 104 | 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. |
97 | 107 | 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. |
100 | 111 |
|
101 | 112 | """ |
102 | 113 | # try to get these values from environment variables if not provided |
|
0 commit comments