Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
745 changes: 316 additions & 429 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "modelbench"
requires-python = ">=3.10, !=3.12.5, <3.13"
requires-python = ">=3.12,!=3.12.5,<4"

[tool.poetry]
name = "modelbench"
Expand Down Expand Up @@ -49,7 +49,7 @@ packages = [
]

[tool.poetry.dependencies]
python = ">=3.10,!=3.12.5,<3.13"
python = ">=3.12,!=3.12.5,<4"
jq = "^1.6.0"
click = "^8.3.0"
casefy = "^1.0.0"
Expand Down
13 changes: 10 additions & 3 deletions src/modelgauge/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
import tomli

from modelgauge import config_templates
from modelgauge.log_config import get_logger
from modelgauge.secret_values import MissingSecretValues, RawSecrets, SecretDescription

DEFAULT_CONFIG_DIR = "config"
DEFAULT_SECRETS = "secrets.toml"
SECRETS_PATH = os.path.join(DEFAULT_CONFIG_DIR, DEFAULT_SECRETS)
CONFIG_TEMPLATES = [DEFAULT_SECRETS]

logger = get_logger(__name__)


def find_config_dir(path: str = ".") -> str:
"""Search up the tree for the config directory."""
Expand Down Expand Up @@ -47,9 +50,13 @@ def write_default_config(parent_dir: str = "."):

def load_secrets_from_config(path: str = ".") -> RawSecrets:
"""Load the toml file and verify it is shaped as expected."""
secrets_path = os.path.join(find_config_dir(path), DEFAULT_SECRETS)
with open(secrets_path, "rb") as f:
data = tomli.load(f)
try:
secrets_path = os.path.join(find_config_dir(path), DEFAULT_SECRETS)
with open(secrets_path, "rb") as f:
data = tomli.load(f)
except FileNotFoundError as exc:
logger.warning("Could not find secrets file", exc_info=exc)
data = {}
for values in data.values():
# Verify the config is shaped as expected.
assert isinstance(values, Mapping), "All keys should be in a [scope]."
Expand Down
11 changes: 6 additions & 5 deletions src/modelgauge/ensemble_annotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@
from modelgauge.config import load_secrets_from_config, raise_if_missing_from_config
from modelgauge.ensemble_strategies import ENSEMBLE_STRATEGIES
from modelgauge.prompt import ChatPrompt, TextPrompt
from modelgauge.secret_values import MissingSecretValues
from modelgauge.secret_values import MissingSecretValues, RawSecrets
from modelgauge.sut import SUTResponse


class EnsembleAnnotator(Annotator):
"""Defines an ensemble; responds like an annotator."""

def __init__(self, uid, annotators: list[str], ensemble_strategy: str):
def __init__(self, uid, annotators: list[str], ensemble_strategy: str, secrets: RawSecrets | None = None):
super().__init__(uid)
self.annotators = self._make_annotators(annotators)
self.annotators = self._make_annotators(annotators, secrets)
if ensemble_strategy not in ENSEMBLE_STRATEGIES:
raise ValueError(f"Ensemble strategy {ensemble_strategy} not recognized.")
self.ensemble_strategy = ENSEMBLE_STRATEGIES[ensemble_strategy]

def _make_annotators(self, annotator_uids: list[str]) -> dict[str, Annotator]:
secrets = load_secrets_from_config()
def _make_annotators(self, annotator_uids: list[str], secrets: RawSecrets | None) -> dict[str, Annotator]:
if secrets is None:
secrets = load_secrets_from_config()
missing_secrets: list[MissingSecretValues] = []
for annotator_uid in annotator_uids:
missing_secrets.extend(ANNOTATORS.get_missing_dependencies(annotator_uid, secrets=secrets))
Expand Down
2 changes: 2 additions & 0 deletions src/modelgauge/private_benchmark_uids.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SAFETY_ANNOTATOR_V1_1_UID = "safety_v1.1"
SECURITY_ANNOTATOR_V0_5_UID = "security_v0.5"
2 changes: 2 additions & 0 deletions src/modelgauge/private_ensemble_annotator_uids.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# TODO: remove this file once modelbench-private is removed

try:
from modelgauge.annotators.official import (
SAFETY_ANNOTATOR_V1_0_UID,
Expand Down
1 change: 1 addition & 0 deletions src/modelgauge/suts/huggingface_chat_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def evaluate(self, request: HuggingFaceChatCompletionRequest) -> HuggingFaceChat
except HTTPError as http_error:
if http_error.response.status_code >= 500 or http_error.response.status_code == 429:
raise TransientHttpError from http_error
raise

# Convert to cacheable pydantic object.
return HuggingFaceChatCompletionOutput(
Expand Down
4 changes: 2 additions & 2 deletions tests/modelgauge_tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def test_load_secrets_from_config_no_file(tmpdir):
config_dir = tmpdir.join("config")
os.makedirs(config_dir)

with pytest.raises(FileNotFoundError):
load_secrets_from_config(tmpdir)
secrets = load_secrets_from_config(tmpdir)
assert secrets == {}


def test_load_secrets_from_config_bad_format(tmpdir):
Expand Down