Spaces:
Running
Running
sync: 167 file da Baida98/AI@a9c5b8e5 (2026-08-22 07:53 UTC)
Browse files- benchmarks/model_watch_adapter.py +2 -2
- memory/sync.py +7 -5
- tests/test_model_catalog_scan.py +48 -0
benchmarks/model_watch_adapter.py
CHANGED
|
@@ -230,7 +230,7 @@ class ObserveOnlyModelsAdapter:
|
|
| 230 |
params: dict[str, str] = {}
|
| 231 |
if profile.auth_mode == "query_key":
|
| 232 |
params["key"] = profile.api_key
|
| 233 |
-
|
| 234 |
headers["Authorization"] = f"Bearer {profile.api_key}"
|
| 235 |
|
| 236 |
owns_client = self._client is None
|
|
@@ -292,7 +292,7 @@ class GeminiModelsAdapter(ObserveOnlyModelsAdapter):
|
|
| 292 |
async def list_models(self, profile: ProviderProfile) -> CatalogResult:
|
| 293 |
url = models_url(profile.base_url)
|
| 294 |
headers = {"Accept": "application/json"}
|
| 295 |
-
params = {"key": profile.api_key}
|
| 296 |
owns_client = self._client is None
|
| 297 |
client = self._client or httpx.AsyncClient(timeout=self.timeout_seconds)
|
| 298 |
try:
|
|
|
|
| 230 |
params: dict[str, str] = {}
|
| 231 |
if profile.auth_mode == "query_key":
|
| 232 |
params["key"] = profile.api_key
|
| 233 |
+
elif profile.auth_mode != "none":
|
| 234 |
headers["Authorization"] = f"Bearer {profile.api_key}"
|
| 235 |
|
| 236 |
owns_client = self._client is None
|
|
|
|
| 292 |
async def list_models(self, profile: ProviderProfile) -> CatalogResult:
|
| 293 |
url = models_url(profile.base_url)
|
| 294 |
headers = {"Accept": "application/json"}
|
| 295 |
+
params = {"key": profile.api_key} if profile.auth_mode != "none" else {}
|
| 296 |
owns_client = self._client is None
|
| 297 |
client = self._client or httpx.AsyncClient(timeout=self.timeout_seconds)
|
| 298 |
try:
|
memory/sync.py
CHANGED
|
@@ -58,6 +58,12 @@ class MemorySyncStatus(BaseModel):
|
|
| 58 |
stats: dict[str, Any]
|
| 59 |
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
# ββ GAP-VAULT-AUTH: autenticazione Bearer βββββββββββββββββββββββββββββββββββββ
|
| 62 |
_SYNC_ADMIN_TOKEN = os.getenv('VAULT_ADMIN_TOKEN', '') # stessa variabile del vault
|
| 63 |
|
|
@@ -218,13 +224,9 @@ def create_memory_sync_router(memory: Any) -> APIRouter:
|
|
| 218 |
"server_time": _now_ms(),
|
| 219 |
}
|
| 220 |
|
| 221 |
-
class _MemoryImportRequest(BaseModel):
|
| 222 |
-
records: list[dict[str, Any]] = Field(default_factory=list)
|
| 223 |
-
overwrite: bool = False
|
| 224 |
-
|
| 225 |
@router.post("/import")
|
| 226 |
async def memory_import(
|
| 227 |
-
req:
|
| 228 |
_auth: None = Depends(_require_sync_auth),
|
| 229 |
) -> dict[str, Any]:
|
| 230 |
"""Importa records nella semantic memory. Richiede Bearer VAULT_ADMIN_TOKEN."""
|
|
|
|
| 58 |
stats: dict[str, Any]
|
| 59 |
|
| 60 |
|
| 61 |
+
class MemoryImportRequest(BaseModel):
|
| 62 |
+
"""Payload di import definito a livello modulo per lo schema OpenAPI."""
|
| 63 |
+
records: list[dict[str, Any]] = Field(default_factory=list)
|
| 64 |
+
overwrite: bool = False
|
| 65 |
+
|
| 66 |
+
|
| 67 |
# ββ GAP-VAULT-AUTH: autenticazione Bearer βββββββββββββββββββββββββββββββββββββ
|
| 68 |
_SYNC_ADMIN_TOKEN = os.getenv('VAULT_ADMIN_TOKEN', '') # stessa variabile del vault
|
| 69 |
|
|
|
|
| 224 |
"server_time": _now_ms(),
|
| 225 |
}
|
| 226 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
@router.post("/import")
|
| 228 |
async def memory_import(
|
| 229 |
+
req: MemoryImportRequest,
|
| 230 |
_auth: None = Depends(_require_sync_auth),
|
| 231 |
) -> dict[str, Any]:
|
| 232 |
"""Importa records nella semantic memory. Richiede Bearer VAULT_ADMIN_TOKEN."""
|
tests/test_model_catalog_scan.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import unittest
|
| 2 |
+
|
| 3 |
+
from scripts.model_catalog_scan import diff_catalogs
|
| 4 |
+
from scripts.model_catalog_notify import build_body
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class ModelCatalogDiffTests(unittest.TestCase):
|
| 8 |
+
def test_reports_exact_added_removed_and_unavailable_models(self):
|
| 9 |
+
previous = {"state": {"groq/A": {"provider": "groq", "profile": "A", "status": "available", "models": ["old-model", "stable-model"]}}}
|
| 10 |
+
current = {"state": {"groq/A": {"provider": "groq", "profile": "A", "status": "available", "models": ["new-model", "stable-model"], "default_model": "old-model", "default_available": False}}}
|
| 11 |
+
result = diff_catalogs(previous, current)
|
| 12 |
+
self.assertEqual(result["added_models"][0]["model"], "new-model")
|
| 13 |
+
self.assertEqual(result["removed_models"][0]["model"], "old-model")
|
| 14 |
+
self.assertEqual(result["unavailable_defaults"][0]["model"], "old-model")
|
| 15 |
+
self.assertTrue(result["has_changes"])
|
| 16 |
+
|
| 17 |
+
def test_reports_provider_errors_with_exact_status(self):
|
| 18 |
+
current = {"state": {"gemini/default": {"provider": "gemini", "profile": "default", "status": "rate_limited", "models": [], "detail": "retry after 60"}}}
|
| 19 |
+
result = diff_catalogs({}, current)
|
| 20 |
+
self.assertEqual(result["provider_errors"][0]["status"], "rate_limited")
|
| 21 |
+
self.assertIn("gemini", result["provider_errors"][0]["provider"])
|
| 22 |
+
|
| 23 |
+
def test_empty_profile_configuration_is_reported(self):
|
| 24 |
+
from scripts.model_catalog_scan import audit_payload
|
| 25 |
+
from benchmarks.model_watch_adapter import ModelWatchConfig, ObserveOnlyModelsAdapter
|
| 26 |
+
from types import SimpleNamespace
|
| 27 |
+
payload = audit_payload(SimpleNamespace(results=(), skipped_rate_limited=()), ObserveOnlyModelsAdapter(config=ModelWatchConfig()), [], {})
|
| 28 |
+
self.assertEqual(payload["profile_count"], 0)
|
| 29 |
+
self.assertTrue(payload["diff"]["has_changes"])
|
| 30 |
+
self.assertEqual(payload["diff"]["provider_errors"][0]["status"], "missing_profiles")
|
| 31 |
+
|
| 32 |
+
def test_notification_contains_exact_names_and_closed_gate(self):
|
| 33 |
+
body = build_body({
|
| 34 |
+
"auto_apply_gate_open": False,
|
| 35 |
+
"diff": {
|
| 36 |
+
"added_models": [{"provider": "groq", "profile": "A", "model": "new-model"}],
|
| 37 |
+
"removed_models": [{"provider": "groq", "profile": "A", "model": "old-model"}],
|
| 38 |
+
"unavailable_defaults": [],
|
| 39 |
+
"provider_errors": [],
|
| 40 |
+
},
|
| 41 |
+
})
|
| 42 |
+
self.assertIn("new-model", body)
|
| 43 |
+
self.assertIn("old-model", body)
|
| 44 |
+
self.assertIn("CHIUSA", body)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
if __name__ == "__main__":
|
| 48 |
+
unittest.main()
|