fix(chat): 修复能量调整计算中的负数幂错误
当能量值非常接近高能量阈值(0.7)时,由于浮点数精度问题,`energy - 0.7` 的结果可能为一个极小的负数,这会导致 `ValueError` (negative number cannot be raised to a fractional power)。 通过使用 `max(0, ...)` 来确保幂运算的基数始终为非负数,从而解决了这个潜在的运行时错误,增强了系统的健壮性。
This commit is contained in:
@@ -365,7 +365,7 @@ class EnergyManager:
|
|||||||
# 计算与阈值的相对位置
|
# 计算与阈值的相对位置
|
||||||
if energy >= high_threshold:
|
if energy >= high_threshold:
|
||||||
# 高能量区域:指数增强
|
# 高能量区域:指数增强
|
||||||
adjusted = 0.7 + (energy - 0.7) ** 0.8
|
adjusted = 0.7 + max(0, energy - 0.7) ** 0.8
|
||||||
elif energy >= reply_threshold:
|
elif energy >= reply_threshold:
|
||||||
# 中等能量区域:线性保持
|
# 中等能量区域:线性保持
|
||||||
adjusted = energy
|
adjusted = energy
|
||||||
|
|||||||
Reference in New Issue
Block a user