refactor: Consolidate SSE and stream parsing logic into sse_parser.py, remove stream_parser.py, and update WebUI panel text.

This commit is contained in:
CJACK
2026-02-01 15:37:01 +08:00
parent e990517970
commit 1cf52502bb
5 changed files with 227 additions and 203 deletions

View File

@@ -20,12 +20,14 @@ from core.session_manager import (
cleanup_account,
)
from core.models import get_model_config, get_claude_models_response
from core.stream_parser import (
from core.sse_parser import (
parse_deepseek_sse_line,
parse_sse_chunk_for_content,
extract_content_from_chunk,
collect_deepseek_response,
parse_tool_calls,
)
from core.constants import STREAM_IDLE_TIMEOUT
from core.utils import estimate_tokens
from core.messages import (
messages_prepare,
@@ -36,6 +38,7 @@ from core.messages import (
router = APIRouter()
# ----------------------------------------------------------------------
# 通过 OpenAI 接口调用 Claude
# ----------------------------------------------------------------------
@@ -201,9 +204,7 @@ Remember: Output ONLY the JSON, no other text. The response must start with {{ a
if bool(req_data.get("stream", False)):
def claude_sse_stream():
# 智能超时配置
STREAM_IDLE_TIMEOUT = 30 # 无新内容超时(秒)
# 使用导入的常量(不再本地定义)
try:
message_id = f"msg_{int(time.time())}_{random.randint(1000, 9999)}"
input_tokens = sum(len(str(m.get("content", ""))) for m in messages) // 4
@@ -212,6 +213,7 @@ Remember: Output ONLY the JSON, no other text. The response must start with {{ a
last_content_time = time.time()
has_content = False
for line in deepseek_resp.iter_lines():
current_time = time.time()

View File

@@ -23,14 +23,12 @@ from core.session_manager import (
cleanup_account,
)
from core.models import get_model_config, get_openai_models_response
from core.stream_parser import (
parse_deepseek_sse_line,
extract_content_from_chunk,
should_filter_citation,
)
from core.sse_parser import (
parse_deepseek_sse_line,
parse_sse_chunk_for_content,
extract_content_from_chunk,
extract_content_recursive,
should_filter_citation,
)
from core.constants import (
KEEP_ALIVE_TIMEOUT,
@@ -47,6 +45,8 @@ _CITATION_PATTERN = re.compile(r"^\[citation:")
# ----------------------------------------------------------------------
# 路由:/v1/models
# ----------------------------------------------------------------------