feat: 多专业小模型+路由模型系统 MVP(mock 全链路 + FastAPI 网关 + 论文调研)

This commit is contained in:
tzt
2026-08-12 10:40:04 +08:00
commit 1e51167ea5
50 changed files with 49382 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
from router_system.cache import RouterCache
def test_exact_hit():
c = RouterCache()
result = {"response": "hello", "domain": "general"}
assert c.get("query") is None
c.put("query", result)
level, got = c.get("query")
assert level == "exact"
assert got["response"] == "hello"
def test_semantic_hit():
c = RouterCache(semantic_enabled=True, similarity_threshold=0.5)
c.put("?python?????", {"response": "code", "domain": "code"})
# ?????????? L2
hit = c.get("?python????????")
assert hit is not None
assert hit[0] == "semantic"
def test_promote_to_exact():
c = RouterCache(promote_frequency=3)
result = {"response": "x", "domain": "general"}
c.put("query", result)
# ?????? 3 ? ? ???????
for _ in range(3):
hit = c.get("query")
assert hit is not None
assert c.stats()["exact_size"] == 1
def test_stats():
c = RouterCache()
c.put("q", {"response": "r"})
c.get("q")
c.get("q")
c.get("miss")
s = c.stats()
assert s["exact_hits"] == 2
assert s["misses"] == 1