feat: 回忆录证据血缘与内部评测可追溯,顺带对齐本地评测台与 CI

数据库与模型:新增多版迁移(章节证据快照、对话血缘、记忆事实/时间线 lineage 等),把「成稿 ↔ 对话/记忆」的溯源信息落到表结构里。
业务链路:会话与 WS、回忆录/故事流水线、记忆写入与 enrichment 等跟着接上线索与快照;新增章节证据快照与评测侧 EvalTraceService 等模块,方便组评审用的证据包。
内部评测:自动化 run 与手工 memoir 评审共用可追溯证据;rubric/ judge 相关脚本与文档有配套调整。
app-eval-web:Memoir/实验详情里能展开看证据摘要与 evidence_trace(含对话轮次 id);Vite 代理与 development.sh 注入的 API 端口与当前默认内部评测端口一致,避免改端口后页面连错服务。
工程杂项:GitHub Actions / 仓库说明有更新;各适配器与支付/配额/plan 等多处为小改动或跟随主改动的收尾;新增/扩充了?
This commit is contained in:
Kevin
2026-04-08 15:37:09 +08:00
parent 6772e1269c
commit 309a051038
109 changed files with 4125 additions and 858 deletions

View File

@@ -2,6 +2,8 @@
配额检查业务逻辑。
「对话轮数」的定义每条用户发出的消息Segment 表的记录数)计为 1 轮。
限额与 [app.features.plan.catalog](catalog) 中的套餐定义一致,单一事实来源。
"""
from sqlalchemy import func, select
@@ -9,36 +11,9 @@ from sqlalchemy.ext.asyncio import AsyncSession
from app.features.conversation.models import Conversation, Segment
from app.features.memoir.models import Chapter
from app.features.plan.catalog import get_plan_by_type
from app.features.quota.schemas import QuotaCheckResponse
PLAN_QUOTAS = {
"free": {
"max_conversations": 50,
"max_chapters": 1,
"max_words": None,
},
"pro": {
"max_conversations": 2000,
"max_chapters": None,
"max_words": None,
},
"pro_plus": {
"max_conversations": 10000,
"max_chapters": None,
"max_words": None,
},
"premium": {
"max_conversations": None,
"max_chapters": None,
"max_words": None,
},
"test": {
"max_conversations": None,
"max_chapters": None,
"max_words": None,
},
}
async def get_segment_count(user_id: str, db: AsyncSession) -> int:
"""获取用户已消耗的对话轮数(= 该用户所有 Segment 记录数)。"""
@@ -71,8 +46,8 @@ def check_can_send_message(
segment_count: int,
) -> tuple[bool, str]:
"""检查用户是否还能发送消息(对话轮数)。返回 (是否允许, 提示信息)。"""
quotas = PLAN_QUOTAS.get(subscription_type, PLAN_QUOTAS["free"])
max_conv = quotas.get("max_conversations")
plan = get_plan_by_type(subscription_type)
max_conv = plan.max_conversations
if max_conv is None:
return True, ""
if segment_count >= max_conv:
@@ -88,8 +63,8 @@ def check_can_submit_organize(
chapter_count: int,
) -> tuple[bool, str]:
"""检查是否可以提交整理任务(生成新章节)。免费版仅允许 1 个章节。"""
quotas = PLAN_QUOTAS.get(subscription_type, PLAN_QUOTAS["free"])
max_ch = quotas.get("max_chapters")
plan = get_plan_by_type(subscription_type)
max_ch = plan.max_chapters
if max_ch is None:
return True, ""
if chapter_count >= max_ch:
@@ -123,11 +98,10 @@ class QuotaService:
async def check(self, user_id: str, subscription_type: str) -> QuotaCheckResponse:
"""检查用户配额使用情况。"""
quotas = PLAN_QUOTAS.get(subscription_type, PLAN_QUOTAS["free"])
plan = get_plan_by_type(subscription_type)
segment_count, chapter_count = await self.get_usage(user_id)
max_conversations = quotas.get("max_conversations")
max_chapters = quotas.get("max_chapters")
max_words = quotas.get("max_words")
max_conversations = plan.max_conversations
max_chapters = plan.max_chapters
remaining_conversations = None
remaining_chapters = None