-
Notifications
You must be signed in to change notification settings - Fork 0
SDK-89: Validate test LLM and judge LLM can be accessed from HuggingFace #214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
benglewis
wants to merge
12
commits into
main
Choose a base branch
from
codex/2026-02-11/linear-mention-sdk-89-validate-llm-and-judge-model-can-be
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
356754b
SDK-89: Use huggingface_hub for model access validation
benglewis b1033e3
Merge branch 'main' into codex/2026-02-11/linear-mention-sdk-89-valid…
benglewis 4d84127
Bump `huggingface-hub` version to minimum 1.0.0 (for compatibility is…
benglewis 5bb0211
Fix agent PR comments
benglewis d236474
Fix Pydantic model configuration
benglewis dc4df91
Update `authlib` to `1.6.7` to fix vulnerability
benglewis 1e5c8ca
Add docstring to new validation functions
benglewis 9c6bc59
Change `test_llm_behavior_eval_model_access.py` and `test_model_acces…
benglewis ce40b0a
Fix Ruff error
benglewis b09582d
Fix Codex's PR comment about model error
benglewis 8287c9e
Fix Baz comment about validation when setting model to run LLM behavi…
benglewis 8616eab
Refactor to replace boolean environment variable checks with a functi…
benglewis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| from huggingface_hub import HfApi | ||
| from huggingface_hub.errors import ( | ||
| GatedRepoError, | ||
| HfHubHTTPError, | ||
| RepositoryNotFoundError, | ||
| ) | ||
| from requests import HTTPError | ||
|
|
||
| from hirundo._hirundo_error import HirundoError | ||
| from hirundo.logger import get_logger | ||
|
|
||
| logger = get_logger(__name__) | ||
|
|
||
|
|
||
| def _build_huggingface_access_message( | ||
| model_name: str, | ||
| model_role: str, | ||
| hint: str, | ||
| token_provided: bool, | ||
| ) -> str: | ||
| message_prefix = f"The {model_role} model '{model_name}'" | ||
|
|
||
| if hint == "gated": | ||
| if token_provided: | ||
| return ( | ||
| f"{message_prefix} is gated and the provided HuggingFace token does not " | ||
| "have access. Please request access or use a different token." | ||
| ) | ||
| return f"{message_prefix} is gated. Please provide a HuggingFace token with access." | ||
|
|
||
| if hint == "not_found": | ||
| if token_provided: | ||
| return ( | ||
| f"{message_prefix} was not found or is private/gated for the provided " | ||
| "token. Please verify the model ID or token access." | ||
| ) | ||
| return ( | ||
| f"{message_prefix} was not found or is private/gated. Please provide a " | ||
| "HuggingFace token or verify the model ID." | ||
| ) | ||
|
|
||
| if hint == "unauthorized": | ||
| if token_provided: | ||
| return ( | ||
| f"{message_prefix} could not be accessed with the provided HuggingFace " | ||
| "token. Please verify token permissions or use a different model." | ||
| ) | ||
| return ( | ||
| f"{message_prefix} could not be accessed without a HuggingFace token. " | ||
| "Please provide a token or use a public model." | ||
| ) | ||
|
|
||
| return ( | ||
| f"{message_prefix} could not be accessed. Please verify the model ID or provide " | ||
| "a HuggingFace token with access." | ||
| ) | ||
|
|
||
|
|
||
| def _is_local_model_path(path_or_repo_id: str) -> bool: | ||
| potential_path = Path(path_or_repo_id).expanduser() | ||
| return potential_path.exists() | ||
|
|
||
|
|
||
| def _get_huggingface_error_status_code( | ||
| exception: HfHubHTTPError | HTTPError, | ||
| ) -> int | None: | ||
| response = exception.response | ||
| return response.status_code if response is not None else None | ||
|
|
||
|
|
||
| def validate_huggingface_model_access( | ||
| model_name: str, | ||
| token: str | None, | ||
| model_role: str, | ||
| ) -> None: | ||
| """Validate that a Hugging Face model can be accessed. | ||
|
|
||
| Args: | ||
| model_name: Hugging Face repository ID for the model to validate. | ||
| token: Optional Hugging Face access token used for authenticated access. | ||
| model_role: Human-readable role for the model in error messages. | ||
| """ | ||
| huggingface_api = HfApi(token=token) | ||
| token_provided = token is not None | ||
|
|
||
| try: | ||
| huggingface_api.model_info(repo_id=model_name) | ||
| except GatedRepoError as exception: | ||
| raise HirundoError( | ||
| _build_huggingface_access_message( | ||
| model_name=model_name, | ||
| model_role=model_role, | ||
| hint="gated", | ||
| token_provided=token_provided, | ||
| ) | ||
| ) from exception | ||
| except RepositoryNotFoundError as exception: | ||
| raise HirundoError( | ||
| _build_huggingface_access_message( | ||
| model_name=model_name, | ||
| model_role=model_role, | ||
| hint="not_found", | ||
| token_provided=token_provided, | ||
| ) | ||
| ) from exception | ||
| except (HfHubHTTPError, HTTPError) as exception: | ||
| status_code = _get_huggingface_error_status_code(exception) | ||
|
|
||
| if status_code in {401, 403}: | ||
| hint = "unauthorized" | ||
| else: | ||
| hint = "generic" | ||
| logger.debug( | ||
| "HuggingFace access validation failed for %s model '%s' with status %s.", | ||
| model_role, | ||
| model_name, | ||
| status_code, | ||
| ) | ||
| raise HirundoError( | ||
| _build_huggingface_access_message( | ||
| model_name=model_name, | ||
| model_role=model_role, | ||
| hint=hint, | ||
| token_provided=token_provided, | ||
| ) | ||
| ) from exception | ||
|
benglewis marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def validate_judge_model_access(path_or_repo_id: str, token: str | None) -> None: | ||
| """Validate that a judge model can be accessed. | ||
|
|
||
| Args: | ||
| path_or_repo_id: Local filesystem path or Hugging Face repository ID for the | ||
| judge model. | ||
| token: Optional Hugging Face access token used when the judge model is hosted | ||
| on Hugging Face. | ||
| """ | ||
| if _is_local_model_path(path_or_repo_id): | ||
| return | ||
|
|
||
| validate_huggingface_model_access( | ||
| model_name=path_or_repo_id, | ||
| token=token, | ||
| model_role="judge", | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.