Fix/Restore user information archive and one-sentence summary (#37)
* [fix]fix memory insights * [fix]fix memory insights * [fix]Based on the correction of the code by sourcery-ai * [fix]Restore user information archive and one-sentence summary
This commit is contained in:
@@ -11,6 +11,7 @@ from app.db import get_db
|
||||
from app.core.logging_config import get_api_logger
|
||||
from app.core.response_utils import success, fail
|
||||
from app.core.error_codes import BizCode
|
||||
from app.core.api_key_utils import timestamp_to_datetime
|
||||
from app.services.user_memory_service import (
|
||||
UserMemoryService,
|
||||
analytics_memory_types,
|
||||
@@ -356,7 +357,7 @@ async def update_end_user_profile(
|
||||
if 'hire_date' in update_data:
|
||||
hire_date_timestamp = update_data['hire_date']
|
||||
if hire_date_timestamp is not None:
|
||||
update_data['hire_date'] = UserMemoryService.timestamp_to_datetime(hire_date_timestamp)
|
||||
update_data['hire_date'] = timestamp_to_datetime(hire_date_timestamp)
|
||||
# 如果是 None,保持 None(允许清空)
|
||||
|
||||
for field, value in update_data.items():
|
||||
|
||||
@@ -85,33 +85,21 @@ Example Output:
|
||||
===End of Example===
|
||||
|
||||
|
||||
===Reflection Process===
|
||||
===Internal Quality Checks (DO NOT OUTPUT)===
|
||||
|
||||
After generating the profile, perform the following self-review steps:
|
||||
Before generating your final output, internally verify:
|
||||
1. All content is grounded in provided data (no fabrication)
|
||||
2. Format follows the specified structure with correct headers
|
||||
3. Tone is objective, third-person, and neutral
|
||||
4. All four sections are complete and within character limits
|
||||
|
||||
**Step 1: Data Grounding Check**
|
||||
- Verify all statements are supported by the provided entities and statements
|
||||
- Ensure no fabricated or speculated information is included
|
||||
- Confirm all claims can be traced back to the input data
|
||||
|
||||
**Step 2: Format Compliance**
|
||||
- Verify each section follows the specified format with section headers
|
||||
- Check character count limits for each section
|
||||
- Ensure proper use of section markers (【】)
|
||||
|
||||
**Step 3: Tone and Style Review**
|
||||
- Confirm objective third-person perspective is maintained
|
||||
- Check for excessive adjectives or empty phrases
|
||||
- Verify neutral and restrained tone throughout
|
||||
|
||||
**Step 4: Completeness Check**
|
||||
- Ensure all four sections are present and complete
|
||||
- Verify each section addresses its specific focus area
|
||||
- Confirm the one-sentence summary effectively captures the user's essence
|
||||
**IMPORTANT: These checks are for your internal use only. DO NOT include them in your output.**
|
||||
|
||||
|
||||
===Output Requirements===
|
||||
|
||||
**CRITICAL: Your response must ONLY contain the four sections below. Do not include any reflection, self-review, or meta-commentary.**
|
||||
|
||||
**LANGUAGE REQUIREMENT:**
|
||||
- The output language should ALWAYS be Chinese (Simplified)
|
||||
- All section content must be in Chinese
|
||||
@@ -122,3 +110,5 @@ After generating the profile, perform the following self-review steps:
|
||||
- Content follows immediately after the header
|
||||
- Sections are separated by blank lines
|
||||
- Strictly adhere to character limits for each section
|
||||
- **DO NOT include any text after the 【一句话总结】 section**
|
||||
- **DO NOT output reflection steps, self-review, or verification notes**
|
||||
|
||||
@@ -1054,6 +1054,28 @@ async def analytics_user_summary(end_user_id: Optional[str] = None) -> Dict[str,
|
||||
core_values = core_values_match.group(1).strip() if core_values_match else ""
|
||||
one_sentence = one_sentence_match.group(1).strip() if one_sentence_match else ""
|
||||
|
||||
# 6) 清理可能包含的反思内容(防御性编程)
|
||||
# 如果 LLM 仍然输出了反思内容,在这里过滤掉
|
||||
def clean_reflection_content(text: str) -> str:
|
||||
"""移除可能包含的反思内容"""
|
||||
if not text:
|
||||
return text
|
||||
# 移除 "---" 之后的所有内容(通常是反思部分的开始)
|
||||
if '---' in text:
|
||||
text = text.split('---')[0].strip()
|
||||
# 移除 "**Step" 开头的内容
|
||||
if '**Step' in text:
|
||||
text = text.split('**Step')[0].strip()
|
||||
# 移除 "Self-Review" 相关内容
|
||||
if 'Self-Review' in text or 'self-review' in text:
|
||||
text = re.sub(r'[\-\*]*\s*Self-Review.*$', '', text, flags=re.IGNORECASE | re.DOTALL).strip()
|
||||
return text
|
||||
|
||||
user_summary = clean_reflection_content(user_summary)
|
||||
personality = clean_reflection_content(personality)
|
||||
core_values = clean_reflection_content(core_values)
|
||||
one_sentence = clean_reflection_content(one_sentence)
|
||||
|
||||
return {
|
||||
"user_summary": user_summary,
|
||||
"personality": personality,
|
||||
|
||||
Reference in New Issue
Block a user