Function
_bandit_bonus
(
*,
enabled: bool,
bandit_config: BanditConfig,
candidate_cost: float,
cheapest_cost: float,
reliability: float,
samples: int,
bucket_pulls: int,
)
Source from the content-addressed store, hash-verified
| 710 | |
| 711 | |
| 712 | def _bandit_bonus( |
| 713 | *, |
| 714 | enabled: bool, |
| 715 | bandit_config: BanditConfig, |
| 716 | candidate_cost: float, |
| 717 | cheapest_cost: float, |
| 718 | reliability: float, |
| 719 | samples: int, |
| 720 | bucket_pulls: int, |
| 721 | ) -> float: |
| 722 | if not enabled: |
| 723 | return 0.0 |
| 724 | if cheapest_cost > 0 and candidate_cost > (cheapest_cost * bandit_config.max_cost_ratio): |
| 725 | return 0.0 |
| 726 | if samples >= bandit_config.min_samples_for_guardrail and reliability < bandit_config.min_reliability: |
| 727 | return 0.0 |
| 728 | if samples < bandit_config.warmup_pulls: |
| 729 | return bandit_config.exploration_weight |
| 730 | return bandit_config.exploration_weight * math.sqrt( |
| 731 | math.log(max(2, bucket_pulls + 1)) / (samples + 1), |
| 732 | ) |
| 733 | |
| 734 | |
| 735 | # --------------------------------------------------------------------------- |
Tested by
no test coverage detected