Skip to content

Commit 6d6f850

Browse files
committed
fix edge cases
1 parent 7e2ebf9 commit 6d6f850

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

optillm/plugins/spl/evaluation.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,24 @@
2121
# Setup logging
2222
logger = logging.getLogger(__name__)
2323

24-
def select_relevant_strategies(query: str, problem_type: str, db: Any, max_strategies: int = MAX_STRATEGIES_FOR_INFERENCE) -> List[Strategy]:
24+
def select_relevant_strategies(query: str, problem_type: str, db: Any, learning_mode: bool = False, max_strategies: int = MAX_STRATEGIES_FOR_INFERENCE) -> List[Strategy]:
2525
"""
2626
Select the most relevant strategies for a given problem to be used during inference.
2727
This controls how many strategies are included in the system prompt augmentation.
2828
29-
Only selects strategies of the matching problem type with success rate >= MIN_SUCCESS_RATE_FOR_INFERENCE.
29+
When in inference mode (not learning_mode), only strategies with:
30+
- A matching problem type
31+
- Success rate >= MIN_SUCCESS_RATE_FOR_INFERENCE
32+
- At least 5 attempts
33+
are selected.
34+
35+
In learning mode, strategies with fewer attempts are also considered.
3036
3137
Args:
3238
query: The problem/query text
3339
problem_type: The type of problem
3440
db: Strategy database
41+
learning_mode: Whether we're in learning mode (affects filtering criteria)
3542
max_strategies: Maximum number of strategies to return
3643
3744
Returns:
@@ -41,13 +48,22 @@ def select_relevant_strategies(query: str, problem_type: str, db: Any, max_strat
4148
type_specific = db.get_strategies_for_problem(problem_type)
4249
logger.info(f"Found {len(type_specific)} strategies for problem type '{problem_type}'")
4350

44-
# Filter strategies by minimum success rate
51+
# Filter strategies by minimum success rate and attempts
4552
qualified_strategies = []
4653
for strategy in type_specific:
47-
if strategy.success_rate >= MIN_SUCCESS_RATE_FOR_INFERENCE or strategy.total_attempts < 5:
54+
# In learning mode, we're more lenient with new strategies
55+
if learning_mode and strategy.total_attempts < 5:
56+
logger.info(f"Strategy {strategy.strategy_id} included (learning mode - only {strategy.total_attempts} attempts so far)")
57+
qualified_strategies.append(strategy)
58+
# For inference or well-tested strategies, we require minimum success rate
59+
elif strategy.success_rate >= MIN_SUCCESS_RATE_FOR_INFERENCE and strategy.total_attempts >= 5:
60+
logger.info(f"Strategy {strategy.strategy_id} qualified - success rate {strategy.success_rate:.2f} >= minimum {MIN_SUCCESS_RATE_FOR_INFERENCE:.2f} with {strategy.total_attempts} attempts")
4861
qualified_strategies.append(strategy)
4962
else:
50-
logger.info(f"Strategy {strategy.strategy_id} skipped - success rate {strategy.success_rate:.2f} < minimum {MIN_SUCCESS_RATE_FOR_INFERENCE:.2f}")
63+
if strategy.total_attempts < 5:
64+
logger.info(f"Strategy {strategy.strategy_id} skipped - insufficient attempts ({strategy.total_attempts} < 5) in inference mode")
65+
else:
66+
logger.info(f"Strategy {strategy.strategy_id} skipped - success rate {strategy.success_rate:.2f} < minimum {MIN_SUCCESS_RATE_FOR_INFERENCE:.2f}")
5167

5268
if not qualified_strategies:
5369
logger.info(f"No strategies meet the minimum success rate threshold ({MIN_SUCCESS_RATE_FOR_INFERENCE:.2f}) for problem type '{problem_type}'")

optillm/plugins/spl/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def run_spl(system_prompt: str, initial_query: str, client, model: str, request_
119119
existing_strategies = db.get_strategies_for_problem(problem_type)
120120

121121
# 6. Select relevant strategies for this problem (using inference limit)
122-
selected_strategies = select_relevant_strategies(initial_query, problem_type, db, MAX_STRATEGIES_FOR_INFERENCE)
122+
selected_strategies = select_relevant_strategies(initial_query, problem_type, db, learning_mode, MAX_STRATEGIES_FOR_INFERENCE)
123123

124124
# Log the selected strategies
125125
for i, strategy in enumerate(selected_strategies, 1):

0 commit comments

Comments
 (0)