more typing fix和防炸
This commit is contained in:
@@ -271,14 +271,14 @@ async def _default_stream_response_handler(
|
|||||||
_insure_buffer_closed()
|
_insure_buffer_closed()
|
||||||
raise ReqAbortException("请求被外部信号中断")
|
raise ReqAbortException("请求被外部信号中断")
|
||||||
# 空 choices / usage-only 帧的防御
|
# 空 choices / usage-only 帧的防御
|
||||||
if not getattr(event, "choices", None) or len(event.choices) == 0:
|
if not hasattr(event, "choices") or not event.choices:
|
||||||
if getattr(event, "usage", None):
|
if hasattr(event, "usage") and event.usage:
|
||||||
_usage_record = (
|
_usage_record = (
|
||||||
event.usage.prompt_tokens or 0,
|
event.usage.prompt_tokens or 0,
|
||||||
event.usage.completion_tokens or 0,
|
event.usage.completion_tokens or 0,
|
||||||
event.usage.total_tokens or 0,
|
event.usage.total_tokens or 0,
|
||||||
)
|
)
|
||||||
continue # 跳过本帧,避免访问 choices[0]
|
continue # 跳过本帧,避免访问 choices[0]
|
||||||
delta = event.choices[0].delta # 获取当前块的delta内容
|
delta = event.choices[0].delta # 获取当前块的delta内容
|
||||||
|
|
||||||
if hasattr(delta, "reasoning_content") and delta.reasoning_content: # type: ignore
|
if hasattr(delta, "reasoning_content") and delta.reasoning_content: # type: ignore
|
||||||
@@ -479,7 +479,7 @@ class OpenaiClient(BaseClient):
|
|||||||
req_task.cancel()
|
req_task.cancel()
|
||||||
raise ReqAbortException("请求被外部信号中断")
|
raise ReqAbortException("请求被外部信号中断")
|
||||||
await asyncio.sleep(0.1) # 等待0.5秒后再次检查任务&中断信号量状态
|
await asyncio.sleep(0.1) # 等待0.5秒后再次检查任务&中断信号量状态
|
||||||
|
|
||||||
# logger.info(f"OpenAI请求时间: {model_info.model_identifier} {time.time() - start_time} \n{messages}")
|
# logger.info(f"OpenAI请求时间: {model_info.model_identifier} {time.time() - start_time} \n{messages}")
|
||||||
|
|
||||||
resp, usage_record = async_response_parser(req_task.result())
|
resp, usage_record = async_response_parser(req_task.result())
|
||||||
|
|||||||
@@ -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
|
"""根据平台和用户ID获取person_id
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -33,7 +33,7 @@ def get_person_id(platform: str, user_id: int) -> str:
|
|||||||
person_id = person_api.get_person_id("qq", 123456)
|
person_id = person_api.get_person_id("qq", 123456)
|
||||||
"""
|
"""
|
||||||
try:
|
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:
|
except Exception as e:
|
||||||
logger.error(f"[PersonAPI] 获取person_id失败: platform={platform}, user_id={user_id}, error={e}")
|
logger.error(f"[PersonAPI] 获取person_id失败: platform={platform}, user_id={user_id}, error={e}")
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
@@ -98,10 +98,12 @@ async def _send_to_target(
|
|||||||
|
|
||||||
if reply_message:
|
if reply_message:
|
||||||
anchor_message = message_dict_to_message_recv(reply_message)
|
anchor_message = message_dict_to_message_recv(reply_message)
|
||||||
anchor_message.update_chat_stream(target_stream)
|
if anchor_message:
|
||||||
reply_to_platform_id = (
|
anchor_message.update_chat_stream(target_stream)
|
||||||
f"{anchor_message.message_info.platform}:{anchor_message.message_info.user_info.user_id}"
|
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}"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
reply_to_platform_id = ""
|
reply_to_platform_id = ""
|
||||||
anchor_message = None
|
anchor_message = None
|
||||||
|
|||||||
Reference in New Issue
Block a user