Update app.py
Browse files
app.py
CHANGED
|
@@ -25,6 +25,67 @@ client = InferenceClient(
|
|
| 25 |
# AI tutor function
|
| 26 |
# -----------------------------
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
def retrieve_content(question):
|
| 29 |
q = question.lower()
|
| 30 |
retrieved = {}
|
|
|
|
| 25 |
# AI tutor function
|
| 26 |
# -----------------------------
|
| 27 |
|
| 28 |
+
|
| 29 |
+
def retrieve_qa_rules(question):
|
| 30 |
+
q = question.lower()
|
| 31 |
+
|
| 32 |
+
# Map question topics to the QA rules they need.
|
| 33 |
+
topic_rules = {
|
| 34 |
+
"titre": {
|
| 35 |
+
"keywords": [
|
| 36 |
+
"titre", "burette", "initial reading",
|
| 37 |
+
"final reading", "volume delivered",
|
| 38 |
+
"volume used", "how much solution"
|
| 39 |
+
],
|
| 40 |
+
"rule_ids": ["QA-008", "QA-009"]
|
| 41 |
+
},
|
| 42 |
+
"observation": {
|
| 43 |
+
"keywords": [
|
| 44 |
+
"observation", "inference",
|
| 45 |
+
"observed", "measurement"
|
| 46 |
+
],
|
| 47 |
+
"rule_ids": ["QA-007"]
|
| 48 |
+
},
|
| 49 |
+
"endpoint": {
|
| 50 |
+
"keywords": [
|
| 51 |
+
"endpoint", "equivalence point"
|
| 52 |
+
],
|
| 53 |
+
"rule_ids": ["QA-001", "QA-002"]
|
| 54 |
+
},
|
| 55 |
+
"stoichiometry": {
|
| 56 |
+
"keywords": [
|
| 57 |
+
"stoichiometry", "moles",
|
| 58 |
+
"balanced equation", "h2so4",
|
| 59 |
+
"naoh", "c1v1", "c2v2"
|
| 60 |
+
],
|
| 61 |
+
"rule_ids": ["QA-003", "QA-004"]
|
| 62 |
+
},
|
| 63 |
+
"experimental_data": {
|
| 64 |
+
"keywords": [
|
| 65 |
+
"experimental data", "actual results",
|
| 66 |
+
"hypothetical", "invented results"
|
| 67 |
+
],
|
| 68 |
+
"rule_ids": ["QA-005", "QA-006"]
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
# Identify the QA rules relevant to this question.
|
| 73 |
+
relevant_ids = set()
|
| 74 |
+
|
| 75 |
+
for topic in topic_rules.values():
|
| 76 |
+
if any(keyword in q for keyword in topic["keywords"]):
|
| 77 |
+
relevant_ids.update(topic["rule_ids"])
|
| 78 |
+
|
| 79 |
+
# Keep only matching rules from the verified JSON file.
|
| 80 |
+
all_rules = chemistry_content.get("qa_rules", [])
|
| 81 |
+
|
| 82 |
+
selected_rules = [
|
| 83 |
+
rule for rule in all_rules
|
| 84 |
+
if rule.get("id") in relevant_ids
|
| 85 |
+
]
|
| 86 |
+
|
| 87 |
+
return selected_rules
|
| 88 |
+
|
| 89 |
def retrieve_content(question):
|
| 90 |
q = question.lower()
|
| 91 |
retrieved = {}
|