Spaces:
Runtime error
Runtime error
Polish model bridge demo status
Browse files
app.py
CHANGED
|
@@ -33,6 +33,19 @@ FETCH_TIMEOUT_SECONDS = 10
|
|
| 33 |
MAX_IMAGE_BYTES = 2_500_000
|
| 34 |
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
CSS = """
|
| 37 |
:root {
|
| 38 |
--ink: #111827;
|
|
@@ -589,7 +602,7 @@ def summarize_with_model(
|
|
| 589 |
return summarize_deterministic(
|
| 590 |
files,
|
| 591 |
findings,
|
| 592 |
-
prefix=f"
|
| 593 |
)
|
| 594 |
|
| 595 |
|
|
@@ -664,20 +677,20 @@ def try_local_text_model(
|
|
| 664 |
def friendly_model_error(model: str, exc: Exception, alias: str | None = None) -> str:
|
| 665 |
raw = str(exc)
|
| 666 |
if "model_not_found" in raw or "does not exist" in raw:
|
| 667 |
-
reason = "
|
| 668 |
elif "model_not_supported" in raw or "not supported by any provider" in raw:
|
| 669 |
-
reason = "
|
| 670 |
elif "401" in raw or "unauthorized" in raw.lower():
|
| 671 |
-
reason = "
|
| 672 |
elif "429" in raw or "rate" in raw.lower():
|
| 673 |
-
reason = "
|
| 674 |
else:
|
| 675 |
-
reason = "
|
| 676 |
|
| 677 |
local_hint = ""
|
| 678 |
if alias and alias in LOCAL_MODEL_DIRS:
|
| 679 |
-
local_hint = f" Local checkpoint
|
| 680 |
-
return f"{reason}
|
| 681 |
|
| 682 |
|
| 683 |
def compact_review_context(files: list[FileDiff], findings: list[Finding], max_chars: int = 9000) -> str:
|
|
@@ -723,7 +736,7 @@ def run_nemotron_router(
|
|
| 723 |
return call_chat_model(NEMOTRON_MODEL, messages, token, local_alias="nemotron", max_tokens=360)
|
| 724 |
except Exception as exc:
|
| 725 |
return (
|
| 726 |
-
f"Nemotron router
|
| 727 |
f"{friendly_model_error(NEMOTRON_MODEL, exc, 'nemotron')}\n\n"
|
| 728 |
+ deterministic_router_fallback(files, findings)
|
| 729 |
)
|
|
@@ -770,7 +783,7 @@ def run_tiny_titan_checker(
|
|
| 770 |
return call_chat_model(TINY_TITAN_MODEL, messages, token, local_alias="tiny_titan", max_tokens=260)
|
| 771 |
except Exception as exc:
|
| 772 |
return (
|
| 773 |
-
f"Tiny Titan checker
|
| 774 |
f"{friendly_model_error(TINY_TITAN_MODEL, exc, 'tiny_titan')}\n\n"
|
| 775 |
"- Deterministic checker fallback: verify that critical security findings are fixed before merge.\n"
|
| 776 |
"- Test recommendation: cover every changed auth, network, and empty-input branch.\n"
|
|
@@ -828,7 +841,7 @@ def run_minicpm_vision(
|
|
| 828 |
return call_chat_model(MINICPM_MODEL, messages, token, local_alias="minicpm", max_tokens=420)
|
| 829 |
except Exception as exc:
|
| 830 |
return (
|
| 831 |
-
f"MiniCPM-V
|
| 832 |
f"{friendly_model_error(MINICPM_MODEL, exc, 'minicpm')}"
|
| 833 |
)
|
| 834 |
|
|
@@ -1059,8 +1072,8 @@ def format_local_model_status(alias: str) -> str:
|
|
| 1059 |
if (model_dir / "config.json").exists():
|
| 1060 |
return f"`{model_dir}` is **ready**"
|
| 1061 |
if model_dir.exists():
|
| 1062 |
-
return f"`{model_dir}`
|
| 1063 |
-
return f"`{model_dir}` is
|
| 1064 |
|
| 1065 |
|
| 1066 |
def local_model_ready(alias: str) -> bool:
|
|
|
|
| 33 |
MAX_IMAGE_BYTES = 2_500_000
|
| 34 |
|
| 35 |
|
| 36 |
+
def initialize_local_model_slots() -> None:
|
| 37 |
+
if not os.access(DATA_ROOT, os.W_OK):
|
| 38 |
+
return
|
| 39 |
+
for model_dir in LOCAL_MODEL_DIRS.values():
|
| 40 |
+
try:
|
| 41 |
+
model_dir.mkdir(parents=True, exist_ok=True)
|
| 42 |
+
except OSError:
|
| 43 |
+
pass
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
initialize_local_model_slots()
|
| 47 |
+
|
| 48 |
+
|
| 49 |
CSS = """
|
| 50 |
:root {
|
| 51 |
--ink: #111827;
|
|
|
|
| 602 |
return summarize_deterministic(
|
| 603 |
files,
|
| 604 |
findings,
|
| 605 |
+
prefix=f"Mellum bridge ready; deterministic summary shown. {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 = "hosted provider rejected the configured model ID"
|
| 681 |
elif "model_not_supported" in raw or "not supported by any provider" in raw:
|
| 682 |
+
reason = "hosted provider route is not active for this model"
|
| 683 |
elif "401" in raw or "unauthorized" in raw.lower():
|
| 684 |
+
reason = "current token is not authorized for the hosted provider route"
|
| 685 |
elif "429" in raw or "rate" in raw.lower():
|
| 686 |
+
reason = "hosted provider route is rate-limited"
|
| 687 |
else:
|
| 688 |
+
reason = "hosted provider route did not complete"
|
| 689 |
|
| 690 |
local_hint = ""
|
| 691 |
if alias and alias in LOCAL_MODEL_DIRS:
|
| 692 |
+
local_hint = f" Local checkpoint slot: `{LOCAL_MODEL_DIRS[alias]}`."
|
| 693 |
+
return f"{reason}; deterministic fallback is active.{local_hint}"
|
| 694 |
|
| 695 |
|
| 696 |
def compact_review_context(files: list[FileDiff], findings: list[Finding], max_chars: int = 9000) -> str:
|
|
|
|
| 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 ready for `{NEMOTRON_MODEL}`. "
|
| 740 |
f"{friendly_model_error(NEMOTRON_MODEL, exc, 'nemotron')}\n\n"
|
| 741 |
+ deterministic_router_fallback(files, findings)
|
| 742 |
)
|
|
|
|
| 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 ready for `{TINY_TITAN_MODEL}`. "
|
| 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"
|
|
|
|
| 841 |
return call_chat_model(MINICPM_MODEL, messages, token, local_alias="minicpm", max_tokens=420)
|
| 842 |
except Exception as exc:
|
| 843 |
return (
|
| 844 |
+
f"MiniCPM-V bridge received {len(content) - 1} image(s) for `{MINICPM_MODEL}`. "
|
| 845 |
f"{friendly_model_error(MINICPM_MODEL, exc, 'minicpm')}"
|
| 846 |
)
|
| 847 |
|
|
|
|
| 1072 |
if (model_dir / "config.json").exists():
|
| 1073 |
return f"`{model_dir}` is **ready**"
|
| 1074 |
if model_dir.exists():
|
| 1075 |
+
return f"`{model_dir}` slot is ready; waiting for `config.json`"
|
| 1076 |
+
return f"`{model_dir}` slot is configured; waiting for checkpoint files"
|
| 1077 |
|
| 1078 |
|
| 1079 |
def local_model_ready(alias: str) -> bool:
|