File size: 22,213 Bytes
65f7070
8bb96b1
65f7070
 
8bb96b1
65f7070
8bb96b1
 
9950bf5
 
65f7070
8bb96b1
9950bf5
 
 
65f7070
9950bf5
8bb96b1
 
 
 
aa9aebe
 
 
 
 
65f7070
9950bf5
 
 
65f7070
8bb96b1
65f7070
 
9950bf5
65f7070
 
9950bf5
65f7070
9950bf5
65f7070
9950bf5
65f7070
 
 
 
 
9950bf5
65f7070
9950bf5
65f7070
 
 
 
9950bf5
65f7070
 
 
9950bf5
65f7070
 
 
 
 
 
 
 
 
 
 
8bb96b1
 
65f7070
 
 
 
 
8bb96b1
65f7070
 
8bb96b1
65f7070
8bb96b1
9950bf5
 
 
8bb96b1
65f7070
 
9950bf5
65f7070
 
 
 
 
 
9950bf5
 
65f7070
 
 
8bb96b1
65f7070
8bb96b1
65f7070
 
 
 
cacb554
65f7070
8bb96b1
65f7070
 
 
8bb96b1
65f7070
 
 
 
8bb96b1
65f7070
 
cacb554
65f7070
8bb96b1
65f7070
 
8bb96b1
 
65f7070
 
 
9950bf5
aa9aebe
65f7070
aa9aebe
65f7070
9950bf5
65f7070
 
9950bf5
 
65f7070
 
 
 
 
 
aa9aebe
 
 
 
 
cacb554
aa9aebe
 
 
 
 
 
cacb554
aa9aebe
 
 
cacb554
 
 
 
 
 
 
 
 
 
 
65f7070
 
 
 
 
 
 
cacb554
 
8bb96b1
65f7070
8bb96b1
 
65f7070
 
 
 
9950bf5
65f7070
9950bf5
65f7070
9950bf5
65f7070
 
 
 
 
 
 
 
 
9950bf5
8bb96b1
 
65f7070
 
8bb96b1
65f7070
 
 
 
 
cacb554
65f7070
 
 
 
 
cacb554
65f7070
8bb96b1
65f7070
 
8bb96b1
 
 
65f7070
 
 
aa9aebe
65f7070
aa9aebe
65f7070
 
 
 
8bb96b1
 
 
65f7070
 
 
 
 
 
aa9aebe
cacb554
 
aa9aebe
 
 
cacb554
aa9aebe
 
 
 
65f7070
 
 
 
aa9aebe
 
 
cacb554
aa9aebe
 
65f7070
cacb554
 
 
 
 
 
 
 
 
 
 
65f7070
 
 
 
 
 
 
cacb554
 
65f7070
 
8bb96b1
 
 
65f7070
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9950bf5
 
 
8bb96b1
65f7070
 
 
 
 
 
 
 
 
 
 
 
 
cacb554
65f7070
8bb96b1
65f7070
 
 
cacb554
9950bf5
 
65f7070
 
9950bf5
 
65f7070
 
 
 
 
9950bf5
8bb96b1
65f7070
 
cacb554
 
 
8bb96b1
65f7070
cacb554
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9950bf5
cacb554
9950bf5
cacb554
8bb96b1
cacb554
65f7070
cacb554
65f7070
cacb554
8bb96b1
cacb554
 
 
 
 
9950bf5
 
 
 
65f7070
 
 
 
 
8bb96b1
65f7070
 
 
 
 
 
 
 
 
 
9950bf5
 
 
65f7070
 
 
 
8bb96b1
65f7070
 
 
cacb554
65f7070
 
 
 
 
cacb554
65f7070
 
 
 
9950bf5
 
 
65f7070
 
cacb554
65f7070
 
 
 
8bb96b1
65f7070
 
 
 
 
cacb554
9950bf5
 
 
 
65f7070
 
 
9950bf5
65f7070
9950bf5
65f7070
 
 
 
 
 
 
8bb96b1
9950bf5
 
8bb96b1
65f7070
 
9950bf5
65f7070
 
aa9aebe
65f7070
aa9aebe
65f7070
 
 
 
9950bf5
 
8bb96b1
65f7070
 
 
aa9aebe
65f7070
 
aa9aebe
 
 
cacb554
 
aa9aebe
 
 
cacb554
 
 
 
 
 
65f7070
aa9aebe
9950bf5
 
8bb96b1
65f7070
 
