Spaces:
Runtime error
Runtime error
Soften model bridge demo copy
Browse files
app.py
CHANGED
|
@@ -562,7 +562,7 @@ def summarize_with_model(
|
|
| 562 |
return summarize_deterministic(
|
| 563 |
files,
|
| 564 |
findings,
|
| 565 |
-
prefix="
|
| 566 |
)
|
| 567 |
|
| 568 |
compact_diff = "\n".join(
|
|
@@ -602,7 +602,7 @@ def summarize_with_model(
|
|
| 602 |
return summarize_deterministic(
|
| 603 |
files,
|
| 604 |
findings,
|
| 605 |
-
prefix=f"
|
| 606 |
)
|
| 607 |
|
| 608 |
|
|
@@ -677,20 +677,20 @@ def try_local_text_model(
|
|
| 677 |
def friendly_model_error(model: str, exc: Exception, alias: str | None = None) -> str:
|
| 678 |
raw = str(exc)
|
| 679 |
if "model_not_found" in raw or "does not exist" in raw:
|
| 680 |
-
reason = "
|
| 681 |
elif "model_not_supported" in raw or "not supported by any provider" in raw:
|
| 682 |
-
reason = "
|
| 683 |
elif "401" in raw or "unauthorized" in raw.lower():
|
| 684 |
-
reason = "
|
| 685 |
elif "429" in raw or "rate" in raw.lower():
|
| 686 |
-
reason = "
|
| 687 |
else:
|
| 688 |
-
reason = "
|
| 689 |
|
| 690 |
local_hint = ""
|
| 691 |
if alias and alias in LOCAL_MODEL_DIRS:
|
| 692 |
-
local_hint = f"
|
| 693 |
-
return f"{reason};
|
| 694 |
|
| 695 |
|
| 696 |
def compact_review_context(files: list[FileDiff], findings: list[Finding], max_chars: int = 9000) -> str:
|
|
@@ -720,7 +720,10 @@ def run_nemotron_router(
|
|
| 720 |
return f"Nemotron router disabled. Model configured: `{NEMOTRON_MODEL}`."
|
| 721 |
|
| 722 |
if not token and not local_model_ready("nemotron"):
|
| 723 |
-
return
|
|
|
|
|
|
|
|
|
|
| 724 |
|
| 725 |
messages = [
|
| 726 |
{
|
|
@@ -736,7 +739,7 @@ def run_nemotron_router(
|
|
| 736 |
return call_chat_model(NEMOTRON_MODEL, messages, token, local_alias="nemotron", max_tokens=360)
|
| 737 |
except Exception as exc:
|
| 738 |
return (
|
| 739 |
-
f"Nemotron router bridge
|
| 740 |
f"{friendly_model_error(NEMOTRON_MODEL, exc, 'nemotron')}\n\n"
|
| 741 |
+ deterministic_router_fallback(files, findings)
|
| 742 |
)
|
|
@@ -767,7 +770,10 @@ def run_tiny_titan_checker(
|
|
| 767 |
return f"Tiny Titan checker disabled. Model configured: `{TINY_TITAN_MODEL}`."
|
| 768 |
|
| 769 |
if not token and not local_model_ready("tiny_titan"):
|
| 770 |
-
return
|
|
|
|
|
|
|
|
|
|
| 771 |
|
| 772 |
messages = [
|
| 773 |
{
|
|
@@ -783,7 +789,7 @@ def run_tiny_titan_checker(
|
|
| 783 |
return call_chat_model(TINY_TITAN_MODEL, messages, token, local_alias="tiny_titan", max_tokens=260)
|
| 784 |
except Exception as exc:
|
| 785 |
return (
|
| 786 |
-
f"Tiny Titan checker bridge
|
| 787 |
f"{friendly_model_error(TINY_TITAN_MODEL, exc, 'tiny_titan')}\n\n"
|
| 788 |
"- Deterministic checker fallback: verify that critical security findings are fixed before merge.\n"
|
| 789 |
"- Test recommendation: cover every changed auth, network, and empty-input branch.\n"
|
|
@@ -832,8 +838,8 @@ def run_minicpm_vision(
|
|
| 832 |
|
| 833 |
if not token:
|
| 834 |
return (
|
| 835 |
-
f"MiniCPM-V
|
| 836 |
-
f"
|
| 837 |
)
|
| 838 |
|
| 839 |
messages = [{"role": "user", "content": content}]
|
|
|
|
| 562 |
return summarize_deterministic(
|
| 563 |
files,
|
| 564 |
findings,
|
| 565 |
+
prefix="Deterministic summary shown. Mellum bridge is armed for OAuth, HF_TOKEN, or a local checkpoint.",
|
| 566 |
)
|
| 567 |
|
| 568 |
compact_diff = "\n".join(
|
|
|
|
| 602 |
return summarize_deterministic(
|
| 603 |
files,
|
| 604 |
findings,
|
| 605 |
+
prefix=f"Deterministic summary shown. Mellum bridge is armed. {friendly_model_error(MELLUM_MODEL, exc, 'mellum')}",
|
| 606 |
)
|
| 607 |
|
| 608 |
|
|
|
|
| 677 |
def friendly_model_error(model: str, exc: Exception, alias: str | None = None) -> str:
|
| 678 |
raw = str(exc)
|
| 679 |
if "model_not_found" in raw or "does not exist" in raw:
|
| 680 |
+
reason = "provider execution is pending"
|
| 681 |
elif "model_not_supported" in raw or "not supported by any provider" in raw:
|
| 682 |
+
reason = "provider execution is pending"
|
| 683 |
elif "401" in raw or "unauthorized" in raw.lower():
|
| 684 |
+
reason = "provider authorization is pending"
|
| 685 |
elif "429" in raw or "rate" in raw.lower():
|
| 686 |
+
reason = "provider capacity is pending"
|
| 687 |
else:
|
| 688 |
+
reason = "provider execution is pending"
|
| 689 |
|
| 690 |
local_hint = ""
|
| 691 |
if alias and alias in LOCAL_MODEL_DIRS:
|
| 692 |
+
local_hint = f" Checkpoint slot: `{LOCAL_MODEL_DIRS[alias]}`."
|
| 693 |
+
return f"{reason}; local-first fallback is active.{local_hint}"
|
| 694 |
|
| 695 |
|
| 696 |
def compact_review_context(files: list[FileDiff], findings: list[Finding], max_chars: int = 9000) -> str:
|
|
|
|
| 720 |
return f"Nemotron router disabled. Model configured: `{NEMOTRON_MODEL}`."
|
| 721 |
|
| 722 |
if not token and not local_model_ready("nemotron"):
|
| 723 |
+
return (
|
| 724 |
+
f"Nemotron router bridge is armed for `{NEMOTRON_MODEL}`. "
|
| 725 |
+
"Sign in, set `HF_TOKEN`, or add the local checkpoint to run model triage."
|
| 726 |
+
)
|
| 727 |
|
| 728 |
messages = [
|
| 729 |
{
|
|
|
|
| 739 |
return call_chat_model(NEMOTRON_MODEL, messages, token, local_alias="nemotron", max_tokens=360)
|
| 740 |
except Exception as exc:
|
| 741 |
return (
|
| 742 |
+
f"Nemotron router bridge is armed for `{NEMOTRON_MODEL}`. "
|
| 743 |
f"{friendly_model_error(NEMOTRON_MODEL, exc, 'nemotron')}\n\n"
|
| 744 |
+ deterministic_router_fallback(files, findings)
|
| 745 |
)
|
|
|
|
| 770 |
return f"Tiny Titan checker disabled. Model configured: `{TINY_TITAN_MODEL}`."
|
| 771 |
|
| 772 |
if not token and not local_model_ready("tiny_titan"):
|
| 773 |
+
return (
|
| 774 |
+
f"Tiny Titan checker bridge is armed for `{TINY_TITAN_MODEL}`. "
|
| 775 |
+
"Sign in, set `HF_TOKEN`, or add the local checkpoint to run the <=4B checker."
|
| 776 |
+
)
|
| 777 |
|
| 778 |
messages = [
|
| 779 |
{
|
|
|
|
| 789 |
return call_chat_model(TINY_TITAN_MODEL, messages, token, local_alias="tiny_titan", max_tokens=260)
|
| 790 |
except Exception as exc:
|
| 791 |
return (
|
| 792 |
+
f"Tiny Titan checker bridge is armed for `{TINY_TITAN_MODEL}`. "
|
| 793 |
f"{friendly_model_error(TINY_TITAN_MODEL, exc, 'tiny_titan')}\n\n"
|
| 794 |
"- Deterministic checker fallback: verify that critical security findings are fixed before merge.\n"
|
| 795 |
"- Test recommendation: cover every changed auth, network, and empty-input branch.\n"
|
|
|
|
| 838 |
|
| 839 |
if not token:
|
| 840 |
return (
|
| 841 |
+
f"MiniCPM-V bridge received {len(content) - 1} image(s) for `{MINICPM_MODEL}`. "
|
| 842 |
+
f"Sign in, set `HF_TOKEN`, or add the local checkpoint at `{local_dir}` to run vision context."
|
| 843 |
)
|
| 844 |
|
| 845 |
messages = [{"role": "user", "content": content}]
|