Spaces:
Paused
Paused
File size: 5,338 Bytes
378fe8c | 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 | """Check that the configured provider actually produces valid output.
An HTTP 200 proves nothing — llama2 7b/13b returned 200s full of wrong field
names, inline comments, and fractional weights. Only a real generation that
validates against the Pydantic schema counts as working.
Run before any deploy, and again after changing OBE_LLM_MODEL:
python scripts/verify_provider.py
Exits non-zero if any generation fails.
"""
import logging
import os
import sys
import time
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
from obe.course_plo_prompt import build_course_plo_messages
from obe.llm_client import (
generate_course_plo_mapping,
generate_obe_matrix,
generate_question_set,
get_provider,
)
from obe.prompt import build_messages
from obe.question_prompt import build_question_messages
from obe.schema import BLOOM_LABELS
logging.basicConfig(level=logging.INFO, format="%(levelname)s %(name)s: %(message)s")
CHAPTER = """
Memory is the process by which information is encoded, stored, and retrieved.
Encoding converts sensory input into a form the brain can process. Storage
maintains that information over time, across sensory, short-term, and long-term
stores. Retrieval brings stored information back into awareness. The multi-store
model distinguishes these stages, while the levels-of-processing framework
argues that depth of processing at encoding predicts later recall better than
time spent in any one store. Interference and decay both explain forgetting.
"""
PLOS = [
"PLO-01: Apply core psychological theories to explain human behaviour.",
"PLO-02: Evaluate research evidence critically.",
]
def _check(label: str, fn) -> tuple[bool, float]:
print(f"\n-- {label} " + "-" * (56 - len(label)))
start = time.perf_counter()
try:
result = fn()
except Exception as exc:
elapsed = time.perf_counter() - start
print(f" FAIL ({elapsed:.1f}s): {type(exc).__name__}: {exc}")
return False, elapsed
elapsed = time.perf_counter() - start
print(f" OK ({elapsed:.1f}s)")
return True, elapsed
def _obe():
matrix = generate_obe_matrix(build_messages("Cognitive Psychology", PLOS, CHAPTER))
assert matrix.clos, "no CLOs generated"
first = matrix.clos[0]
weights = first.assessment_weights
total = weights.quiz + weights.assignment + weights.midterm + weights.final
print(f" {len(matrix.clos)} CLOs; first at Bloom {first.bloom_level} "
f"({first.bloom_label}); weights sum to {total:g}")
print(f" CLO: {first.clo_text[:80]}")
return matrix
def _questions():
qs = generate_question_set(
build_question_messages(
clo_text="Explain how encoding depth affects long-term recall.",
content_text=CHAPTER,
bloom_level=2,
bloom_label=BLOOM_LABELS[2],
difficulty="Medium",
question_type="MCQ (single correct)",
question_count=3,
option_count=4,
)
)
assert qs.questions, "no questions generated"
first = qs.questions[0]
assert len(first.options) == 4, f"expected 4 options, got {len(first.options)}"
print(f" {len(qs.questions)} questions; {len(first.options)} options on the first")
print(f" Q: {first.question_text[:80]}")
return qs
def _mapping():
result = generate_course_plo_mapping(
build_course_plo_messages(
program="BS Psychology",
course_batch=[
{
"Code": "PSY-101",
"Course Title": "Introduction to Psychology",
"Objectives": "Survey of major areas of psychology.",
"Cr. Hrs.": "3",
},
{
"Code": "PSY-201",
"Course Title": "Research Methods I",
"Objectives": "Design and evaluation of psychological research.",
"Cr. Hrs.": "3",
},
],
plo_list=[
{"PLO Code": "PLO-01", "PLO Text": PLOS[0]},
{"PLO Code": "PLO-02", "PLO Text": PLOS[1]},
],
)
)
assert result.mappings, "no mappings generated"
codes = [m.course_code for m in result.mappings]
print(f" {len(result.mappings)} courses mapped: {', '.join(codes)}")
return result
def main() -> int:
provider = get_provider()
print(f"Provider : {provider.name}")
print(f"Model : {provider.model}")
print(f"Schema : {provider.schema_mode.value}")
print(f"Timeout : {provider.timeout}s")
if provider.schema_mode.value != "native":
print("\n NOTE: no constrained decoding for this model — output is not")
print(" schema-guaranteed. The runner will fall back and repair, but")
print(" a strict-capable model is safer for production.")
results = [
_check("OBEMatrix", _obe),
_check("QuestionSet", _questions),
_check("CoursePLOMappingSet", _mapping),
]
passed = sum(1 for ok, _ in results if ok)
total_time = sum(t for _, t in results)
print("\n" + "=" * 60)
print(f"{passed}/{len(results)} passed in {total_time:.1f}s")
return 0 if passed == len(results) else 1
if __name__ == "__main__":
sys.exit(main())
|