Update reviewed server files: backend/rag.py
Browse files- backend/rag.py +4 -1
backend/rag.py
CHANGED
|
@@ -132,6 +132,9 @@ class SelectedAnswer(BaseModel):
|
|
| 132 |
model_config=ConfigDict(extra='forbid')
|
| 133 |
claims: list[QuoteSelection]=Field(max_length=2)
|
| 134 |
|
|
|
|
|
|
|
|
|
|
| 135 |
def evidence_quotes(evidence):
|
| 136 |
quotes={}
|
| 137 |
for source in evidence:
|
|
@@ -160,7 +163,7 @@ def inspection_facts(question, inspection):
|
|
| 160 |
score,threshold,margin=values
|
| 161 |
verdict=inspection.get('verdict')
|
| 162 |
if verdict not in ('Good','Anomalous','Uncertain') or margin<0:return None
|
| 163 |
-
category=inspection.get('category','selected product').replace('_',' ')
|
| 164 |
question=question.lower()
|
| 165 |
relevant=bool(re.search(r'\b(this|that|it|its|result|inspection|product|score|threshold|anomal\w*|normal|good|heatmap|map|confidence|accur\w*|probab\w*)\b',question))
|
| 166 |
if not relevant:return None
|
|
|
|
| 132 |
model_config=ConfigDict(extra='forbid')
|
| 133 |
claims: list[QuoteSelection]=Field(max_length=2)
|
| 134 |
|
| 135 |
+
# Same product names the dashboard shows, so answers never print internal keys like 'pcb1'.
|
| 136 |
+
PRODUCT_NAMES={'pcb1':'PCB 1','pcb2':'PCB 2','pcb3':'PCB 3','pcb4':'PCB 4','capsules':'capsules','cashew':'cashew','candle':'candle','chewinggum':'chewing gum','fryum':'fryum','macaroni1':'Macaroni 1','macaroni2':'Macaroni 2','pipe_fryum':'pipe fryum'}
|
| 137 |
+
|
| 138 |
def evidence_quotes(evidence):
|
| 139 |
quotes={}
|
| 140 |
for source in evidence:
|
|
|
|
| 163 |
score,threshold,margin=values
|
| 164 |
verdict=inspection.get('verdict')
|
| 165 |
if verdict not in ('Good','Anomalous','Uncertain') or margin<0:return None
|
| 166 |
+
category=PRODUCT_NAMES.get(inspection.get('category'),str(inspection.get('category') or 'selected product').replace('_',' '))
|
| 167 |
question=question.lower()
|
| 168 |
relevant=bool(re.search(r'\b(this|that|it|its|result|inspection|product|score|threshold|anomal\w*|normal|good|heatmap|map|confidence|accur\w*|probab\w*)\b',question))
|
| 169 |
if not relevant:return None
|