8bb96b1
65f7070
 
 
8bb96b1
65f7070
 
 
9950bf5
65f7070
 
 
9950bf5
65f7070
 
 
9950bf5
cacb554
 
 
9950bf5
cacb554
 
aa9aebe
cacb554
 
 
 
 
 
 
 
 
65f7070
 
 
 
 
 
 
 
9950bf5
 
65f7070
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cacb554
65f7070
 
 
 
aa9aebe
 
65f7070
cacb554
65f7070
 
 
 
 
 
 
 
 
 
 
cacb554
aa9aebe
 
9950bf5
 
65f7070
 
 
 
9950bf5
65f7070
9950bf5
65f7070
9950bf5
65f7070
9950bf5
65f7070
 
 
 
 
9950bf5
65f7070
9950bf5
65f7070
9950bf5
65f7070
 
 
 
9950bf5
65f7070
 
 
9950bf5
65f7070
 
 
 
9950bf5
65f7070
9950bf5
65f7070
9950bf5
65f7070
 
 
 
 
9950bf5
65f7070
9950bf5
8bb96b1
9950bf5
65f7070
8bb96b1
 
9950bf5
 
 
 
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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
# ruff: noqa
"""
Interactive Exploration: Cognitive Load Theory & AI-Generated Worked Examples
Five hands-on labs to understand how to design educational AI tools

Built for embedding in Quarto workshop materials
"""

import marimo

__generated_with = "0.17.8"
app = marimo.App(width="medium")


@app.cell
def _():
    import marimo as mo
    from openai import OpenAI
    from pydantic import BaseModel, Field
    from typing import Literal
    import os
    from dotenv import load_dotenv

    # Load environment variables from .env file
    load_dotenv()

    return BaseModel, Field, OpenAI, mo, os


@app.cell
def _(mo):
    mo.md("""
    # πŸ§ͺ Interactive Exploration Lab
    ## Designing AI Tools Grounded in Cognitive Load Theory

    Welcome to the **interactive exploration**! This isn't a complete toolβ€”it's a laboratory
    where you'll experiment with the key design decisions that make AI educational tools effective.

    ### What You'll Explore

    Through 5 hands-on labs, you'll discover:

    1. 🎨 **Prompt Design Lab** - How prompt engineering shapes learning
    2. βš–οΈ **Personalization A/B Test** - Feel the cognitive load difference
    3. πŸ—οΈ **Data Model Designer** - What makes examples "worked"
    4. πŸŽ›οΈ **Parameter Playground** - Model settings and pedagogy
    5. πŸ” **CLT Analyzer** - Evaluate examples with a critical lens

    ### Why This Matters

    You could just use a tool. But **understanding the design principles** lets you:
    - Adapt tools to your specific domain
    - Critique and improve existing AI educational tools
    - Design new tools grounded in learning science

    **Ready to explore?** Let's start with the setup.
    """)
    return


@app.cell
def _(OpenAI, os):
    """Setup: Initialize OpenAI client"""
    client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
    return (client,)


@app.cell
def _(mo):
    mo.md("""
    ---

    ## 🎨 Lab 1: Prompt Design Laboratory

    **Learning Question**: How does prompt engineering affect the quality of worked examples?

    ### The Experiment

    You'll see **two prompts** - a basic one and one grounded in CLT principles.
    Try editing them and see how the outputs change.

    **Key insight**: The prompt IS your pedagogical design encoded in language.
    """)
    return


@app.cell
def _(BaseModel, Field):
    """Simple data model for Lab 1"""

    class SimpleExample(BaseModel):
        """Minimal structure for prompt comparison"""
        problem: str = Field(description="The problem to solve")
        solution: str = Field(description="Step-by-step solution")
        explanation: str = Field(description="Why this approach works")
    return (SimpleExample,)


@app.cell
def _(mo):
    """Lab 1: Prompt inputs"""

    mo.md("### Try These Prompts")

    basic_prompt = mo.ui.text_area(
        label="Basic Prompt (no pedagogical grounding):",
        value="""Create an example problem about Python for loops and solve it step by step.""",
        full_width=True,
        rows=3
    )

    clt_prompt = mo.ui.text_area(
        label="CLT-Grounded Prompt (reduces cognitive load):",
        value="""Create a worked example about Python for loops.

    CRITICAL: This is a WORKED EXAMPLE for novice learners.
    - Problem: Clear, specific, uses familiar context (counting items)
    - Solution: Break into small steps, explain each step's purpose
    - Explanation: Connect to WHY this pattern works (not just WHAT it does)

    Keep cognitive load low: avoid technical jargon, use concrete examples.""",
        full_width=True,
        rows=8
    )

    mo.vstack([basic_prompt, clt_prompt])
    return basic_prompt, clt_prompt


