A8多套打包+M4归档+R5多图:存量功能备份
A8 多套交付包(packaging_task.py): - 修复交付包只打第1条混乱note的bug,按ImageCandidate.strategy分A/B/C组 - 每组生独立note_0N夹(6图+文案.txt),同seq留最新去重,老数据兼容 - task74端到端验:3套各6图,独立agent7项交叉验证全过 M4 归档(tasks.py/exports.py/前端): - list_tasks加date_from/date_to/product_id筛选+product_name批量填(防N+1) - 新增exports.py:产品JSON导出+标杆CSV导出(UTF-8 BOM) - 前端HistoryFilters日期/产品筛选+产品列+打回原因红banner - response.py加raise_param_error;独立agent验A1/A2/A9通过 R5 产品多图(product_images.py/020迁移/前端): - product_images表+5端点(上传/列/改场景/设主图/删图) - 生图按ROLE_SCENE_PREFERENCE选对应场景图,回落primary - 前端ProductImageManager多图画廊 R6 账号config拆页(settings/): - 配置页按角色拆/settings(运营+组长+admin)+/config(仅admin) - Key只显末4位不显余额(守红线) 核销表对齐真实代码状态:D1改稿框/M7裂变/E12评图分纠偏为已完成(曾漏回写) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -8,10 +8,10 @@ preference_aggregator:查最近50条 → 最常选角度 + 打回原因近3条
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from sqlalchemy import desc, func
|
||||
from sqlalchemy import desc
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.constants.enums import SIGNAL_WEIGHTS, DataOwnership, SignalType
|
||||
from app.constants.enums import SIGNAL_WEIGHTS, DataOwnership
|
||||
from app.middleware.workspace_guard import CurrentUser
|
||||
from app.models.flywheel import PreferenceEvent
|
||||
from app.models.task import GenerationTask
|
||||
@@ -20,8 +20,6 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
# 实时聚合窗口:最近50条事件
|
||||
_AGGREGATION_WINDOW = 50
|
||||
# 冷启动阈值:不足5条信号用产品档案冷启动
|
||||
_COLD_START_THRESHOLD = 5
|
||||
|
||||
|
||||
def record_signal(
|
||||
@@ -32,12 +30,14 @@ def record_signal(
|
||||
candidate_id: int | None = None,
|
||||
angle_label: str | None = None,
|
||||
reason: str | None = None,
|
||||
signal_meta: str | None = None,
|
||||
) -> None:
|
||||
"""
|
||||
写入飞轮信号。
|
||||
workspace_id + product_id 都必须有(基石C + 按产品分开学)。
|
||||
signal_weight 用枚举默认值,北哥可校准。
|
||||
data_ownership 默认 client_data(选择行为归客户)。
|
||||
signal_meta:JSON 扩展(如选图存 strategy),不参与角度聚合主逻辑。
|
||||
"""
|
||||
weight = SIGNAL_WEIGHTS.get(signal_type, 0)
|
||||
event = PreferenceEvent(
|
||||
@@ -50,6 +50,7 @@ def record_signal(
|
||||
candidate_id=candidate_id,
|
||||
angle_label=angle_label,
|
||||
reason=reason,
|
||||
signal_meta=signal_meta,
|
||||
data_ownership=DataOwnership.CLIENT_DATA,
|
||||
)
|
||||
try:
|
||||
@@ -69,14 +70,17 @@ def record_signal(
|
||||
|
||||
|
||||
def get_preference_context(
|
||||
db: Session, workspace_id: int, product_id: int
|
||||
db: Session, workspace_id: int, product_id: int,
|
||||
product_dict: dict[str, Any] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
实时聚合偏好上下文(最近50条 events)。
|
||||
返回:recent_preference摘要 + reject_reasons近3条 + injected_count。
|
||||
不足5条 → 冷启动提示(产品档案兜底,由 AIE prompt 层读 products.custom_prompt)。
|
||||
实时聚合偏好上下文(最近50条 events)供前端展示。
|
||||
R7断点3:统一口径——委托给生产链同一个 aggregate_preference_context(权重口径),
|
||||
消除"前端展示按次数/生成按权重"的口径分裂(说一套做一套)。
|
||||
按 workspace_id + product_id 严格过滤(不串数据,基石C)。
|
||||
"""
|
||||
from app.services.ai_engine.preference_aggregator import aggregate_preference_context
|
||||
|
||||
recent = (
|
||||
db.query(PreferenceEvent)
|
||||
.filter(
|
||||
@@ -87,35 +91,18 @@ def get_preference_context(
|
||||
.limit(_AGGREGATION_WINDOW)
|
||||
.all()
|
||||
)
|
||||
|
||||
if len(recent) < _COLD_START_THRESHOLD:
|
||||
return {
|
||||
"recent_preference": "信号不足,使用产品档案基线(冷启动)",
|
||||
"reject_reasons": [],
|
||||
"injected_count": len(recent),
|
||||
}
|
||||
|
||||
# 统计最常被选中的角度(text_edit 改稿=最强真实信号,按权重计入,倩倩姐2026-06-16)
|
||||
angle_counts: dict[str, int] = {}
|
||||
for ev in recent:
|
||||
if ev.signal_type in (SignalType.TEXT_SELECT, SignalType.APPROVE, SignalType.TEXT_EDIT) and ev.angle_label:
|
||||
angle_counts[ev.angle_label] = angle_counts.get(ev.angle_label, 0) + 1
|
||||
|
||||
top_angles = sorted(angle_counts.items(), key=lambda x: x[1], reverse=True)[:3]
|
||||
if top_angles:
|
||||
pref_desc = ";".join(f"{a}(已选{c}次)" for a, c in top_angles)
|
||||
preference_summary = f"最近偏好:{pref_desc}"
|
||||
else:
|
||||
preference_summary = "暂无明显角度偏好"
|
||||
|
||||
# 取最近3条打回原因原文(不做 AI 归纳,契约§3)
|
||||
reject_reasons = [
|
||||
ev.reason for ev in recent
|
||||
if ev.signal_type == SignalType.REJECT_WITH_REASON and ev.reason
|
||||
][:3]
|
||||
|
||||
events_dicts = [
|
||||
{"signal_type": e.signal_type, "workspace_id": e.workspace_id,
|
||||
"product_id": e.product_id, "angle_label": e.angle_label or "",
|
||||
"signal_weight": e.signal_weight, "reason": e.reason or ""}
|
||||
for e in recent
|
||||
]
|
||||
ctx = aggregate_preference_context(
|
||||
events_dicts, product_dict or {}, workspace_id, product_id
|
||||
)
|
||||
# 前端展示不需要 prompt_fragment(注入用),剥掉只回摘要+原因+计数
|
||||
return {
|
||||
"recent_preference": preference_summary,
|
||||
"reject_reasons": reject_reasons,
|
||||
"injected_count": len(recent),
|
||||
"recent_preference": ctx.get("recent_preference", ""),
|
||||
"reject_reasons": ctx.get("reject_reasons", []),
|
||||
"injected_count": ctx.get("injected_count", 0),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user