feat(config): 新增流式输出优化器开关配置

在环境变量示例文件(.env.example)和配置类(config.py)中新增 STREAM_OPTIMIZER_ENABLED 配置项,用于控制流式输出优化器的启用状态,默认设为 false

调整 Gemini 和 OpenAI 聊天服务的流式响应处理逻辑:
- 仅在流式优化器启用时(settings.STREAM_OPTIMIZER_ENABLED 为 true)
- 才会对文本内容执行流式输出优化处理
- 保持原有文本提取逻辑不变,仅增加配置条件判断

该变更使流式输出优化器变为可选功能,方便根据实际需求进行开关控制
This commit is contained in:
snaily
2025-04-03 04:47:06 +08:00
parent baf643e884
commit cc36ba4c9e
4 changed files with 5 additions and 4 deletions
+2 -3
View File
@@ -167,9 +167,8 @@ class GeminiChatService:
json.loads(line), model, stream=True
)
text = self._extract_text_from_response(response_data)
# 如果有文本内容,使用流式输出优化器处理
if text:
# 如果有文本内容,且开启了流式输出优化器,则使用流式输出优化器处理
if text and settings.STREAM_OPTIMIZER_ENABLED:
# 使用流式输出优化器处理文本输出
async for (
optimized_chunk
+1 -1
View File
@@ -215,7 +215,7 @@ class OpenAIChatService:
if openai_chunk:
# 提取文本内容
text = self._extract_text_from_openai_chunk(openai_chunk)
if text:
if text and settings.STREAM_OPTIMIZER_ENABLED:
# 使用流式输出优化器处理文本输出
async for (
optimized_chunk