Skip to content

Review 数据模型

字数
946 字
阅读时间
5 分钟

定义 Review Pipeline 的输入/输出结构,与具体实现解耦。

ReviewScore

角色体验评分(0-1 浮点数),8 个维度。

python
from nbot.review.models import ReviewScore

score = ReviewScore(
    character_fidelity=0.8,
    immersion=0.7,
    relationship_progress=0.5,
    story_progress=0.6,
    memory_value=0.4,
    world_consistency=0.9,
    user_engagement=0.6,
    risk=0.1,
)
字段说明
character_fidelity角色一致性:回复是否贴合角色设定
immersion沉浸感:场景描写与情感表达质量
relationship_progress关系推进:关系是否有实质性发展
story_progress剧情推进:剧情是否有实质性进展
memory_value记忆价值:本轮对话是否值得记录
world_consistency世界一致性:是否与既定世界观/设定一致
user_engagement用户互动:用户参与度
risk风险评分:内容是否存在偏离设定或前后矛盾的风险

评分来源:

  • character_fidelity / immersion / world_consistency / risk:来自 AutoState 的 LLM 评估缓存
  • memory_value / story_progress / relationship_progress / user_engagement:规则引擎计算

MemoryItem

待写入的记忆条目。

python
from nbot.review.models import MemoryItem

item = MemoryItem(
    target="user",
    mem_type="relationship",
    title="用户表达了喜欢",
    content="用户:我很喜欢你\n角色:谢谢你的喜欢!",
    importance=0.7,
    ttl="long",
)
字段可选值说明
targetuser / character / world记忆目标
mem_typeshort / long / relationship / event记忆类型
titlestr记忆标题
contentstr记忆内容
importancefloat重要性(0-1)
ttlshort / long / permanent保留时间

RelationshipDelta

关系变化结果,六维增量。

python
from nbot.review.models import RelationshipDelta

delta = RelationshipDelta(
    affection=2,
    trust=1,
    familiarity=1,
    dependency=0,
    security=0,
    jealousy=0,
    reason="用户表达了亲密情感;选择了 important 级剧情分支。",
)
字段类型说明
affectionint好感度增量
trustint信任度增量
familiarityint熟悉度增量
dependencyint依赖度增量
securityint安全感增量
jealousyint嫉妒度增量
reasonstr变化原因(人类可读)
sourcestr来源(默认 "review_pipeline"
plot_node_idstr关联的剧情节点 ID
conversation_idstr关联的会话 ID

PlotUpdate

剧情更新建议。

字段类型说明
should_create_nodebool是否需要创建剧情节点
levelstr节点级别:normal / important / turning_point / ending
summarystr剧情摘要
titlestr节点标题

WorldBookUpdate

世界书更新建议。

字段类型说明
should_updatebool是否需要更新世界书
reasonstr更新原因
entry_titlestr条目标题
entry_contentstr条目内容

ReviewInput

Review Pipeline 输入,包含本轮对话的完整上下文。

python
from nbot.review.models import ReviewInput

inp = ReviewInput(
    conversation_id="conv_abc",
    character_id="char_xyz",
    user_id="user_123",
    user_message="你好,今天天气真好",
    assistant_message="是的,天气很好呢!",
    selected_choice={"level": "normal", "text": "继续聊天"},
    relationship_state={"affection": 75, "trust": 60},
    character_state={"mood": "happy", "energy": 0.8},
    real_time_context={"continuity_level": "continuous", "elapsed_label": "5分钟"},
)
字段类型说明
conversation_idstr会话 ID
character_idstr角色 ID
user_idstr用户 ID
group_idstr群聊 ID(可选)
user_messagestr用户消息
assistant_messagestrAI 回复
recent_messageslist[dict]最近消息列表
active_plot_nodedict | None当前激活的剧情节点
selected_choicedict | None已选择的剧情选项
relationship_statedict关系状态
character_statedict角色状态
world_contextdict世界上下文
real_time_contextdict现实时间上下文
tool_callslist[dict]工具调用记录

ReviewOutput

Review Pipeline 输出,结构化的审查结果。

python
from nbot.review.models import ReviewOutput

output = ReviewOutput(
    should_write_memory=True,
    memory_items=[MemoryItem(...)],
    relationship_delta=RelationshipDelta(...),
    plot_update=PlotUpdate(should_create_node=True, level="important"),
    scores=ReviewScore(...),
    source="rule",
    skipped=False,
)
字段类型说明
should_write_memorybool是否需要写入记忆
memory_itemslist[MemoryItem]待写入的记忆条目
relationship_deltaRelationshipDelta | None关系变化增量
plot_updatePlotUpdate | None剧情更新建议
world_book_updateWorldBookUpdate | None世界书更新建议
scoresReviewScore | None各维度评分
sourcestr审查来源:"rule""llm"
skippedbool是否跳过(普通闲聊)

页面历史