Spaces:
Paused
Paused
Constrain reference-covered explanations to reviewed source sentences
Browse filesFiles changed (2)
- app.py+1-1
- security_knowledge.py+20-5
2066 unmodified lines20672068206920702071207220732066 unmodified linesContext-grounded security assistant that:1. Accepts a live context blob (telemetry, scan history, IOCs) andgrounds every answer in it (RAG-lite over the current request — nopersistent vector store, which requires paid GPU on free tier).2. Translates raw ML signals / IOCs into plain human language when theuser includes raw data and asks for an explanation.3. Uses the open-source model running in this Space, or the ML-powered2066 unmodified lines20672068206920702071207220732066 unmodified linesContext-grounded security assistant that:1. Accepts a live context blob (telemetry, scan history, IOCs) andgrounds every answer in it (RAG-lite over the current request — nopersistent vector store; memory is owned by the caller).2. Translates raw ML signals / IOCs into plain human language when theuser includes raw data and asks for an explanation.3. Uses the open-source model running in this Space, or the ML-powered
4 unmodified lines567891011103 unmodified lines1151161171181191201211221 unmodified line1241251261271281291301314 unmodified lines"""import reREVISION = "2026-10-23.1"POLICY = ("Detector policy: the supervised phishing, malware-URL and web-attack classifiers ""flag rescaled scores >= 0.50. The anomaly model measures unusualness, not proof ""of maliciousness. Name it separately; never say all detectors are below threshold "103 unmodified linessystem += "\n\n" + POLICYif refs:system += ("\n\nVERIFIED REFERENCE CONTEXT (editorially reviewed; use for factual claims). ""Answer the question from these facts. Do not invent versions, causes or remedies. ""If the reference cannot answer a detail, say it is not established here.\n")system += "\n".join(f"[{r['id']}] {r['facts']}" for r in refs)return system, refs1 unmodified linedef reference_fallback_needed(text, refs):if not refs:return Falsereturn any(not all(re.search(p, text, re.I) for p in r["required"])or any(re.search(p, text, re.I) for p in r["forbidden"]) for r in refs)def finish_grounded_answer(text, refs, analyst=False):4 unmodified lines567891011103 unmodified lines1151161171181191201211221231241 unmodified line1261271281291301311321331341351361371381391401411421431441451464 unmodified lines"""import reREVISION = "2026-10-23.2"POLICY = ("Detector policy: the supervised phishing, malware-URL and web-attack classifiers ""flag rescaled scores >= 0.50. The anomaly model measures unusualness, not proof ""of maliciousness. Name it separately; never say all detectors are below threshold "103 unmodified linessystem += "\n\n" + POLICYif refs:system += ("\n\nVERIFIED REFERENCE CONTEXT (editorially reviewed; use for factual claims). ""Answer using only complete sentences copied from the facts below. ""Select the relevant sentences; you may omit others and format them as bullets. ""Do not paraphrase, add yes/no introductions, risk labels, causes, versions or remedies. ""If a requested detail is absent, give only the relevant established facts.\n")system += "\n".join(f"[{r['id']}] {r['facts']}" for r in refs)return system, refs1 unmodified linedef reference_fallback_needed(text, refs):if not refs:return Falseif any(not all(re.search(p, text, re.I) for p in r["required"])or any(re.search(p, text, re.I) for p in r["forbidden"]) for r in refs):return True# Literal sentence support is conservative: a sensible paraphrase may also# use the explicit reference response. Keyword presence cannot establish# that a newly generated mechanism or recommendation is supported.normalize = lambda s: " ".join(re.findall(r"[\w]+", s.lower()))sentences = lambda s: re.split(r"(?<=[.!?])\s+|\n+", s.strip())allowed = {normalize(s) for r in refs for s in sentences(r["facts"])}for sentence in sentences(text):sentence = re.sub(r"^\s*(?:[-*•]\s+|\d+\.\s+)", "", sentence)sentence = sentence.replace("**", "").strip()if normalize(sentence) and normalize(sentence) not in allowed:return Truereturn Falsedef finish_grounded_answer(text, refs, analyst=False):
app.py+1-1
security_knowledge.py+20-5