feat:人工学习过的表达会有更高的使用概率

This commit is contained in:
SengokuCola
2025-11-24 00:40:37 +08:00
parent e0b28f9708
commit 63c093af63
7 changed files with 41 additions and 105 deletions

View File

@@ -63,13 +63,15 @@ def format_create_date(timestamp: float) -> str:
def _compute_weights(population: List[Dict]) -> List[float]:
"""
根据表达的count计算权重范围限定在1~3之间。
count越高权重越高但最多为基础权重的3倍。
根据表达的count计算权重范围限定在1~5之间。
count越高权重越高但最多为基础权重的5倍。
如果表达已checked权重会再乘以3倍。
"""
if not population:
return []
counts = []
checked_flags = []
for item in population:
count = item.get("count", 1)
try:
@@ -77,18 +79,29 @@ def _compute_weights(population: List[Dict]) -> List[float]:
except (TypeError, ValueError):
count_value = 1.0
counts.append(max(count_value, 0.0))
# 获取checked状态
checked = item.get("checked", False)
checked_flags.append(bool(checked))
min_count = min(counts)
max_count = max(counts)
if max_count == min_count:
return [1.0 for _ in counts]
base_weights = [1.0 for _ in counts]
else:
base_weights = []
for count_value in counts:
# 线性映射到[1,5]区间
normalized = (count_value - min_count) / (max_count - min_count)
base_weights.append(1.0 + normalized * 4.0) # 1~3
# 如果checked权重乘以3
weights = []
for count_value in counts:
# 线性映射到[1,3]区间
normalized = (count_value - min_count) / (max_count - min_count)
weights.append(1.0 + normalized * 2.0) # 1~3
for base_weight, checked in zip(base_weights, checked_flags):
if checked:
weights.append(base_weight * 3.0)
else:
weights.append(base_weight)
return weights

View File

@@ -37,6 +37,12 @@ class ExpressionReflector:
logger.info(f"[Expression Reflection] Operator ID 未配置,跳过")
return False
# 检查是否在允许列表中
allow_reflect = global_config.expression.allow_reflect
if allow_reflect and self.chat_id not in allow_reflect:
logger.info(f"[Expression Reflection] 当前聊天流 {self.chat_id} 不在允许列表中,跳过")
return False
# 检查上一次提问时间
current_time = time.time()
time_since_last_ask = current_time - self.last_ask_time

View File

@@ -140,6 +140,7 @@ class ExpressionSelector:
"source_id": expr.chat_id,
"create_date": expr.create_date if expr.create_date is not None else expr.last_active_time,
"count": expr.count if getattr(expr, "count", None) is not None else 1,
"checked": expr.checked if getattr(expr, "checked", None) is not None else False,
}
for expr in style_query
]