@app.cell
def _(mo):
    """Lab 1: Generate button"""

    lab1_button = mo.ui.run_button(
        label="πŸ”¬ Generate Both Examples",
        kind="success",
    )

    mo.md(f"### Compare the Results\n\n{lab1_button}")
    return (lab1_button,)


@app.cell
def _(SimpleExample, basic_prompt, client, clt_prompt, lab1_button, mo):
    """Lab 1: Generate and compare both examples"""

    lab1_output = None

    if lab1_button.value and basic_prompt.value and clt_prompt.value:
        with mo.status.spinner(title="Generating both examples..."):
            basic_response = client.responses.parse(
                model="gpt-5.1",
                input=[{"role": "user", "content": basic_prompt.value}],
                text_format=SimpleExample
            )
            basic_example = basic_response.output_parsed

            clt_response = client.responses.parse(
                model="gpt-5.1",
                input=[{"role": "user", "content": clt_prompt.value}],
                text_format=SimpleExample
            )
            clt_example = clt_response.output_parsed

        lab1_output = mo.vstack([
            mo.md("### πŸ“Š Basic Prompt Result"),
            mo.md(f"**Problem:** {basic_example.problem}"),
            mo.md(f"**Solution:** {basic_example.solution}"),
            mo.md(f"**Explanation:** {basic_example.explanation}"),
            mo.md("---"),
            mo.md("### πŸŽ“ CLT-Grounded Prompt Result"),
            mo.md(f"**Problem:** {clt_example.problem}"),
            mo.md(f"**Solution:** {clt_example.solution}"),
            mo.md(f"**Explanation:** {clt_example.explanation}"),
            mo.callout(mo.md("""
            ### πŸ’­ What Do You Notice?

            - Which problem is clearer and more specific?
            - Which solution breaks down steps better?
            - Which explanation helps you understand WHY, not just WHAT?

            **The prompt IS your pedagogical design!**
            """), kind="info")
        ])

    lab1_output


@app.cell
def _(mo):
    mo.md("""
    ---

    ## βš–οΈ Lab 2: Personalization A/B Test

    **Learning Question**: Can you FEEL the difference in cognitive load?

    ### The Experiment

    You'll enter YOUR context (hobby, goal), then see the SAME concept taught:
    - **Generic**: Standard textbook style
    - **Personalized**: Using your context

    **Hypothesis**: The personalized version should feel more engaging and easier to process.
    """)
    return


@app.cell
def _(mo):
    """Lab 2: Context inputs"""

    mo.md("### Your Context")

    your_hobby = mo.ui.text(
        label="Your hobby or interest:",
        placeholder="e.g., photography, cooking, gaming",
        full_width=True
    )

    your_goal = mo.ui.text(
        label="What you want to achieve:",
        placeholder="e.g., build a recipe app, automate photo editing",
        full_width=True
    )

    mo.vstack([your_hobby, your_goal])
    return your_hobby, your_goal


@app.cell
def _(mo):
    """Lab 2: Generate button"""

    lab2_button = mo.ui.run_button(
        label="βš–οΈ Generate A/B Comparison",
        kind="success",
    )

    mo.md(f"{lab2_button}")
    return (lab2_button,)


