-
Notifications
You must be signed in to change notification settings - Fork 0
feat(model-profiles): add input/output MIME type fields to ModelProfile #2
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,11 +55,30 @@ def _validate_data_dir(data_dir: Path) -> Path: | |
| return resolved | ||
|
|
||
|
|
||
| def _profile_field_names() -> frozenset[str]: | ||
| """Return the set of keys declared on `ModelProfile`, or an empty set.""" | ||
| try: | ||
| from langchain_core.language_models.model_profile import ModelProfile | ||
| except ImportError: | ||
| return frozenset() | ||
|
|
||
| try: | ||
| return frozenset(get_type_hints(ModelProfile).keys()) | ||
| except (TypeError, NameError): | ||
| return frozenset() | ||
|
|
||
|
|
||
| def _load_augmentations( | ||
| data_dir: Path, | ||
| ) -> tuple[dict[str, Any], dict[str, dict[str, Any]]]: | ||
| """Load augmentations from `profile_augmentations.toml`. | ||
|
|
||
| Provider-level overrides are top-level keys under `[overrides]`. Model-level | ||
| overrides are keyed by model id under `[overrides."model-id"]`. Because TOML | ||
| subtables produce `dict` values, we distinguish the two by checking the key | ||
| against the declared `ModelProfile` field names. If `ModelProfile` cannot be | ||
| imported, we fall back to the legacy heuristic of "dict value ⇒ model id." | ||
|
|
||
| Args: | ||
| data_dir: Directory containing `profile_augmentations.toml`. | ||
|
|
||
|
|
@@ -90,8 +109,26 @@ def _load_augmentations( | |
| provider_aug: dict[str, Any] = {} | ||
| model_augs: dict[str, dict[str, Any]] = {} | ||
|
|
||
| profile_fields = _profile_field_names() | ||
|
|
||
| for key, value in overrides.items(): | ||
| if isinstance(value, dict): | ||
| if profile_fields: | ||
| # Schema-driven: known profile field names are provider-level; all | ||
| # other keys are treated as model identifiers (whose values must be | ||
| # dict overrides). | ||
| if key in profile_fields: | ||
| provider_aug[key] = value | ||
| elif isinstance(value, dict): | ||
| model_augs[key] = value | ||
| else: | ||
| msg = ( | ||
| f"Augmentation key '{key}' is not a declared ModelProfile " | ||
| f"field and its value is not a table of overrides." | ||
| ) | ||
| print(f"❌ {msg}", file=sys.stderr) | ||
| sys.exit(1) | ||
| # Legacy fallback when ModelProfile is unavailable. | ||
| elif isinstance(value, dict): | ||
|
Comment on lines
+112
to
+131
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If Suggested fix profile_fields = _profile_field_names()
schema_available = profile_fields is not None
for key, value in overrides.items():
if schema_available:
# Schema-driven: known profile field names are provider-level; all
# other keys are treated as model identifiers (whose values must be
# dict overrides).
if key in profile_fields:
provider_aug[key] = value
elif isinstance(value, dict):
model_augs[key] = value
else:
msg = (
f"Augmentation key '{key}' is not a declared ModelProfile "
f"field and its value is not a table of overrides."
)
print(f"❌ {msg}", file=sys.stderr)
sys.exit(1)
elif isinstance(value, dict):
model_augs[key] = value
else:
provider_aug[key] = valuePrompt for AI assistanceCopy the prompt below and paste it into ChatGPT, Claude, or any LLM: |
||
| model_augs[key] = value | ||
| else: | ||
| provider_aug[key] = value | ||
|
Comment on lines
+130
to
134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new schema-driven branch rejects any non-dict key not present on
ModelProfile, which breaks forward compatibility whenprofile_augmentations.tomlcontains a newly added provider-level field; keep unknown scalar keys as provider overrides instead of exiting.Suggested fix
Prompt for AI assistance
Copy the prompt below and paste it into ChatGPT, Claude, or any LLM: