ChemDave commited on
Commit
8f54ac7
·
verified ·
1 Parent(s): ba16d06

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +99 -0
app.py CHANGED
@@ -349,6 +349,104 @@ def evaluate_content_retrieval():
349
  print(f"PASS RATE: {passed / total:.1%}")
350
 
351
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
352
  def answer(question):
353
 
354
  relevant_content = retrieve_content(question)
@@ -465,5 +563,6 @@ demo = gr.Interface(
465
 
466
  evaluate_qa_retrieval()
467
  evaluate_content_retrieval()
 
468
  demo.launch()
469
 
 
349
  print(f"PASS RATE: {passed / total:.1%}")
350
 
351
 
352
+ def run_regression_tests():
353
+ tests = [
354
+ {
355
+ "name": "Titre QA rules",
356
+ "question": "How do I calculate titre from burette readings?",
357
+ "qa": {"QA-008", "QA-009"},
358
+ "sections": {"data_recording"}
359
+ },
360
+ {
361
+ "name": "Observation and inference",
362
+ "question": "Explain observation and inference.",
363
+ "qa": {"QA-007"},
364
+ "sections": {"important_distinctions"}
365
+ },
366
+ {
367
+ "name": "Equivalence point",
368
+ "question": "What is the equivalence point?",
369
+ "qa": {"QA-001", "QA-002"},
370
+ "sections": {"key_definitions"}
371
+ },
372
+ {
373
+ "name": "Stoichiometry",
374
+ "question": "Must H2SO4 and NaOH have equal moles?",
375
+ "qa": {"QA-003", "QA-004"},
376
+ "sections": {"calculation_rules"}
377
+ },
378
+ {
379
+ "name": "Hypothetical data",
380
+ "question": "Give me a hypothetical titration example.",
381
+ "qa": {"QA-005", "QA-006"},
382
+ "sections": {"data_recording"}
383
+ },
384
+ {
385
+ "name": "Laboratory safety",
386
+ "question": "What safety precautions should I take?",
387
+ "qa": set(),
388
+ "sections": {"safety"}
389
+ },
390
+ {
391
+ "name": "Indicator selection",
392
+ "question": "Why is phenolphthalein used?",
393
+ "qa": set(),
394
+ "sections": {"indicators"}
395
+ }
396
+ ]
397
+
398
+ passed = 0
399
+
400
+ for test in tests:
401
+ question = test["question"]
402
+
403
+ # Retrieve the QA rules for this question.
404
+ actual_qa = {
405
+ rule["id"]
406
+ for rule in retrieve_qa_rules(question)
407
+ }
408
+
409
+ # Retrieve the chemistry content sections.
410
+ actual_sections = set(
411
+ retrieve_content(question).keys()
412
+ )
413
+
414
+ # Check whether all expected items were retrieved.
415
+ qa_ok = test["qa"].issubset(actual_qa)
416
+ sections_ok = test["sections"].issubset(
417
+ actual_sections
418
+ )
419
+
420
+ success = qa_ok and sections_ok
421
+
422
+ print(
423
+ f"{'PASS' if success else 'FAIL'}: "
424
+ f"{test['name']}"
425
+ )
426
+
427
+ if not qa_ok:
428
+ print(
429
+ " Missing QA rules:",
430
+ sorted(test["qa"] - actual_qa)
431
+ )
432
+
433
+ if not sections_ok:
434
+ print(
435
+ " Missing sections:",
436
+ sorted(test["sections"] - actual_sections)
437
+ )
438
+
439
+ if success:
440
+ passed += 1
441
+
442
+ total = len(tests)
443
+
444
+ print(f"\nRegression result: {passed}/{total}")
445
+ print(f"Pass rate: {passed / total:.1%}")
446
+
447
+ return passed == total
448
+
449
+
450
  def answer(question):
451
 
452
  relevant_content = retrieve_content(question)
 
563
 
564
  evaluate_qa_retrieval()
565
  evaluate_content_retrieval()
566
+ run_regression_tests()
567
  demo.launch()
568