@app.cell
def _(SimpleExample, client, lab2_button, mo, your_goal, your_hobby):
    """Lab 2: Generate A/B comparison"""

    lab2_output = None

    if lab2_button.value and your_hobby.value and your_goal.value:
        with mo.status.spinner(title="Generating generic and personalized examples..."):

            generic_prompt = "Create a worked example about Python dictionaries for beginners."
            generic_response = client.responses.parse(
                model="gpt-5.1",
                input=[{"role": "user", "content": generic_prompt}],
                text_format=SimpleExample
            )
            generic_example = generic_response.output_parsed

            personalized_prompt = f"""Create a worked example about Python dictionaries for beginners.

IMPORTANT: Personalize this example for someone who is interested in {your_hobby.value} and wants to {your_goal.value}.
Use familiar contexts and examples from their interest to make the concept more relatable and reduce cognitive load."""

            personalized_response = client.responses.parse(
                model="gpt-5.1",
                input=[{"role": "user", "content": personalized_prompt}],
                text_format=SimpleExample
            )
            personalized_example = personalized_response.output_parsed

        lab2_output = mo.vstack([
            mo.md("### πŸ“– Generic Example (Standard Textbook Style)"),
            mo.md(f"**Problem:** {generic_example.problem}"),
            mo.md(f"**Solution:** {generic_example.solution}"),
            mo.md(f"**Explanation:** {generic_example.explanation}"),
            mo.md("---"),
            mo.md(f"### ✨ Personalized Example (Your Context: {your_hobby.value})"),
            mo.md(f"**Problem:** {personalized_example.problem}"),
            mo.md(f"**Solution:** {personalized_example.solution}"),
            mo.md(f"**Explanation:** {personalized_example.explanation}"),
            mo.callout(mo.md("""
            ### πŸ’­ How Did That Feel?

            - Which example was more engaging to read?
            - Which one felt easier to process mentally?
            - Could you visualize the personalized example more easily?

            **This is the personalization effect in action!** Familiar contexts reduce extraneous cognitive load.
            """), kind="success")
        ])

    lab2_output


@app.cell
def _(mo):
    mo.md("""
    ---

    ## πŸ—οΈ Lab 3: Data Model Designer

    **Learning Question**: What makes a worked example "worked"?

    ### The Experiment

    Design the data structure for a worked example. What fields do you need?
    Think about:
    - What cognitive load principle does each field support?
    - How does structure guide the AI's output?

    **Current Model** (you can modify this in your mind):
    ```python
    class WorkedExample:
        problem: str           # What they need to solve
        solution_steps: list   # Broken into chunks (why a list?)
        final_answer: str      # Clear conclusion
        key_insight: str       # Schema activation
    ```
    """)
    return


@app.cell
def _(mo):
    """Lab 3: Interactive field selector"""

    mo.md("### Which Fields Support Learning?")

    field_options = {
        "problem: str": "The problem statement",
        "solution_steps: list[str]": "Steps as a list (chunking!)",
        "solution: str": "Solution as one big block",
        "final_answer: str": "Explicit conclusion",
        "key_insight: str": "Why this approach works",
        "code_with_comments: str": "Annotated code",
        "common_mistakes: str": "What to avoid",
        "connection_to_real_world: str": "Practical relevance"
    }

    field_selector = mo.ui.multiselect(
        options=list(field_options.keys()),
        label="Select fields for YOUR ideal worked example:",
        value=["problem: str", "solution_steps: list[str]", "final_answer: str", "key_insight: str"]
    )

    field_selector
    return (field_selector,)


@app.cell
def _(field_selector, mo):
    """Lab 3: Display selection count"""
    mo.md(f"**You selected {len(field_selector.value)} fields**")
    return


