eval::threshold_adapter::ThresholdAdapter
More...
Public Functions
|
Name |
|
init(self self, teacher_client teacher_client, Optional project_root[Path] =None, Optional] config[Dict[str, Any] =None) |
| ThresholdRecommendation |
evaluate_thresholds(self self, str niche, Dict current_metrics[str, Any], Dict current_thresholds[str, Any], Optional]] prior_runs[List[Dict[str, Any] =None, Optional model_name[str] =None) |
| bool |
enabled(self self) |
| float |
confidence_minimum(self self) |
| float |
max_adjustment_percent(self self) |
Protected Functions
|
Name |
| Dict[str, Any] |
_load_config(self self, Path project_root) |
| str |
_build_prompt(self self, str niche, Dict current_metrics[str, Any], Dict current_thresholds[str, Any], List] prior_runs[Dict[str, Any]) |
| str |
_call_llm(self self, str prompt, Optional model_name[str] =None) |
| Dict[str, Any] |
_parse_response(self self, str content) |
| bool |
_should_auto_apply(self self, ThresholdRecommendation recommendation, Dict current_thresholds[str, Any]) |
| bool |
_all_changes_within_cap(self self, Dict recs[str, Any], Dict current_thresholds[str, Any]) |
| Dict[str, Any] |
_compute_updated_thresholds(self self, ThresholdRecommendation recommendation, Dict current_thresholds[str, Any]) |
Protected Attributes
Detailed Description
class eval::threshold_adapter::ThresholdAdapter;
LLM-based adaptive threshold evaluator via TeacherClient.
Sends structured evaluation metrics to an LLM, parses the JSON
recommendation, and conditionally auto-applies threshold changes
when confidence and magnitude criteria are met.
Args:
teacher_client: Phase 1 ``TeacherClient`` instance for LLM calls.
project_root: Root of the gnus-poc project (for config loading).
config: Optional dict of ``adaptive_thresholding`` settings.
Loaded from ``config/pipeline.yaml`` if not provided.
Public Functions Documentation
function init
__init__(
self self,
teacher_client teacher_client,
Optional project_root[Path] =None,
Optional] config[Dict[str, Any] =None
)
function evaluate_thresholds
ThresholdRecommendation evaluate_thresholds(
self self,
str niche,
Dict current_metrics[str, Any],
Dict current_thresholds[str, Any],
Optional]] prior_runs[List[Dict[str, Any] =None,
Optional model_name[str] =None
)
Prompt the LLM for threshold recommendations and conditionally apply.
Args:
niche: Specialist niche name.
current_metrics: Dict with keys ``ppl``, ``bleu``, ``rouge_l``,
``latency`` matching the current evaluation run.
current_thresholds: Dict with keys ``ppl_max``, ``bleu_min``,
``consecutive_failures``.
prior_runs: Optional list of prior-run metric dicts.
model_name: Optional teacher model override.
Returns:
``ThresholdRecommendation`` with the LLM's analysis and any
auto-applied threshold updates.
function enabled
bool enabled(
self self
)
function confidence_minimum
float confidence_minimum(
self self
)
function max_adjustment_percent
float max_adjustment_percent(
self self
)
Protected Functions Documentation
function _load_config
Dict[str, Any] _load_config(
self self,
Path project_root
)
Load ``adaptive_thresholding`` section from pipeline.yaml.```
### function _build_prompt
```python
str _build_prompt(
self self,
str niche,
Dict current_metrics[str, Any],
Dict current_thresholds[str, Any],
List] prior_runs[Dict[str, Any]
)
Format the THRESHOLD_EVALUATION_PROMPT with runtime data.
Prior run metrics are embedded as a JSON code block to prevent
prompt injection (T-02-09 mitigation).
function _call_llm
str _call_llm(
self self,
str prompt,
Optional model_name[str] =None
)
Send the prompt to TeacherClient and return the content string.```
### function _parse_response
```python
Dict[str, Any] _parse_response(
self self,
str content
)
Extract JSON from an LLM response string.
Attempts to find a JSON code block first, then falls back to
parsing the entire content as JSON. Returns an empty dict on
parse failure to avoid crashing the pipeline.
function _should_auto_apply
bool _should_auto_apply(
self self,
ThresholdRecommendation recommendation,
Dict current_thresholds[str, Any]
)
Check whether the recommendation meets auto-apply criteria.
Two conditions must BOTH be true (T-02-10):
1. ``confidence`` > ``confidence_minimum`` (default 0.9)
2. Every recommended threshold change is < ``max_adjustment_percent``
(default 20%) of the current value.
function _all_changes_within_cap
bool _all_changes_within_cap(
self self,
Dict recs[str, Any],
Dict current_thresholds[str, Any]
)
Return True if ALL recommended changes are within the adjustment cap.```
### function _compute_updated_thresholds
```python
Dict[str, Any] _compute_updated_thresholds(
self self,
ThresholdRecommendation recommendation,
Dict current_thresholds[str, Any]
)
Build the updated thresholds dict from the recommendation.```
## Protected Attributes Documentation
### variable _teacher
```python
_teacher;
variable _project_root
variable _config
variable _confidence_minimum
variable _max_adjustment_percent
variable _enabled
Updated on 2026-10-09 at 03:59:43 +0000