Skip to content

Commit 14835b5

Browse files
LesereingrapeSoultersourcery-ai[bot]
authored
fix(respond): keep an unusable segmented-reply log base from dropping the reply (#10231)
* fix(respond): keep an unusable segmented-reply log base from dropping the reply * Update astrbot/core/pipeline/respond/stage.py Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> * Delete tests/test_respond_stage_log_base.py --------- Co-authored-by: Soulter <[email protected]> Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
1 parent d3ac318 commit 14835b5

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

‎astrbot/core/pipeline/respond/stage.py‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,27 @@
1414
from ..context import PipelineContext, call_event_hook
1515
from ..stage import Stage, register_stage
1616

17+
DEFAULT_LOG_BASE = 2.6
18+
19+
20+
def _resolve_log_base(value: float | str | None) -> float:
21+
"""Return a log base that math.log accepts, or the documented default."""
22+
try:
23+
log_base = float(value)
24+
except (TypeError, ValueError) as e:
25+
logger.error(f"Failed to parse the segmented-reply log base: {e}")
26+
return DEFAULT_LOG_BASE
27+
if not math.isfinite(log_base) or log_base <= 1:
28+
# math.log(words, 1) raises ZeroDivisionError and a non-positive base
29+
# raises ValueError; both escape from _calc_comp_interval before the
30+
# first send, so the whole reply is dropped.
31+
logger.error(
32+
f"Unusable segmented-reply log base: {log_base}, "
33+
f"using the default {DEFAULT_LOG_BASE} instead.",
34+
)
35+
return DEFAULT_LOG_BASE
36+
return log_base
37+
1738

1839
@register_stage
1940
class RespondStage(Stage):
@@ -72,7 +93,7 @@ async def initialize(self, ctx: PipelineContext) -> None:
7293
self.interval_method = ctx.astrbot_config["platform_settings"][
7394
"segmented_reply"
7495
]["interval_method"]
75-
self.log_base = float(
96+
self.log_base = _resolve_log_base(
7697
ctx.astrbot_config["platform_settings"]["segmented_reply"]["log_base"],
7798
)
7899
self.interval = [1.5, 3.5]

0 commit comments

Comments
 (0)