@app.cell
def _(field_selector, mo):
    """Lab 3: Adaptive analysis based on selections"""

    analysis_output = None

    if field_selector.value:
        selected = field_selector.value

        # Analyze specific choices
        has_chunked_solution = "solution_steps: list[str]" in selected
        has_monolithic_solution = "solution: str" in selected
        has_key_insight = "key_insight: str" in selected
        has_common_mistakes = "common_mistakes: str" in selected
        has_final_answer = "final_answer: str" in selected
        has_code_comments = "code_with_comments: str" in selected
        has_real_world = "connection_to_real_world: str" in selected
        has_problem = "problem: str" in selected

        # Detect issues
        contradiction = has_chunked_solution and has_monolithic_solution
        too_many_fields = len(selected) >= 7
        too_few_fields = len(selected) <= 2
        no_chunking = not has_chunked_solution

        # Calculate design score
        design_score = 0
        feedback_items = []

        # Essential field
        if has_problem:
            design_score += 1
        else:
            feedback_items.append("⚠️ Missing `problem` field - students need to know what to solve!")

        # Chunking (most critical for CLT)
        if has_chunked_solution and not has_monolithic_solution:
            design_score += 2  # Worth 2 points!
            feedback_items.append("βœ… **Excellent**: `solution_steps: list[str]` implements **chunking** (reduces intrinsic load)")
        elif has_monolithic_solution and not has_chunked_solution:
            feedback_items.append("❌ **Problem**: `solution: str` as one block creates **high cognitive load** for novices")
        elif contradiction:
            feedback_items.append("⚠️ **Contradiction**: You have BOTH chunked and monolithic solutions - choose one!")
        else:
            feedback_items.append("⚠️ **Missing**: No solution field at all - how will students see the steps?")

        # Schema activation
        if has_key_insight:
            design_score += 1
            feedback_items.append("βœ… `key_insight` supports **schema activation** (connects to prior knowledge)")
        else:
            feedback_items.append("πŸ’‘ **Consider adding**: `key_insight` for schema activation")

        # Desirable difficulty
        if has_common_mistakes:
            design_score += 1
            feedback_items.append("βœ… `common_mistakes` creates **desirable difficulty** (learning from contrasts)")

        # Closure
        if has_final_answer:
            design_score += 1
            feedback_items.append("βœ… `final_answer` provides **closure** (reduces uncertainty)")

        # Additional good choices
        if has_code_comments:
            feedback_items.append("βœ… `code_with_comments` uses **dual coding** (text + code)")

        if has_real_world:
            feedback_items.append("βœ… `connection_to_real_world` adds **relevance** (reduces extraneous load)")

        # Check for cognitive overload
        if too_many_fields:
            design_score -= 1
            feedback_items.append("⚠️ **Cognitive overload risk**: 7-8 fields may overwhelm novices. Consider focusing on core elements.")

        if too_few_fields and not contradiction:
            feedback_items.append("πŸ’‘ **Suggestion**: Add more fields to support learning (aim for 4-6 well-chosen fields)")

        # Determine overall quality
        max_design_score = 6
        if design_score >= 5:
            quality = "🌟 **Excellent pedagogical design!**"
            kind = "success"
        elif design_score >= 3:
            quality = "πŸ‘ **Good design with room for improvement**"
            kind = "info"
        else:
            quality = "⚠️ **Needs pedagogical revision**"
            kind = "warn"

        # Build the output
        analysis_output = mo.vstack([
            mo.md(f"""
            ### Your Selected Structure

            ```python
            class WorkedExample:
                {chr(10).join(['    ' + f for f in selected])}
            ```
            """),
            mo.callout(mo.md(f"""
            ### πŸ“Š Pedagogical Analysis

            **Score: {design_score}/{max_design_score}**

            {quality}

            #### Design Evaluation:

            {chr(10).join(['- ' + item for item in feedback_items])}

            ---

            **Key Principle**: The design IS the pedagogy. Each field choice implements (or undermines) a CLT principle.
            """), kind=kind)
        ])

    analysis_output
    return


@app.cell
def _(mo):
    mo.md("""
    ---

    ## πŸŽ›οΈ Lab 4: Parameter Playground

    **Learning Question**: How do model parameters affect pedagogical quality?

    ### The Experiment

    GPT-5.1 has parameters like `reasoning.effort`. Try different settings and see
    how they affect example quality.

    **Note**: This lab is conceptual---showing the parameters you COULD control.
    """)
    return


@app.cell
def _(mo):
    """Lab 4: Parameter sliders"""

    mo.md("### Adjust Parameters")

    reasoning_effort = mo.ui.dropdown(
        options=["none", "low", "medium", "high"],
        value="low",
        label="Reasoning Effort (how much thinking?)"
    )

    verbosity = mo.ui.dropdown(
        options=["low", "medium", "high"],
        value="medium",
        label="Verbosity (explanation detail)"
    )

    mo.vstack([reasoning_effort, verbosity])
    return reasoning_effort, verbosity


@app.cell
def _(mo, reasoning_effort, verbosity):
    """Lab 4: Display parameter info"""
    mo.callout(mo.md(f"""
    **Current Settings:**

    - Reasoning: {reasoning_effort.value}
    - Verbosity: {verbosity.value}

    **For novices**: Low reasoning (fast), medium-high verbosity (detailed explanations)

    **For experts**: Higher reasoning (better solutions), lower verbosity (concise)

    The "best" parameters depend on your learners!
    """), kind="info")
    return


@app.cell
def _(mo):
    mo.md("""
    ---

    ## πŸ” Lab 5: CLT Analyzer

    **Learning Question**: Can you evaluate examples using CLT principles?

    ### The Experiment

    Read an AI-generated example and evaluate it against CLT criteria.
    This develops your **critical lens** for educational AI.
    """)
    return


@app.cell
def _(mo):
    """Lab 5: Generate button"""

    mo.md("### Generate an Example to Analyze")

    lab5_button = mo.ui.run_button(
        label="🎲 Generate Random Example",
        kind="neutral",
    )

    lab5_button
    return (lab5_button,)


