-
Notifications
You must be signed in to change notification settings - Fork 20
feat(scrapbook): 群贤毕至添加头像 #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideAdds avatar support and a chat-style layout for golden quotes in scrapbook templates, propagating QQ IDs from message analysis through data models and generators to templates so each quote can render an optional user avatar and styled sender name. Class diagram for updated GoldenQuote model and usageclassDiagram
class GoldenQuote {
+str content
+str sender
+str reason
+int qq
}
class GoldenQuoteAnalyzer {
+extract_interesting_messages(messages)
+analyze_golden_quotes(messages, umo)
}
class ReportGenerator {
+_prepare_render_data(analysis_result)
+_get_user_avatar(user_id)
}
class QuoteTemplateContext {
+str content
+str sender
+str reason
+str avatar_url
}
GoldenQuoteAnalyzer ..> GoldenQuote : creates
GoldenQuoteAnalyzer ..> ReportGenerator : provides_golden_quotes
ReportGenerator ..> GoldenQuote : reads
ReportGenerator ..> QuoteTemplateContext : builds
QuoteTemplateContext ..> GoldenQuote : derived_from
Flow diagram for QQ avatar propagation into scrapbook templatesflowchart LR
A["Raw chat messages
list[dict]"] --> B["GoldenQuoteAnalyzer
extract_interesting_messages"]
B --> C["interesting_messages
with sender, time, content, qq"]
C --> D["GoldenQuoteAnalyzer
analyze_golden_quotes"]
D --> E["GoldenQuote objects
(content, sender, reason, qq)"]
E --> F["ReportGenerator
_prepare_render_data"]
F --> G["_get_user_avatar(qq)
returns avatar_url or None"]
G --> H["quotes_list items
(content, sender, reason, avatar_url)"]
H --> I["quote_item.html
uses avatar_url, sender,
content, reason"]
I --> J["image_template.html /
pdf_template.html
render chat-style bubbles
with optional avatars"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've found 1 issue, and left some high level feedback:
- In
analyze_golden_quotes, thelogger.info(f"开始从 {len(interesting_messages)} 条圣经消息中提取金句")line is logged twice in a row; consider removing one to avoid redundant log noise. - The QQ backfill loop in
analyze_golden_quotesrelies on substring matching ofcontent, which may misassign when different messages share similar text; if possible, prefer using a stable identifier (e.g., message ID) or a stronger matching key to link quotes back tointeresting_messages. - The CSS for
.q-sender-namediffers betweenimage_template.html(usesvar(--font-hand)) andpdf_template.html(hardcodes'Long Cang', cursive); if this isn’t intentional, aligning them to the same variable-based font definition would keep the two renderings visually consistent.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `analyze_golden_quotes`, the `logger.info(f"开始从 {len(interesting_messages)} 条圣经消息中提取金句")` line is logged twice in a row; consider removing one to avoid redundant log noise.
- The QQ backfill loop in `analyze_golden_quotes` relies on substring matching of `content`, which may misassign when different messages share similar text; if possible, prefer using a stable identifier (e.g., message ID) or a stronger matching key to link quotes back to `interesting_messages`.
- The CSS for `.q-sender-name` differs between `image_template.html` (uses `var(--font-hand)`) and `pdf_template.html` (hardcodes `'Long Cang', cursive`); if this isn’t intentional, aligning them to the same variable-based font definition would keep the two renderings visually consistent.
## Individual Comments
### Comment 1
<location> `src/analysis/analyzers/golden_quote_analyzer.py:194-204` </location>
<code_context>
+ for msg in interesting_messages:
+ # 尝试匹配内容和发送者
+ # 注意:LLM 可能会微调内容,这里使用包含匹配或精确匹配
+ if (
+ quote.content in msg["content"]
+ or msg["content"] in quote.content
+ ) and quote.sender == msg["sender"]:
+ quote.qq = msg.get("qq", 0)
+ break
</code_context>
<issue_to_address>
**suggestion (bug_risk):** The content containment matching for backfilling QQ IDs may incorrectly associate quotes when messages share overlapping content.
The containment check (`quote.content in msg["content"] or msg["content"] in quote.content`) is likely to match the wrong message when content is short or shared across multiple messages (repetitions, common phrases, quotes), which can backfill an incorrect `qq`. To reduce false matches, consider tightening the criteria (e.g., prefer exact equality, add timestamp proximity or minimum-length requirements, and short‑circuit on exact match before using containment).
```suggestion
# 回填QQ号
for quote in quotes:
for msg in interesting_messages:
# 先严格匹配:内容完全一致且发送者一致
if quote.sender == msg["sender"] and quote.content == msg["content"]:
quote.qq = msg.get("qq", 0)
break
# 再进行保守的包含匹配:
# - 仍然要求发送者一致
# - 只对较长内容启用(避免短语/常用语误匹配)
# - 使用双向包含作为兜底
if quote.sender == msg["sender"]:
content_quote = quote.content or ""
content_msg = msg.get("content") or ""
min_length = 20 # 避免短内容造成大量误匹配
if (
len(content_quote) >= min_length
and len(content_msg) >= min_length
and (
content_quote in content_msg
or content_msg in content_quote
)
):
quote.qq = msg.get("qq", 0)
break
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| # 回填QQ号 | ||
| for quote in quotes: | ||
| for msg in interesting_messages: | ||
| # 尝试匹配内容和发送者 | ||
| # 注意:LLM 可能会微调内容,这里使用包含匹配或精确匹配 | ||
| if ( | ||
| quote.content in msg["content"] | ||
| or msg["content"] in quote.content | ||
| ) and quote.sender == msg["sender"]: | ||
| quote.qq = msg.get("qq", 0) | ||
| break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): The content containment matching for backfilling QQ IDs may incorrectly associate quotes when messages share overlapping content.
The containment check (quote.content in msg["content"] or msg["content"] in quote.content) is likely to match the wrong message when content is short or shared across multiple messages (repetitions, common phrases, quotes), which can backfill an incorrect qq. To reduce false matches, consider tightening the criteria (e.g., prefer exact equality, add timestamp proximity or minimum-length requirements, and short‑circuit on exact match before using containment).
| # 回填QQ号 | |
| for quote in quotes: | |
| for msg in interesting_messages: | |
| # 尝试匹配内容和发送者 | |
| # 注意:LLM 可能会微调内容,这里使用包含匹配或精确匹配 | |
| if ( | |
| quote.content in msg["content"] | |
| or msg["content"] in quote.content | |
| ) and quote.sender == msg["sender"]: | |
| quote.qq = msg.get("qq", 0) | |
| break | |
| # 回填QQ号 | |
| for quote in quotes: | |
| for msg in interesting_messages: | |
| # 先严格匹配:内容完全一致且发送者一致 | |
| if quote.sender == msg["sender"] and quote.content == msg["content"]: | |
| quote.qq = msg.get("qq", 0) | |
| break | |
| # 再进行保守的包含匹配: | |
| # - 仍然要求发送者一致 | |
| # - 只对较长内容启用(避免短语/常用语误匹配) | |
| # - 使用双向包含作为兜底 | |
| if quote.sender == msg["sender"]: | |
| content_quote = quote.content or "" | |
| content_msg = msg.get("content") or "" | |
| min_length = 20 # 避免短内容造成大量误匹配 | |
| if ( | |
| len(content_quote) >= min_length | |
| and len(content_msg) >= min_length | |
| and ( | |
| content_quote in content_msg | |
| or content_msg in content_quote | |
| ) | |
| ): | |
| quote.qq = msg.get("qq", 0) | |
| break |
Summary by Sourcery
Add avatar support and refreshed layout for scrapbook golden quote items across HTML, PDF, and analysis pipeline.
New Features:
Enhancements: