more typing fix和防炸
This commit is contained in:
@@ -271,8 +271,8 @@ async def _default_stream_response_handler(
|
||||
_insure_buffer_closed()
|
||||
raise ReqAbortException("请求被外部信号中断")
|
||||
# 空 choices / usage-only 帧的防御
|
||||
if not getattr(event, "choices", None) or len(event.choices) == 0:
|
||||
if getattr(event, "usage", None):
|
||||
if not hasattr(event, "choices") or not event.choices:
|
||||
if hasattr(event, "usage") and event.usage:
|
||||
_usage_record = (
|
||||
event.usage.prompt_tokens or 0,
|
||||
event.usage.completion_tokens or 0,
|
||||
|
||||
@@ -19,7 +19,7 @@ logger = get_logger("person_api")
|
||||
# =============================================================================
|
||||
|
||||
|
||||
def get_person_id(platform: str, user_id: int) -> str:
|
||||
def get_person_id(platform: str, user_id: int | str) -> str:
|
||||
"""根据平台和用户ID获取person_id
|
||||
|
||||
Args:
|
||||
@@ -33,7 +33,7 @@ def get_person_id(platform: str, user_id: int) -> str:
|
||||
person_id = person_api.get_person_id("qq", 123456)
|
||||
"""
|
||||
try:
|
||||
return Person(platform=platform, user_id=user_id).person_id
|
||||
return Person(platform=platform, user_id=str(user_id)).person_id
|
||||
except Exception as e:
|
||||
logger.error(f"[PersonAPI] 获取person_id失败: platform={platform}, user_id={user_id}, error={e}")
|
||||
return ""
|
||||
|
||||
@@ -98,7 +98,9 @@ async def _send_to_target(
|
||||
|
||||
if reply_message:
|
||||
anchor_message = message_dict_to_message_recv(reply_message)
|
||||
if anchor_message:
|
||||
anchor_message.update_chat_stream(target_stream)
|
||||
assert anchor_message.message_info.user_info, "用户信息缺失"
|
||||
reply_to_platform_id = (
|
||||
f"{anchor_message.message_info.platform}:{anchor_message.message_info.user_info.user_id}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user