@app.cell
def _(SimpleExample, client, lab5_button, mo):
    """Lab 5: Generate and display example to analyze"""

    example_output = None

    if lab5_button.value:
        with mo.status.spinner(title="Generating example..."):
            response = client.responses.parse(
                model="gpt-5.1",
                input=[{"role": "user", "content": "Create a worked example about Python dictionaries for beginners."}],
                text_format=SimpleExample
            )
            analyze_example = response.output_parsed

        example_output = mo.vstack([
            mo.md("### Example to Analyze"),
            mo.md(f"**Problem:** {analyze_example.problem}"),
            mo.md(f"**Solution:** {analyze_example.solution}"),
            mo.md(f"**Explanation:** {analyze_example.explanation}"),
        ])

    example_output


@app.cell
def _(mo):
    """Lab 5: CLT evaluation checklist"""

    reduces_extraneous = mo.ui.checkbox(
        label="βœ… Reduces extraneous cognitive load (no unnecessary complexity)"
    )

    manages_intrinsic = mo.ui.checkbox(
        label="βœ… Manages intrinsic load (breaks problem into chunks)"
    )

    optimizes_germane = mo.ui.checkbox(
        label="βœ… Optimizes germane load (helps build schemas/patterns)"
    )

    worked_not_problem = mo.ui.checkbox(
        label="βœ… Is a WORKED example (shows complete solution, not a puzzle)"
    )

    clear_steps = mo.ui.checkbox(
        label="βœ… Has clear step-by-step progression"
    )

    explains_why = mo.ui.checkbox(
        label="βœ… Explains WHY, not just WHAT"
    )

    mo.vstack([
        reduces_extraneous,
        manages_intrinsic,
        optimizes_germane,
        worked_not_problem,
        clear_steps,
        explains_why
    ])
    return (
        clear_steps,
        explains_why,
        manages_intrinsic,
        optimizes_germane,
        reduces_extraneous,
        worked_not_problem,
    )


@app.cell
def _(
    clear_steps,
    explains_why,
    manages_intrinsic,
    mo,
    optimizes_germane,
    reduces_extraneous,
    worked_not_problem,
):
    """Lab 5: Scoring"""

    checklist_values = [
        reduces_extraneous.value,
        manages_intrinsic.value,
        optimizes_germane.value,
        worked_not_problem.value,
        clear_steps.value,
        explains_why.value
    ]

    score = sum(1 for v in checklist_values if v)

    score_output = None

    if score > 0:
        score_output = mo.callout(f"""
        ### Score: {score}/6

        {"🌟" * score}

        **Interpretation:**
        - 5-6: Excellent pedagogical design
        - 3-4: Good, but room for improvement
        - 1-2: Needs significant pedagogical revision
        - 0: Not yet evaluated

        **Key Skill**: You're developing a CLT-grounded critical lens for evaluating AI tools!
        """, kind="success" if score >= 5 else "info")

    score_output


@app.cell
def _(mo):
    mo.md("""
    ---

    ## 🎯 Conclusion: From Exploration to Creation

    ### What You Discovered

    Through these 5 labs, you explored:

    1. βœ… **Prompts encode pedagogy** - Design drives outputs
    2. βœ… **Personalization reduces load** - Context matters
    3. βœ… **Structure shapes learning** - Data models are pedagogical choices
    4. βœ… **Parameters affect quality** - Settings have learning implications
    5. βœ… **Critical evaluation is a skill** - You can assess AI tools with CLT

    ### What's Next?

    Now that you understand the **design principles**, you're ready to:

    **Option 1: Build Your Own Tool**
    - Use the simplified code from the workshop
    - Apply these design principles
    - Deploy to HuggingFace Spaces

    **Option 2: Use the Complete Tool**
    - [Try the full Worked Example Weaver](https://huggingface.co/spaces/virtuelleakademie/worked-example-weaver-app)
    - See all 5 principles integrated

    **Option 3: Adapt to Your Domain**
    - Take the template
    - Add your concepts
    - Customize for your learners

    ### The Big Idea

    AI tools for education should be **grounded in learning science**, not just technically impressive.

    You now have:
    - 🧠 The theoretical foundation (CLT)
    - πŸ”¬ Hands-on experience (these labs)
    - πŸ› οΈ The technical skills (simple OpenAI API)
    - 🎯 A critical lens (can evaluate tools)

    **Go build something that helps people learn!**

    ---

    *Created by the [Virtual Academy](https://virtuelleakademie.ch/), BFH*
    """)
    return


if __name__ == "__main__":
    app.run()