2026-08-04 17:15:02 +08:00
|
|
|
|
# -*- coding: utf-8 -*-
|
2026-08-04 18:02:00 +08:00
|
|
|
|
"""iAOP-Core · LLM 网关(LLM Gateway)—— 混合 LLM 的安全出站防线与编排。
|
2026-08-04 17:15:02 +08:00
|
|
|
|
|
|
|
|
|
|
对应 PRD 5.4「④ LLM 网关 + RAG」与 EPIC #6:
|
|
|
|
|
|
本地 70B(敏感/核心)+ 云端 API(脱敏/通用)混合,敏感数据**本地闭环**。
|
|
|
|
|
|
|
2026-08-04 18:02:00 +08:00
|
|
|
|
模块组成:
|
|
|
|
|
|
- dlp DLP 敏感数据拦截引擎(Issue #48):出站内容(query / RAG context /
|
|
|
|
|
|
模型输出)发往云端前做敏感规则检查,命中即拦截(目标 100% 拦截),
|
|
|
|
|
|
全量审计。
|
|
|
|
|
|
- router 敏感度路由规则引擎(Issue #43 雏形):敏感度分级路由(local/cloud/
|
|
|
|
|
|
block),模板配置驱动,DLP 拦截即 fail-closed 转 block。
|
2026-08-04 23:15:39 +08:00
|
|
|
|
- prompts Prompt 版本管理(Issue #47 完成交付):semver 版本库、运行时绑定、
|
2026-08-04 18:02:00 +08:00
|
|
|
|
一键回滚、变更审计。
|
2026-08-04 23:15:39 +08:00
|
|
|
|
- hallucination 幻觉/事实性校验中间件(Issue #47 完成交付):引用溯源 +
|
|
|
|
|
|
高利害信度阈值 → 人工确认,与 Prompt 版本库联动(评测按 name@version
|
|
|
|
|
|
分解,配套评测报告脚本 evaluate_hallucination.py)。
|
2026-08-04 18:02:00 +08:00
|
|
|
|
- gateway 混合网关主编排(EPIC #6 主体):路由 → 生成 → 溯源校验 →
|
|
|
|
|
|
DLP 出站防线,端到端闭环。
|
2026-08-04 17:15:02 +08:00
|
|
|
|
|
|
|
|
|
|
测试:`python -m unittest discover -s tests -v`(在 core/llm-gateway 目录下执行)。
|
|
|
|
|
|
"""
|
2026-08-04 23:15:39 +08:00
|
|
|
|
__version__ = "0.3.0"
|
2026-08-04 17:15:02 +08:00
|
|
|
|
|
|
|
|
|
|
from .dlp import (
|
|
|
|
|
|
DLP_DEFAULT_RULES,
|
|
|
|
|
|
DlpEngine,
|
|
|
|
|
|
DlpHit,
|
|
|
|
|
|
DlpResult,
|
|
|
|
|
|
DlpRule,
|
|
|
|
|
|
DlpRuleKind,
|
|
|
|
|
|
)
|
2026-08-04 18:02:00 +08:00
|
|
|
|
from .router import (
|
|
|
|
|
|
RouteDecision,
|
|
|
|
|
|
RouteTarget,
|
|
|
|
|
|
RouterRule,
|
|
|
|
|
|
SensitivityRouter,
|
|
|
|
|
|
)
|
|
|
|
|
|
from .prompts import (
|
|
|
|
|
|
PromptChange,
|
|
|
|
|
|
PromptRegistry,
|
|
|
|
|
|
PromptVersion,
|
|
|
|
|
|
validate_semver,
|
|
|
|
|
|
)
|
|
|
|
|
|
from .hallucination import (
|
|
|
|
|
|
GuardVerdict,
|
|
|
|
|
|
HallucinationGuard,
|
|
|
|
|
|
)
|
|
|
|
|
|
from .gateway import (
|
|
|
|
|
|
CloudBackend,
|
|
|
|
|
|
GatewayResult,
|
|
|
|
|
|
InferenceBackend,
|
|
|
|
|
|
LLMGateway,
|
|
|
|
|
|
LocalBackend,
|
|
|
|
|
|
)
|
2026-08-04 17:15:02 +08:00
|
|
|
|
|
|
|
|
|
|
__all__ = [
|
2026-08-04 18:02:00 +08:00
|
|
|
|
# dlp
|
|
|
|
|
|
"DlpRuleKind", "DlpRule", "DlpHit", "DlpResult", "DlpEngine", "DLP_DEFAULT_RULES",
|
|
|
|
|
|
# router
|
|
|
|
|
|
"RouteTarget", "RouterRule", "RouteDecision", "SensitivityRouter",
|
|
|
|
|
|
# prompts
|
|
|
|
|
|
"PromptVersion", "PromptChange", "PromptRegistry", "validate_semver",
|
|
|
|
|
|
# hallucination
|
|
|
|
|
|
"GuardVerdict", "HallucinationGuard",
|
|
|
|
|
|
# gateway
|
|
|
|
|
|
"InferenceBackend", "LocalBackend", "CloudBackend",
|
|
|
|
|
|
"GatewayResult", "LLMGateway",
|
2026-08-04 17:15:02 +08:00
|
|
|
|
]
|