Spaces:
Sleeping
Sleeping
Pointf5ive commited on
Commit ·
78d0b70
1
Parent(s): f21149b
Expose TOTEM model response diagnostics
Browse files- app.py +41 -0
- src/totem_bridge.py +4 -0
app.py
CHANGED
|
@@ -3122,6 +3122,44 @@ def _apply_llm_dashboard_state(
|
|
| 3122 |
return render_dashboard(state), log_df, _score_summary(log_df), gate_summary
|
| 3123 |
|
| 3124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3125 |
def analyze_manuscript_and_refresh(
|
| 3126 |
file_obj,
|
| 3127 |
author_name: str,
|
|
@@ -3234,6 +3272,9 @@ def run_totem_analysis_from_context(active_path: str, manuscript_context_json: s
|
|
| 3234 |
"actual_tokens": debug.get("actual_tokens"),
|
| 3235 |
"token_audit_path": debug.get("token_audit_path"),
|
| 3236 |
"token_audit_transaction_id": debug.get("token_audit_transaction_id"),
|
|
|
|
|
|
|
|
|
|
| 3237 |
}
|
| 3238 |
return dashboard_html, log_df, summary, json.dumps(debug_log, indent=2)
|
| 3239 |
except Exception as exc:
|
|
|
|
| 3122 |
return render_dashboard(state), log_df, _score_summary(log_df), gate_summary
|
| 3123 |
|
| 3124 |
|
| 3125 |
+
def _bridge_verification_notes(debug: dict, llm_state: dict) -> dict:
|
| 3126 |
+
actual = debug.get("actual_tokens") if isinstance(debug.get("actual_tokens"), dict) else {}
|
| 3127 |
+
usage_reported = actual.get("total_tokens") not in (None, "", 0)
|
| 3128 |
+
warnings: list[str] = []
|
| 3129 |
+
if debug.get("provider") == "fake":
|
| 3130 |
+
warnings.append("Fake audit provider returned these numbers; this should never be enabled on Hugging Face Spaces.")
|
| 3131 |
+
if not usage_reported:
|
| 3132 |
+
warnings.append("Provider did not report token usage, so API completion cannot be cost-audited from usage fields.")
|
| 3133 |
+
if not str(llm_state.get("evidence_summary") or "").strip():
|
| 3134 |
+
warnings.append("Model returned no evidence_summary; score grounding is weak.")
|
| 3135 |
+
|
| 3136 |
+
scores = llm_state.get("scores") if isinstance(llm_state.get("scores"), dict) else {}
|
| 3137 |
+
rounded_scores = [score for score in scores.values() if isinstance(score, int) and score % 5 == 0]
|
| 3138 |
+
if scores and len(rounded_scores) == len(scores):
|
| 3139 |
+
warnings.append("All dashboard scores are multiples of 5; this may indicate coarse model judgement rather than workbook-derived precision.")
|
| 3140 |
+
|
| 3141 |
+
queue = llm_state.get("revision_priority_queue") or []
|
| 3142 |
+
generic_blocks = []
|
| 3143 |
+
if isinstance(queue, list):
|
| 3144 |
+
for item in queue:
|
| 3145 |
+
if not isinstance(item, dict):
|
| 3146 |
+
continue
|
| 3147 |
+
block = str(item.get("block") or "").strip().lower()
|
| 3148 |
+
if block in {"page 1", "page 2", "page 3", "page 4", "page 5", "opening", "middle", "ending"}:
|
| 3149 |
+
generic_blocks.append(item.get("block"))
|
| 3150 |
+
if generic_blocks:
|
| 3151 |
+
warnings.append(f"Revision queue uses generic block labels: {generic_blocks}. Ask for stronger manuscript evidence.")
|
| 3152 |
+
|
| 3153 |
+
return {
|
| 3154 |
+
"api_call_verified": bool(debug.get("provider") and debug.get("provider") != "fake" and debug.get("schema_pass")),
|
| 3155 |
+
"usage_reported": usage_reported,
|
| 3156 |
+
"raw_response_chars": debug.get("raw_response_chars"),
|
| 3157 |
+
"token_audit_transaction_id": debug.get("token_audit_transaction_id"),
|
| 3158 |
+
"token_audit_path": debug.get("token_audit_path"),
|
| 3159 |
+
"warnings": warnings,
|
| 3160 |
+
}
|
| 3161 |
+
|
| 3162 |
+
|
| 3163 |
def analyze_manuscript_and_refresh(
|
| 3164 |
file_obj,
|
| 3165 |
author_name: str,
|
|
|
|
| 3272 |
"actual_tokens": debug.get("actual_tokens"),
|
| 3273 |
"token_audit_path": debug.get("token_audit_path"),
|
| 3274 |
"token_audit_transaction_id": debug.get("token_audit_transaction_id"),
|
| 3275 |
+
"verification": _bridge_verification_notes(debug, llm_state),
|
| 3276 |
+
"validated_payload": debug.get("validated_payload") or llm_state,
|
| 3277 |
+
"raw_model_payload": debug.get("raw_model_payload"),
|
| 3278 |
}
|
| 3279 |
return dashboard_html, log_df, summary, json.dumps(debug_log, indent=2)
|
| 3280 |
except Exception as exc:
|
src/totem_bridge.py
CHANGED
|
@@ -223,6 +223,8 @@ Use the workbook matrix as scoring authority and manuscript text as evidence.
|
|
| 223 |
"schema_pass": True,
|
| 224 |
"token_audit_path": audit_path,
|
| 225 |
"token_audit_transaction_id": transaction_id,
|
|
|
|
|
|
|
| 226 |
}
|
| 227 |
|
| 228 |
provider_config = _select_llm_provider()
|
|
@@ -350,6 +352,8 @@ Use the workbook matrix as scoring authority and manuscript text as evidence.
|
|
| 350 |
"actual_tokens": actual_tokens,
|
| 351 |
"token_audit_path": audit_path,
|
| 352 |
"token_audit_transaction_id": transaction_id,
|
|
|
|
|
|
|
| 353 |
}
|
| 354 |
return validated, debug
|
| 355 |
|
|
|
|
| 223 |
"schema_pass": True,
|
| 224 |
"token_audit_path": audit_path,
|
| 225 |
"token_audit_transaction_id": transaction_id,
|
| 226 |
+
"raw_model_payload": raw_payload,
|
| 227 |
+
"validated_payload": validated,
|
| 228 |
}
|
| 229 |
|
| 230 |
provider_config = _select_llm_provider()
|
|
|
|
| 352 |
"actual_tokens": actual_tokens,
|
| 353 |
"token_audit_path": audit_path,
|
| 354 |
"token_audit_transaction_id": transaction_id,
|
| 355 |
+
"raw_model_payload": parsed,
|
| 356 |
+
"validated_payload": validated,
|
| 357 |
}
|
| 358 |
return validated, debug
|
| 359 |
|