feat: add stream parsing for DeepSeek SSE responses, centralize model management, and refactor tool call handling.

This commit is contained in:
CJACK
2026-02-01 03:53:01 +08:00
parent 4193336dd8
commit b90901d5a0
10 changed files with 359 additions and 192 deletions

29
core/utils.py Normal file
View File

@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
"""公共工具函数模块"""
def get_account_identifier(account: dict) -> str:
"""返回账号的唯一标识,优先使用 email否则使用 mobile"""
return account.get("email", "").strip() or account.get("mobile", "").strip()
def estimate_tokens(text) -> int:
"""估算文本的 token 数量(简单估算:字符数/4
Args:
text: 字符串或其他类型
Returns:
估算的 token 数量,最小为 1
"""
if isinstance(text, str):
return max(1, len(text) // 4)
elif isinstance(text, list):
return sum(
estimate_tokens(item.get("text", ""))
if isinstance(item, dict)
else estimate_tokens(str(item))
for item in text
)
else:
return max(1, len(str(text)) // 4)