Spaces:
Paused
Paused
Preserve reference provenance and honest uncertainty in both chat APIs
Browse filesFiles changed (2)
- app.py+14-5
- security_knowledge.py+1-1
2242 unmodified lines224322442245224622472248224922502251225222532254225522562257225822592260226122622242 unmodified linesllm_result = await run_in_threadpool(transformer_loader.security_chat, enriched_message, 600)if llm_result.get("response") and not llm_result.get("error"):text = llm_result["response"]risk_level = stated_risk(text) or "low"risk_score = {"critical": 85.0, "high": 70.0, "medium": 45.0, "low": 20.0}[risk_level]# Override with ML scan if strongerif detected_risk_score > 0:ml_score_100 = round(detected_risk_score * 100, 1)if ml_score_100 > risk_score:risk_score = ml_score_100risk_level = detected_risk_levelreturn {"response": text,"confidence": 0.72,"risk_level": risk_level,"risk_score": risk_score,"model_used": llm_result.get("model_id", LOCAL_LLM_REPO),"session_id": session_id,"sources": sources,"timestamp": datetime.utcnow().isoformat(),2242 unmodified lines224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712242 unmodified linesllm_result = await run_in_threadpool(transformer_loader.security_chat, enriched_message, 600)if llm_result.get("response") and not llm_result.get("error"):text = llm_result["response"]risk_level = stated_risk(text) or "unknown"risk_score = {"critical": 85.0, "high": 70.0, "medium": 45.0, "low": 20.0}.get(risk_level)# Override with ML scan if strongerif detected_risk_score > 0:ml_score_100 = round(detected_risk_score * 100, 1)if risk_score is None or ml_score_100 > risk_score:risk_score = ml_score_100risk_level = detected_risk_levelreturn {"response": text,"confidence": None,"confidence_source": "not_calibrated","risk_level": risk_level,"risk_score": risk_score,"model_used": llm_result.get("model_used") or llm_result.get("model_id", LOCAL_LLM_REPO),"model_id": llm_result.get("model_id", LOCAL_LLM_REPO),"model": llm_result.get("model"),"source": llm_result.get("source"),"grounding": llm_result.get("grounding"),"references": llm_result.get("references", []),"model_generated": llm_result.get("model_generated", True),"answered": True,"result_kind": "reasoning_text","session_id": session_id,"sources": sources,"timestamp": datetime.utcnow().isoformat(),
95 unmodified lines9697989910010110295 unmodified linesdef question_text(user):# Match the person's current question, never remembered scans or conversation.for marker in ("\n\nMy question: ", "\n\nQUESTION: ", "\n\nUser: "):if marker in user:return user.rsplit(marker, 1)[1][:1200]return user.split("\n\nCONTEXT:", 1)[0][:1200]95 unmodified lines9697989910010110295 unmodified linesdef question_text(user):# Match the person's current question, never remembered scans or conversation.for marker in ("\n\nMy question: ", "\n\nQUESTION: ", "[USER MESSAGE]\n", "\n\nUser: "):if marker in user:return user.rsplit(marker, 1)[1][:1200]return user.split("\n\nCONTEXT:", 1)[0][:1200]
app.py+14-5
security_knowledge.py+1-1