Spaces:
Sleeping
Sleeping
File size: 12,623 Bytes
c5d7500 2b5291f c5d7500 2b5291f c5d7500 2b5291f c5d7500 2b5291f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | from __future__ import annotations
from copy import deepcopy
from .constants import APPROVAL_REQUIRED_STAGE_IDS
from .compat import model_to_dict, model_validate
from .models import (
ArtifactStatus,
IssueSeverity,
IssueStatus,
IssueType,
LayoutSpec,
PedagogicalRole,
ProposedChange,
ProposedChangeSet,
ReviewRole,
RevisionConstraints,
Slide,
SlideClaim,
SpeakerNotes,
VisualAsset,
)
from .quality import approve_current_artifact, create_artifact_version, grade_stage, now_iso, upsert_issue
from .workflow import build_empty_state, record_prompt_run
def valid_minimal_job():
state = build_empty_state(
deck_title="Intro to Deterministic Slide QA",
source_url="mock://source/course-notes",
template_url="mock://template/course",
dry_run=True,
)
state.source_chunks = {
"chunk_1": "Deterministic slide QA requires objective mapping and supported claims.",
"chunk_2": "A worked example helps learners apply the concept.",
}
state.objectives = {
"obj_1": "Explain deterministic slide quality checks.",
"obj_2": "Apply quality checks to a worked example.",
}
state.slides = {
"slide_1": Slide(
slide_id="slide_1",
slide_number=1,
title="Deterministic Slide QA",
visible_text="Quality checks make slide readiness explicit.",
bullet_points=["Trace objectives", "Check evidence", "Validate layout"],
objective_ids=["obj_1"],
pedagogical_role=PedagogicalRole.CONCEPT,
requires_visual=True,
speaker_notes=SpeakerNotes(
slide_id="slide_1",
notes_text="Explain why readiness must be explicit before export.",
instructor_intent="Connect quality gates to production trust.",
estimated_teaching_time_seconds=180,
),
),
"slide_2": Slide(
slide_id="slide_2",
slide_number=2,
title="Worked QA Example",
visible_text="Use the checklist to evaluate one generated slide.",
bullet_points=["Map objective", "Inspect claim support", "Confirm layout"],
objective_ids=["obj_2"],
pedagogical_role=PedagogicalRole.WORKED_EXAMPLE,
requires_visual=False,
speaker_notes=SpeakerNotes(
slide_id="slide_2",
notes_text="Walk through each checklist item and ask learners what blocks export.",
instructor_intent="Make the gating rule concrete.",
estimated_teaching_time_seconds=240,
),
),
}
state.claims = {
"claim_1": SlideClaim(
claim_id="claim_1",
slide_id="slide_1",
claim_text="Quality checks make slide readiness explicit.",
source_ids=["source_1"],
source_chunk_ids=["chunk_1"],
review_status="supported",
),
"claim_2": SlideClaim(
claim_id="claim_2",
slide_id="slide_2",
claim_text="A worked example helps learners apply the concept.",
source_ids=["source_1"],
source_chunk_ids=["chunk_2"],
review_status="supported",
),
}
state.visual_assets = {
"asset_1": VisualAsset(
asset_id="asset_1",
slide_id="slide_1",
asset_type="diagram",
path_or_url="mock://asset/qa-flow",
prompt="Simple quality gate diagram",
purpose="instructional",
alt_text="Flow from generation through grading, approval, and export.",
source="mock",
license_status="generated",
approved_for_export=True,
)
}
state.layout_specs = {
"slide_1": LayoutSpec(
slide_id="slide_1",
layout_id="title_bullets_visual",
approved_template_id="default_course_template",
slot_assignments={
"title": "Deterministic Slide QA",
"bullets": ["Trace objectives", "Check evidence", "Validate layout"],
"visual": "asset_1",
},
),
"slide_2": LayoutSpec(
slide_id="slide_2",
layout_id="worked_example",
approved_template_id="default_course_template",
slot_assignments={
"title": "Worked QA Example",
"problem": "Evaluate one generated slide.",
"steps": ["Map objective", "Inspect claim support", "Confirm layout"],
},
),
}
# Pydantic validates nested dicts assigned above during this explicit round-trip;
# this explicit round-trip keeps fixture construction terse and typed.
state = model_validate(type(state), model_to_dict(state))
for stage_id in APPROVAL_REQUIRED_STAGE_IDS:
prompt_run = record_prompt_run(
state,
stage_id,
rendered_prompt=f"Fixture generation for {stage_id}",
)
artifact = create_artifact_version(
state,
stage_id,
{"fixture": stage_id},
created_by="mock",
status=ArtifactStatus.CANDIDATE,
prompt_run_id=prompt_run.prompt_run_id,
mark_downstream_stale=False,
)
prompt_run.output_artifact_version_id = artifact.artifact_version_id
grade_stage(stage_id, state)
approve_current_artifact(state, stage_id, reviewer_name="fixture_reviewer")
return state
def missing_objective_mapping_job():
state = deepcopy(valid_minimal_job())
state.slides["slide_2"].objective_ids = []
return state
def stale_downstream_job():
state = deepcopy(valid_minimal_job())
create_artifact_version(
state,
"slide_outline_order",
{"fixture": "changed outline"},
created_by="human",
status=ArtifactStatus.CANDIDATE,
mark_downstream_stale=True,
)
return state
def invalidated_approval_job():
state = deepcopy(valid_minimal_job())
create_artifact_version(
state,
"text_generation",
{"fixture": "human edit after approval"},
created_by="human",
status=ArtifactStatus.CANDIDATE,
mark_downstream_stale=False,
)
return state
def unsupported_claim_job():
state = deepcopy(valid_minimal_job())
claim = state.claims["claim_1"]
claim.review_status = "unsupported"
claim.source_ids = []
claim.source_chunk_ids = []
return state
def missing_visual_asset_job():
state = deepcopy(valid_minimal_job())
state.visual_assets = {}
return state
def invalid_layout_job():
state = deepcopy(valid_minimal_job())
state.layout_specs["slide_1"] = LayoutSpec(
slide_id="slide_1",
layout_id="raw_coordinates",
approved_template_id=None,
slot_assignments={"x": 10, "y": 20, "width": 400, "height": 300},
)
return state
def text_density_failure_job():
state = deepcopy(valid_minimal_job())
state.slides["slide_1"].visible_text = " ".join(["dense"] * 80)
state.slides["slide_1"].bullet_points = ["one", "two", "three", "four", "five"]
return state
def review_queue_mixed_issues_job():
state = deepcopy(valid_minimal_job())
upsert_issue(
state,
IssueType.TEXT_DENSITY_EXCEEDED,
IssueSeverity.MAJOR,
"Slide text is too dense.",
stage_id="text_generation",
slide_id="slide_1",
)
upsert_issue(
state,
IssueType.ALT_TEXT_MISSING,
IssueSeverity.MINOR,
"Alt text needs review.",
stage_id="aesthetic_review",
slide_id="slide_1",
)
blocker = upsert_issue(
state,
IssueType.UNSUPPORTED_CLAIM,
IssueSeverity.BLOCKER,
"Unsupported claim blocks export.",
stage_id="technical_review",
slide_id="slide_1",
claim_id="claim_1",
)
blocker.assigned_role = ReviewRole.SME
return state
def role_filtered_review_job():
state = review_queue_mixed_issues_job()
visual_issue = upsert_issue(
state,
IssueType.LAYOUT_SCHEMA_INVALID,
IssueSeverity.MAJOR,
"Layout needs visual design review.",
stage_id="aesthetic_ordering_visual_composition",
slide_id="slide_2",
)
visual_issue.assigned_role = ReviewRole.VISUAL_DESIGNER
return state
def waivable_major_issue_job():
state = deepcopy(valid_minimal_job())
upsert_issue(
state,
IssueType.TEXT_DENSITY_EXCEEDED,
IssueSeverity.MAJOR,
"Major density issue can be waived with rationale.",
stage_id="text_generation",
slide_id="slide_1",
)
return state
def non_waivable_blocker_job():
state = deepcopy(valid_minimal_job())
upsert_issue(
state,
IssueType.UNSUPPORTED_CLAIM,
IssueSeverity.BLOCKER,
"Blocker cannot be waived.",
stage_id="technical_review",
slide_id="slide_1",
claim_id="claim_1",
)
return state
def proposed_change_set_job():
from .review import critique_artifact_for_improvement, create_proposed_change_set
state = waivable_major_issue_job()
critique = critique_artifact_for_improvement("text_generation", state)
create_proposed_change_set("text_generation", state, critique=critique)
return state
def constraint_violation_change_set_job():
state = deepcopy(valid_minimal_job())
artifact = next(
artifact
for artifact in state.artifacts.values()
if artifact.stage_id == "title_generation" and artifact.is_current
)
change_set = ProposedChangeSet(
change_set_id="changes_constraint_violation",
stage_id="title_generation",
artifact_version_id=artifact.artifact_version_id,
created_at=now_iso(),
constraints=RevisionConstraints(preserve_slide_titles=True),
changes=[
ProposedChange(
change_id="change_title_violation",
target_type="slide_title",
target_id="slide_1",
field_path="title",
before=state.slides["slide_1"].title,
after="Changed title",
)
],
)
state.proposed_change_sets[change_set.change_set_id] = change_set
return state
def selected_slide_improvement_job():
return deepcopy(valid_minimal_job())
def fast_path_stops_at_blocker_job():
return non_waivable_blocker_job()
def semantic_diff_changed_slide_job():
state = deepcopy(valid_minimal_job())
first = create_artifact_version(
state,
"text_generation",
{"slides": [model_to_dict(slide) for slide in state.slides.values()]},
created_by="mock",
status=ArtifactStatus.CANDIDATE,
mark_downstream_stale=False,
)
state.slides["slide_1"].title = "Changed Semantic Title"
second = create_artifact_version(
state,
"text_generation",
{"slides": [model_to_dict(slide) for slide in state.slides.values()]},
created_by="mock",
status=ArtifactStatus.CANDIDATE,
mark_downstream_stale=False,
)
first.status = ArtifactStatus.CANDIDATE
state.artifacts[first.artifact_version_id] = first
state.artifacts[second.artifact_version_id] = second
return state
def review_packet_job():
state = review_queue_mixed_issues_job()
issue = next(issue for issue in state.issues.values() if issue.severity == IssueSeverity.MAJOR)
issue.status = IssueStatus.WAIVED
issue.waiver_reason = "Accepted for this pilot deck."
return state
def restore_candidate_version_job():
state = deepcopy(valid_minimal_job())
artifact = create_artifact_version(
state,
"text_generation",
{"fixture": "restore source"},
created_by="human",
status=ArtifactStatus.CANDIDATE,
mark_downstream_stale=False,
)
artifact.is_current = False
artifact.status = ArtifactStatus.CANDIDATE
current = create_artifact_version(
state,
"text_generation",
{"fixture": "current candidate"},
created_by="human",
status=ArtifactStatus.CANDIDATE,
mark_downstream_stale=False,
)
artifact.status = ArtifactStatus.CANDIDATE
artifact.is_current = False
state.artifacts[artifact.artifact_version_id] = artifact
state.artifacts[current.artifact_version_id] = current
return state
|