refactor: consolidate stream smoothing into StreamProcessor with intelligent timing

- Move StreamSmoother functionality directly into StreamProcessor for better integration
- Create ContentExtractor strategy pattern for format-agnostic content extraction
- Implement intelligent dynamic delay calculation based on text length
- Support three text length tiers: short (char-by-char), medium (chunked), long (chunked)
- Remove manual chunk_size and delay_ms configuration - now auto-calculated
- Simplify admin UI to single toggle switch with auto timing adjustment
- Extract format detection logic to reusable content_extractors module
- Improve code maintainability with cleaner architecture
This commit is contained in:
fawney19
2025-12-19 09:46:22 +08:00
parent 85fafeacb8
commit 070121717d
7 changed files with 600 additions and 360 deletions

View File

@@ -298,16 +298,11 @@ class ChatHandlerBase(BaseMessageHandler, ABC):
def update_streaming_status() -> None:
self._update_usage_to_streaming_with_ctx(ctx)
# 从数据库批量读取流式平滑输出配置(单次查询)
smoothing_cfg = SystemConfigService.get_configs(
self.db,
["stream_smoothing_enabled", "stream_smoothing_chunk_size", "stream_smoothing_delay_ms"],
)
smoothing_config = StreamSmoothingConfig(
enabled=bool(smoothing_cfg.get("stream_smoothing_enabled", False)),
chunk_size=int(smoothing_cfg.get("stream_smoothing_chunk_size") or 5),
delay_ms=int(smoothing_cfg.get("stream_smoothing_delay_ms") or 15),
# 读取流式平滑输出开关
smoothing_enabled = bool(
SystemConfigService.get_config(self.db, "stream_smoothing_enabled", False)
)
smoothing_config = StreamSmoothingConfig(enabled=smoothing_enabled)
# 创建流处理器
stream_processor = StreamProcessor(