fix: MCP插件TimeoutError修复 + 多项Bug修复和性能优化

- fix: MCP插件管理接口改为后台任务,修复TimeoutError
- fix: MCP连接失败后上下文清理的cancel scope错误
- feat: MCP插件后台注册添加重试机制
- fix: 限制每章自动创建伏笔数量上限
- fix: 修复JSON非法转义字符清洗
- fix: SSE流式生成添加心跳保活
- fix: 职业生成改用POST请求避免URL长度限制
- perf: 使用torch CPU版本加速Docker构建
- fix: 自动修复JSON字符串值中的裸换行符
- feat: 集成json5容错解析器
This commit is contained in:
未来
2026-04-26 13:58:15 +08:00
parent 5c22f29bf9
commit 17e78955a9
18 changed files with 559 additions and 179 deletions
+5 -4
View File
@@ -6,6 +6,7 @@ import json
from app.database import get_db
from app.services.ai_service import AIService
from app.services.json_helper import loads_json
from app.api.settings import get_user_ai_service
from app.services.prompt_service import PromptService
from app.logger import get_logger
@@ -166,7 +167,7 @@ async def generate_options(
# 使用统一的JSON清洗方法
cleaned_content = ai_service._clean_json_response(content)
result = json.loads(cleaned_content)
result = loads_json(cleaned_content)
# 校验返回格式
is_valid, error_msg = validate_options_response(result, step)
@@ -343,7 +344,7 @@ async def refine_options(
# 解析JSON
try:
cleaned_content = ai_service._clean_json_response(content)
result = json.loads(cleaned_content)
result = loads_json(cleaned_content)
# 校验返回格式
is_valid, error_msg = validate_options_response(result, step)
@@ -466,7 +467,7 @@ async def quick_generate(
# 使用统一的JSON清洗方法
cleaned_content = ai_service._clean_json_response(content)
result = json.loads(cleaned_content)
result = loads_json(cleaned_content)
# 合并用户已提供的信息(用户输入优先)
final_result = {
@@ -487,4 +488,4 @@ async def quick_generate(
logger.error(f"智能补全失败: {e}", exc_info=True)
return {
"error": str(e)
}
}