-
Notifications
You must be signed in to change notification settings - Fork 52.6k
feat(moa): add reference model toggles #59753
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
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 |
|---|---|---|
|
|
@@ -21,6 +21,10 @@ | |
| } | ||
|
|
||
|
|
||
| def _default_reference_models() -> list[dict[str, Any]]: | ||
| return [{**slot, "enabled": True} for slot in deepcopy(DEFAULT_MOA_REFERENCE_MODELS)] | ||
|
|
||
|
|
||
| def _coerce_float_or_none(value: Any) -> float | None: | ||
| """Coerce to a float, or None when unset/blank/invalid. | ||
|
|
||
|
|
@@ -73,7 +77,22 @@ def _coerce_fanout(value: Any) -> str: | |
| return mode if mode in {"per_iteration", "user_turn"} else "per_iteration" | ||
|
|
||
|
|
||
| def _clean_slot(slot: Any) -> dict[str, str] | None: | ||
| def _coerce_bool(value: Any, default: bool = True) -> bool: | ||
| if value is None: | ||
| return default | ||
| if isinstance(value, bool): | ||
| return value | ||
| if isinstance(value, str): | ||
| text = value.strip().lower() | ||
| if text in {"0", "false", "no", "off"}: | ||
| return False | ||
| if text in {"1", "true", "yes", "on"}: | ||
| return True | ||
| return default | ||
| return bool(value) | ||
|
|
||
|
|
||
| def _clean_slot(slot: Any, *, include_enabled: bool = False) -> dict[str, Any] | None: | ||
| if not isinstance(slot, dict): | ||
| return None | ||
| provider = str(slot.get("provider") or "").strip() | ||
|
|
@@ -87,12 +106,15 @@ def _clean_slot(slot: Any) -> dict[str, str] | None: | |
| # an invalid slot is dropped, falling back to the preset's defaults. | ||
| if provider.lower() == "moa": | ||
| return None | ||
|
Collaborator
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. Current main's |
||
| return {"provider": provider, "model": model} | ||
| clean: dict[str, Any] = {"provider": provider, "model": model} | ||
| if include_enabled: | ||
| clean["enabled"] = _coerce_bool(slot.get("enabled"), True) | ||
| return clean | ||
|
|
||
|
|
||
| def _default_preset() -> dict[str, Any]: | ||
| return { | ||
| "reference_models": deepcopy(DEFAULT_MOA_REFERENCE_MODELS), | ||
| "reference_models": _default_reference_models(), | ||
| "aggregator": deepcopy(DEFAULT_MOA_AGGREGATOR), | ||
| # None = temperature omitted from API calls (provider default), | ||
| # matching single-model agent behavior. | ||
|
|
@@ -115,15 +137,15 @@ def _normalize_preset(raw: Any) -> dict[str, Any]: | |
| # defaults instead of crashing the iteration, mirroring the tolerance | ||
| # for the scalar fields below (reference_temperature / max_tokens). | ||
| raw_refs = [raw_refs] if isinstance(raw_refs, dict) else [] | ||
| refs = [_clean_slot(item) for item in raw_refs] | ||
| refs = [_clean_slot(item, include_enabled=True) for item in raw_refs] | ||
| refs = [item for item in refs if item is not None] | ||
| if not refs: | ||
| refs = deepcopy(DEFAULT_MOA_REFERENCE_MODELS) | ||
| refs = _default_reference_models() | ||
|
|
||
| aggregator = _clean_slot(raw.get("aggregator")) or deepcopy(DEFAULT_MOA_AGGREGATOR) | ||
|
|
||
| return { | ||
| "enabled": bool(raw.get("enabled", True)), | ||
| "enabled": _coerce_bool(raw.get("enabled"), True), | ||
| "reference_models": refs, | ||
| "aggregator": aggregator, | ||
| "reference_temperature": _coerce_float_or_none(raw.get("reference_temperature")), | ||
|
|
||
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.
Please add a direct
aggregate_moa_context()test for this filter. The new runtime test covers persistentMoAChatCompletions.create(), but one-shot/moareaches this separate path throughagent/conversation_loop.py:877-893.