fix: Ensure explicit returns and correct async calls

Adds explicit `return None` statements in several functions across different modules to improve code clarity and prevent potential issues where functions might implicitly return None.
Corrects an async call in `Heartflow.deactivate_chat` by adding `await`.
Updates type hints in `heartflow_prompt_builder.py`.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
春河晴
2025-04-23 15:18:01 +09:00
parent 7e26304e94
commit 9b9dbbd74d
4 changed files with 8 additions and 4 deletions

View File

@@ -97,6 +97,7 @@ class MaiState(enum.Enum):
return 3
elif self == MaiState.FOCUSED_CHAT:
return 2
return None
def get_focused_chat_max_num(self):
if self == MaiState.OFFLINE:
@@ -107,6 +108,7 @@ class MaiState(enum.Enum):
return 1
elif self == MaiState.FOCUSED_CHAT:
return 2
return None
class MaiStateInfo:
@@ -879,7 +881,7 @@ class Heartflow:
if subflow.chat_state.chat_status != ChatState.ABSENT:
logger.debug(f"[Heartflow Deactivate] 正在将子心流 {stream_name} 状态设置为 ABSENT。")
# 调用 set_chat_state它会处理日志和状态更新
subflow.set_chat_state(ChatState.ABSENT)
await subflow.set_chat_state(ChatState.ABSENT)
deactivated_count += 1
else:
# 如果已经是 ABSENT则无需再次设置但记录一下检查

View File

@@ -7,7 +7,7 @@ from src.plugins.utils.chat_message_builder import build_readable_messages, get_
from src.plugins.person_info.relationship_manager import relationship_manager
from src.plugins.chat.utils import get_embedding, parse_text_timestamps
import time
from typing import Union
from typing import Union, Optional
from ...common.database import db
from ..chat.utils import get_recent_group_speaker
from ..moods.moods import MoodManager
@@ -80,12 +80,13 @@ class PromptBuilder:
async def build_prompt(
self, build_mode, reason, current_mind_info, message_txt: str, sender_name: str = "某人", chat_stream=None
) -> tuple[str, str]:
) -> Optional[tuple[str, str]]:
if build_mode == "normal":
return await self._build_prompt_normal(chat_stream, message_txt, sender_name)
elif build_mode == "focus":
return await self._build_prompt_focus(reason, current_mind_info, chat_stream, message_txt, sender_name)
return None
async def _build_prompt_focus(
self, reason, current_mind_info, chat_stream, message_txt: str, sender_name: str = "某人"

View File

@@ -689,7 +689,7 @@ class LLMRequest:
stream_mode = request_content["stream_mode"]
if response.status in policy["retry_codes"] or response.status in policy["abort_codes"]:
await self._handle_error_response(response, retry_count, policy)
return
return None
response.raise_for_status()
result = {}