This commit is contained in:
tt-P607
2025-11-01 20:55:45 +08:00
5 changed files with 15 additions and 9 deletions

View File

@@ -444,10 +444,13 @@ class ChatManager:
return stream
# 使用优化后的API查询带缓存
current_time = time.time()
model_instance, _ = await get_or_create_chat_stream(
stream_id=stream_id,
platform=platform,
defaults={
"create_time": current_time,
"last_active_time": current_time,
"user_platform": user_info.platform if user_info else platform,
"user_id": user_info.user_id if user_info else "",
"user_nickname": user_info.user_nickname if user_info else "",

View File

@@ -1468,18 +1468,15 @@ class DefaultReplyer:
if now < start_time:
now += timedelta(days=1)
if start_time <= now < end_time:
duration_minutes = (now - start_time).total_seconds() / 60
remaining_minutes = (end_time - now).total_seconds() / 60
schedule_block = (
duration_minutes = (now - start_time).total_seconds() / 60
remaining_minutes = (end_time - now).total_seconds() / 60
schedule_block = (
f"你当前正在进行“{activity}”,"
f"计划时间从{start_time.strftime('%H:%M')}{end_time.strftime('%H:%M')}"
f"这项活动已经开始了{duration_minutes:.0f}分钟,"
f"预计还有{remaining_minutes:.0f}分钟结束。"
"(此为你的当前状态,仅供参考。除非被直接询问,否则不要在对话中主动提及。)"
)
else:
schedule_block = f"你当前正在进行“{activity}”。(此为你的当前状态,仅供参考。除非被直接询问,否则不要在对话中主动提及。)"
except (ValueError, AttributeError):
schedule_block = f"你当前正在进行“{activity}”。(此为你的当前状态,仅供参考。除非被直接询问,否则不要在对话中主动提及。)"

View File

@@ -350,10 +350,10 @@ def _default_normal_response_parser(
api_response.tool_calls = []
for call in message_part.tool_calls:
try:
arguments = orjson.loads(repair_json(call.function.arguments))
arguments = orjson.loads(repair_json(call.function.arguments)) # type: ignore
if not isinstance(arguments, dict):
raise RespParseException(resp, "响应解析失败,工具调用参数无法解析为字典类型")
api_response.tool_calls.append(ToolCall(call.id, call.function.name, arguments))
api_response.tool_calls.append(ToolCall(call.id, call.function.name, arguments)) # type: ignore
except orjson.JSONDecodeError as e:
raise RespParseException(resp, "响应解析失败,无法解析工具调用参数") from e

View File

@@ -257,14 +257,20 @@ class RelationshipFetcher:
"""
try:
from src.common.database.api.specialized import get_or_create_chat_stream
import time
# 使用优化后的API带缓存
# 从stream_id解析platform或使用默认值
platform = stream_id.split("_")[0] if "_" in stream_id else "unknown"
current_time = time.time()
stream, _ = await get_or_create_chat_stream(
stream_id=stream_id,
platform=platform,
defaults={
"create_time": current_time,
"last_active_time": current_time,
},
)
if not stream:

View File

@@ -112,7 +112,7 @@ class BaseTool(ABC):
if not cls.is_two_step_tool:
return []
definitions: ClassVar = []
definitions = []
for sub_name, sub_desc, sub_params in cls.sub_tools:
definitions.append({"name": f"{cls.name}_{sub_name}", "description": sub_desc, "parameters": sub_params})
return definitions