已合并
chore(intelliRouter): merge IntelliRouter module into develop #358
yutaoJustinBieber1223创建于 24 天前
chore(intelliRouter): merge IntelliRouter module into develop #358
已合并
yutaoJustinBieber1223创建于 24 天前
共 230 个文件变更+23629-6
MREADME.md+13-3
@@ -4,9 +4,9 @@ English | [简体中文](./README_zh.md)
4 4 
5## Introduction5## Introduction
6 6 
7-**Agent Protocol** provides protocol SDKs and a service registry for agent interoperability in the [openJiuwen](https://github.com/openJiuwen-ai) ecosystem. It helps developers connect agents to tools, communicate with remote agents, discover available services, and enforce verifiable user authorization before sensitive operations.7+**Agent Protocol** provides protocol SDKs and a service registry for agent interoperability in the [openJiuwen](https://github.com/openJiuwen-ai) ecosystem. It helps developers connect agents to tools, communicate with remote agents, discover available services, route requests across LLM deployments, and enforce verifiable user authorization before sensitive operations.
8 8 
9-An agent application needs more than a model and task logic: it needs a way to access external capabilities, locate suitable collaborators, exchange messages and task results, and constrain what it can execute on a user's behalf. This repository addresses these needs through four complementary components: **MCP C++ SDK**, **A2A C++ SDK**, **A2X Registry**, and **A4P Python SDK**. Developers can choose individual components or combine them according to their integration needs.9+An agent application needs more than a model and task logic: it needs a way to access external capabilities, locate suitable collaborators, exchange messages and task results, and constrain what it can execute on a user's behalf. This repository addresses these needs through five complementary components: **MCP C++ SDK**, **A2A C++ SDK**, **A2X Registry**, **A4P Python SDK**, and **IntelliRouter**. Developers can choose individual components or combine them according to their integration needs.
10 10 
11## Core Capabilities11## Core Capabilities
12 12 
@@ -30,6 +30,12 @@ The Agentic Authentication, Authorization, and Audit Protocol (A4P) Python SDK s
30 30 
31The SDK provides Ed25519-signed authorization objects, Ed25519 and WebAuthn/passkey user-signature methods, parameter-scope checks, and execution limits with SQLite-backed atomic consumption. Its two-stage prepare/complete interfaces support asynchronous user confirmation and integration with existing tool services.31The SDK provides Ed25519-signed authorization objects, Ed25519 and WebAuthn/passkey user-signature methods, parameter-scope checks, and execution limits with SQLite-backed atomic consumption. Its two-stage prepare/complete interfaces support asynchronous user confirmation and integration with existing tool services.
32 32 
33+### Intelligent LLM routing with IntelliRouter
34+ 
35+IntelliRouter is a lightweight **LLM proxy SDK** that maps a single model name to multiple deployment endpoints and routes each request intelligently. It pools deployments across providers — OpenAI, Anthropic, Bedrock, DeepSeek, Gemini, and SiliconFlow, plus any OpenAI-compatible endpoint — and selects among them with pluggable strategies: SimpleShuffle, LowestLatency, TagBased, TokenAware, RateLimitAware, Adaptive, OrderedFailover, and TagFiltered.
36+ 
37+The router tracks per-deployment health and quota state (latency, failure counts, TPM/RPM usage, cooling windows), runs background health checks, retries failed requests with automatic failover, and exposes observability through an event bus, Prometheus metrics, a web dashboard, and logging hooks. Streaming responses and JSON/Markdown output parsers are also included.
38+ 
33## Choosing a Component39## Choosing a Component
34 40 
35Each component addresses a different integration need and can be used independently, without adopting the others.41Each component addresses a different integration need and can be used independently, without adopting the others.
@@ -40,6 +46,7 @@ Each component addresses a different integration need and can be used independen
40| Delegate work to another agent | A2A C++ SDK | Exchange messages, track tasks, and receive streaming results. |46| Delegate work to another agent | A2A C++ SDK | Exchange messages, track tasks, and receive streaming results. |
41| Find an appropriate service or collaborator | A2X Registry | Register service metadata, discover capabilities, and coordinate availability. |47| Find an appropriate service or collaborator | A2X Registry | Register service metadata, discover capabilities, and coordinate availability. |
42| Execute within user-approved boundaries | A4P Python SDK | Obtain verifiable authorization and validate its scope before a protected operation. |48| Execute within user-approved boundaries | A4P Python SDK | Obtain verifiable authorization and validate its scope before a protected operation. |
49+| Route requests across multiple LLM deployments | IntelliRouter | Pool model endpoints, pick the best deployment per request, and fail over automatically. |
43 50 
44## Repository Layout51## Repository Layout
45 52 
@@ -48,7 +55,8 @@ agent-protocol/
48├── MCP/cpp-sdk/ # MCP C++ client/server SDK and examples55├── MCP/cpp-sdk/ # MCP C++ client/server SDK and examples
49├── A2A/cpp-sdk/ # A2A C++ client/server SDK and examples56├── A2A/cpp-sdk/ # A2A C++ client/server SDK and examples
50├── AgentRegistry/ # A2X registry, Python client, web UI, and documentation57├── AgentRegistry/ # A2X registry, Python client, web UI, and documentation
51-└── A4P-python-sdk/ # A4P Python SDK, protocol documentation, and examples58+├── A4P-python-sdk/ # A4P Python SDK, protocol documentation, and examples
59+└── intelli_router/ # IntelliRouter LLM proxy SDK, tests, and examples
52```60```
53 61 
54## Getting Started62## Getting Started
@@ -66,6 +74,7 @@ cd agent-protocol
66| [A2A C++ SDK](./A2A/cpp-sdk/README.md) | C++17, CMake ≥ 3.15, and system dependencies; Linux is the primary validation platform | Build with examples enabled, then run the Hello World and streaming examples. |74| [A2A C++ SDK](./A2A/cpp-sdk/README.md) | C++17, CMake ≥ 3.15, and system dependencies; Linux is the primary validation platform | Build with examples enabled, then run the Hello World and streaming examples. |
67| [A2X Registry](./AgentRegistry/README.md) | Python ≥ 3.10; LLM configuration for A2X search | Install the registry, start the service, and register/query services through HTTP APIs or the UI. |75| [A2X Registry](./AgentRegistry/README.md) | Python ≥ 3.10; LLM configuration for A2X search | Install the registry, start the service, and register/query services through HTTP APIs or the UI. |
68| [A4P Python SDK](./A4P-python-sdk/README.md) | Python ≥ 3.10 and uv | Install dependencies and run the non-interactive Ed25519 authorization example. |76| [A4P Python SDK](./A4P-python-sdk/README.md) | Python ≥ 3.10 and uv | Install dependencies and run the non-interactive Ed25519 authorization example. |
77+| [IntelliRouter](./intelli_router/README.md) | Python ≥ 3.9 | Install the SDK, run the unit tests, then try the end-to-end and observability examples. |
69 78 
70The components are built and installed separately. See each guide for complete dependency requirements and platform-specific instructions.79The components are built and installed separately. See each guide for complete dependency requirements and platform-specific instructions.
71 80 
@@ -75,6 +84,7 @@ The components are built and installed separately. See each guide for complete d
75- **A2A:** [API reference](./A2A/cpp-sdk/docs/api/README.md) · [Dependencies](./A2A/cpp-sdk/docs/dependencies.md) · [Error handling](./A2A/cpp-sdk/docs/errors.md)84- **A2A:** [API reference](./A2A/cpp-sdk/docs/api/README.md) · [Dependencies](./A2A/cpp-sdk/docs/dependencies.md) · [Error handling](./A2A/cpp-sdk/docs/errors.md)
76- **A2X:** [Registry guide](./AgentRegistry/README.md) · [Python client](./AgentRegistry/client/README.md) · [Agent Team deployment](./AgentRegistry/README_forAgentTeam.md)85- **A2X:** [Registry guide](./AgentRegistry/README.md) · [Python client](./AgentRegistry/client/README.md) · [Agent Team deployment](./AgentRegistry/README_forAgentTeam.md)
77- **A4P:** [Protocol](./A4P-python-sdk/A4P_PROTOCOL.md) · [SDK design](./A4P-python-sdk/A4P_SDK_DESIGN.md) · [MCP integration example](./A4P-python-sdk/examples/note_mcp_a4p/README.md)86- **A4P:** [Protocol](./A4P-python-sdk/A4P_PROTOCOL.md) · [SDK design](./A4P-python-sdk/A4P_SDK_DESIGN.md) · [MCP integration example](./A4P-python-sdk/examples/note_mcp_a4p/README.md)
87+- **IntelliRouter:** [SDK guide](./intelli_router/README.md) · [API reference](./intelli_router/API.md) · [Examples](./intelli_router/examples/)
78 88 
79## Contributing89## Contributing
80 90 
@@ -4,9 +4,9 @@
4 4 
5## 简介5## 简介
6 6 
7-**Agent Protocol** 是 [openJiuwen](https://github.com/openJiuwen-ai) 生态中面向智能体互操作的协议 SDK 与服务注册中心集合,帮助开发者连接智能体与工具、与远端智能体通信、发现可用服务,并在执行敏感操作前落实可验证的用户授权。7+**Agent Protocol** 是 [openJiuwen](https://github.com/openJiuwen-ai) 生态中面向智能体互操作的协议 SDK 与服务注册中心集合,帮助开发者连接智能体与工具、与远端智能体通信、发现可用服务,在多个 LLM 部署间智能路由请求,并在执行敏感操作前落实可验证的用户授权。
8 8 
9-智能体应用除了模型和任务逻辑,还需要解决外部能力接入、协作对象发现、消息与任务结果交换,以及代理用户执行操作时的权限边界等问题。本仓库通过 **MCP C++ SDK**、**A2A C++ SDK**、**A2X Registry** 和 **A4P Python SDK** 四个互补组件提供支持。开发者可以按需独立使用,也可以结合具体业务进行组合集成。9+智能体应用除了模型和任务逻辑,还需要解决外部能力接入、协作对象发现、消息与任务结果交换,以及代理用户执行操作时的权限边界等问题。本仓库通过 **MCP C++ SDK**、**A2A C++ SDK**、**A2X Registry**、**A4P Python SDK** 和 **IntelliRouter** 五个互补组件提供支持。开发者可以按需独立使用,也可以结合具体业务进行组合集成。
10 10 
11## 核心能力11## 核心能力
12 12 
@@ -30,6 +30,12 @@ Agentic Authentication, Authorization, and Audit Protocol(A4P)Python SDK 提
30 30 
31SDK 提供 Ed25519 签名的授权对象、Ed25519 与 WebAuthn/passkey 用户签名方式、参数范围校验,以及基于 SQLite 持久化和原子消费的执行次数限制。prepare/complete 两阶段接口支持异步完成用户确认,便于集成到现有工具服务中。31SDK 提供 Ed25519 签名的授权对象、Ed25519 与 WebAuthn/passkey 用户签名方式、参数范围校验,以及基于 SQLite 持久化和原子消费的执行次数限制。prepare/complete 两阶段接口支持异步完成用户确认,便于集成到现有工具服务中。
32 32 
33+### 基于 IntelliRouter 的智能 LLM 路由
34+ 
35+IntelliRouter 是一个轻量级 **LLM 代理 SDK**,将同一模型名映射到多个部署端点,并对每次请求进行智能路由。它支持池化管理多家 Provider 的部署——OpenAI、Anthropic、Bedrock、DeepSeek、Gemini、SiliconFlow,以及任意 OpenAI 兼容端点——并通过可插拔策略选择部署:SimpleShuffle、LowestLatency、TagBased、TokenAware、RateLimitAware、Adaptive、OrderedFailover 与 TagFiltered。
36+ 
37+路由器持续跟踪各部署的健康与配额状态(延迟、失败计数、TPM/RPM 用量、冷却窗口),后台运行健康检查,请求失败时自动重试与故障转移,并通过事件总线、Prometheus 指标、Web 看板和日志钩子提供可观测性。SDK 同时内置流式响应与 JSON/Markdown 输出解析器。
38+ 
33## 组件选型39## 组件选型
34 40 
35各组件面向不同的接入需求,可独立使用,无需同时引入其他组件。41各组件面向不同的接入需求,可独立使用,无需同时引入其他组件。
@@ -40,6 +46,7 @@ SDK 提供 Ed25519 签名的授权对象、Ed25519 与 WebAuthn/passkey 用户
40| 委派任务给其他智能体 | A2A C++ SDK | 交换消息、跟踪任务状态并接收流式结果。 |46| 委派任务给其他智能体 | A2A C++ SDK | 交换消息、跟踪任务状态并接收流式结果。 |
41| 寻找合适的服务或协作对象 | A2X Registry | 注册服务元数据、发现能力并协调服务可用状态。 |47| 寻找合适的服务或协作对象 | A2X Registry | 注册服务元数据、发现能力并协调服务可用状态。 |
42| 在用户批准的范围内执行操作 | A4P Python SDK | 获取可验证的授权,并在受保护操作执行前校验授权范围。 |48| 在用户批准的范围内执行操作 | A4P Python SDK | 获取可验证的授权,并在受保护操作执行前校验授权范围。 |
49+| 在多个 LLM 部署间智能路由请求 | IntelliRouter | 池化模型端点,按请求选择最优部署,失败时自动切换。 |
43 50 
44## 仓库结构51## 仓库结构
45 52 
@@ -48,7 +55,8 @@ agent-protocol/
48├── MCP/cpp-sdk/ # MCP C++ 客户端/服务端 SDK 与示例55├── MCP/cpp-sdk/ # MCP C++ 客户端/服务端 SDK 与示例
49├── A2A/cpp-sdk/ # A2A C++ 客户端/服务端 SDK 与示例56├── A2A/cpp-sdk/ # A2A C++ 客户端/服务端 SDK 与示例
50├── AgentRegistry/ # A2X 注册中心、Python 客户端、Web UI 与文档57├── AgentRegistry/ # A2X 注册中心、Python 客户端、Web UI 与文档
51-└── A4P-python-sdk/ # A4P Python SDK、协议文档与示例58+├── A4P-python-sdk/ # A4P Python SDK、协议文档与示例
59+└── intelli_router/ # IntelliRouter LLM 代理 SDK、测试与示例
52```60```
53 61 
54## 快速开始62## 快速开始
@@ -66,6 +74,7 @@ cd agent-protocol
66| [A2A C++ SDK](./A2A/cpp-sdk/README.md) | C++17、CMake ≥ 3.15 及系统依赖;Linux 为主要验证平台 | 启用示例构建,运行 Hello World 与流式通信示例。 |74| [A2A C++ SDK](./A2A/cpp-sdk/README.md) | C++17、CMake ≥ 3.15 及系统依赖;Linux 为主要验证平台 | 启用示例构建,运行 Hello World 与流式通信示例。 |
67| [A2X Registry](./AgentRegistry/README.md) | Python ≥ 3.10;A2X 搜索需要配置 LLM | 安装并启动注册中心,通过 HTTP API 或 UI 注册和查询服务。 |75| [A2X Registry](./AgentRegistry/README.md) | Python ≥ 3.10;A2X 搜索需要配置 LLM | 安装并启动注册中心,通过 HTTP API 或 UI 注册和查询服务。 |
68| [A4P Python SDK](./A4P-python-sdk/README.md) | Python ≥ 3.10 与 uv | 安装依赖,运行无需交互的 Ed25519 授权全链路示例。 |76| [A4P Python SDK](./A4P-python-sdk/README.md) | Python ≥ 3.10 与 uv | 安装依赖,运行无需交互的 Ed25519 授权全链路示例。 |
77+| [IntelliRouter](./intelli_router/README.md) | Python ≥ 3.9 | 安装 SDK,运行单元测试,体验端到端与可观测性示例。 |
69 78 
70各组件分别构建和安装,完整依赖与各平台操作步骤请参阅对应指南。79各组件分别构建和安装,完整依赖与各平台操作步骤请参阅对应指南。
71 80 
@@ -75,6 +84,7 @@ cd agent-protocol
75- **A2A:** [API 参考](./A2A/cpp-sdk/docs/api/README.md) · [依赖说明](./A2A/cpp-sdk/docs/dependencies.md) · [错误处理](./A2A/cpp-sdk/docs/errors.md)84- **A2A:** [API 参考](./A2A/cpp-sdk/docs/api/README.md) · [依赖说明](./A2A/cpp-sdk/docs/dependencies.md) · [错误处理](./A2A/cpp-sdk/docs/errors.md)
76- **A2X:** [注册中心指南](./AgentRegistry/README.md) · [Python 客户端](./AgentRegistry/client/README.md) · [Agent Team 部署](./AgentRegistry/README_forAgentTeam.md)85- **A2X:** [注册中心指南](./AgentRegistry/README.md) · [Python 客户端](./AgentRegistry/client/README.md) · [Agent Team 部署](./AgentRegistry/README_forAgentTeam.md)
77- **A4P:** [协议说明](./A4P-python-sdk/A4P_PROTOCOL.md) · [SDK 设计](./A4P-python-sdk/A4P_SDK_DESIGN.md) · [MCP 集成示例](./A4P-python-sdk/examples/note_mcp_a4p/README.md)86- **A4P:** [协议说明](./A4P-python-sdk/A4P_PROTOCOL.md) · [SDK 设计](./A4P-python-sdk/A4P_SDK_DESIGN.md) · [MCP 集成示例](./A4P-python-sdk/examples/note_mcp_a4p/README.md)
87+- **IntelliRouter:** [SDK 指南](./intelli_router/README.md) · [API 参考](./intelli_router/API.md) · [示例](./intelli_router/examples/)
78 88 
79## 参与贡献89## 参与贡献
80 90 
@@ -0,0 +1,301 @@
1+# IntelliRouter - 轻量LLM代理SDK
2+ 
3+## 项目简介
4+ 
5+**IntelliRouter** 是一个轻量级LLM代理SDK,实现多部署端点管理和智能路由。
6+ 
7+核心特性:
8+- **API池化**: 单一模型名 → 多部署端点映射
9+- **策略插拔**: 支持SimpleShuffle、LowestLatency、TagBased、TokenAware、RateLimitAware、Adaptive等路由策略
10+- **状态管理**: 部署状态追踪、Token/RPM实时监控,失败计数,冷却机制
11+- **健康检查**: 后台健康检查循环
12+- **重试机制**: 自动重试机制
13+ 
14+## 代码结构设计
15+ 
16+```
17+intelli_router/ # SDK 模块根目录
18+├── intelli_router/ # SDK 源码包
19+│ ├── core/ # 部署配置、路由状态与路由上下文
20+│ ├── strategy/ # 路由策略与策略工厂
21+│ │ ├── __init__.py # 策略工厂(create_strategy 按名称创建策略)
22+│ │ ├── base_strategy.py # 抽象策略基类
23+│ │ ├── simple_shuffle.py # 随机选择策略
24+│ │ ├── lowest_latency.py # 最低延迟策略
25+│ │ ├── tag_based.py # 标签策略
26+│ │ ├── tag_filtered.py # 标签过滤策略
27+│ │ ├── token_aware.py # Token 感知策略
28+│ │ ├── rate_limit_aware.py # RPM 限流策略
29+│ │ ├── ordered_failover.py # 顺序故障转移策略
30+│ │ └── adaptive.py # 自适应策略
31+│ ├── router/ # 基础路由器与可靠性路由器
32+│ ├── cache/ # LocalCache(LRU 本地缓存)
33+│ ├── health/ # 后台健康检查
34+│ ├── observability/ # 事件总线、指标、Web 看板与日志钩子
35+│ ├── parser/ # JSON / Markdown 输出解析器
36+│ ├── provider/ # 多厂商 Provider 适配器与注册表
37+│ └── utils/ # 异常层次与媒体工具
38+├── examples/ # 可运行示例(见下文"示例与测试")
39+├── demo_adaptive_strategy.py # 三种路由策略对比演示(直接可跑)
40+├── tests/ # 单元测试(pytest)
41+├── API.md # API 参考
42+└── pyproject.toml # 构建与依赖配置
43+```
44+ 
45+## 路由策略介绍
46+ 
47+本SDK实现了多种路由策略,以下介绍其中三种代表性的策略:
48+ 
49+### 1. Token感知策略 (TokenAwareStrategy)
50+ 
51+**场景**: Token耗尽时无缝切换
52+ 
53+**策略**:
54+1. 过滤可用部署
55+2. 按Token剩余量排序
56+3. 优先选择Token充足的部署
57+4. Token耗尽时无缝切换到下一个
58+ 
59+**关键参数**:
60+- `token_threshold`: Token阈值 (默认1000)
61+- `exploration_ratio`: 探索比例 (默认0.1)
62+ 
63+### 2. RPM限流策略 (RateLimitAwareStrategy)
64+ 
65+**场景**: RPM限流时负载均衡
66+ 
67+**策略**:
68+1. 过滤可用部署
69+2. 按RPM剩余配额排序
70+3. 优先选择RPM配额充足的部署
71+4. RPM耗尽时无缝切换
72+ 
73+**关键参数**:
74+- `rpm_threshold`: RPM阈值 (默认10)
75+- `exploration_ratio`: 探索比例 (默认0.1)
76+ 
77+### 3. 自适应策略 (AdaptiveStrategy)
78+ 
79+**场景**: 多级决策树
80+ 
81+**策略**:
82+1. 健康检查 → 剔除不健康部署
83+2. Token剩余 → 优先Token充足的
84+3. RPM剩余 → 优先RPM配额充足的
85+4. 延迟收益 → 优先低延迟的
86+5. 随机回退 → 随机选择
87+ 
88+**评分公式**:
89+```
90+score = w_health * health_score
91+ + w_token * token_score
92+ + w_rpm * rpm_score
93+ + w_latency * latency_score
94+```
95+ 
96+**关键参数**:
97+- `w_health`: 健康权重 (默认1.0)
98+- `w_token`: Token权重 (默认0.5)
99+- `w_rpm`: RPM权重 (默认0.3)
100+- `w_latency`: 延迟权重 (默认0.2)
101+ 
102+## 示例与测试
103+ 
104+所有示例脚本都位于 `examples/` 目录下,请在模块根目录(`intelli_router/`)中运行。
105+ 
106+### 端到端示例 (examples/demo_e2e.py)
107+ 
108+演示 OpenAI / Anthropic / Gemini 真实调用、dead 端点自动 failover、全部端点不可用时抛出 `RouterError`。未配置对应 API Key 的场景会自动跳过:
109+ 
110+**运行**:
111+```bash
112+export OPENAI_API_KEY="sk-..."
113+python examples/demo_e2e.py
114+```
115+ 
116+**输出示例**(配置 `OPENAI_API_KEY` 后):
117+```
118+intelli_router 端到端 Demo
119+==================================================
120+ 
121+=== scene: OpenAI real ===
122+ response: 你好世界
123+ latency: 0.85s
124+ usage: {'prompt_tokens': 21, 'completion_tokens': 8, 'total_tokens': 29}
125+ 
126+=== scene: Failover ===
127+ primary deployment (dead): openai-dead → http://localhost:19999
128+ fallback deployment (healthy): openai-real → https://api.openai.com
129+ response: 你好世界
130+ latency: 1.23s
131+ after call status:
132+ openai-dead: cooldown
133+ openai-real: healthy
134+ 
135+=== scene: All dead ===
136+ caught expected RouterError ✓
137+ error: All deployments failed for model 'gpt-4o-mini'
138+ 
139+=== done ===
140+```
141+ 
142+配置 `ANTHROPIC_API_KEY` / `GEMINI_API_KEY` 后还会追加对应 Provider 的真实调用场景。
143+ 
144+### Prometheus 指标示例 (examples/demo_prometheus.py)
145+ 
146+使用模拟请求,无需真实 API Key:
147+ 
148+```bash
149+pip install prometheus-client
150+python examples/demo_prometheus.py
151+ 
152+# 另一个终端验证(默认端口 9091,可通过 METRICS_PORT 环境变量修改)
153+curl http://localhost:9091/metrics | grep intelli_router
154+```
155+ 
156+### Web 指标看板示例 (examples/demo_web_dashboard.py)
157+ 
158+同样使用模拟请求,无需真实 API Key。启动后在浏览器打开 http://localhost:8080(端口可通过 `WEB_PORT` 环境变量修改):
159+ 
160+```bash
161+python examples/demo_web_dashboard.py
162+```
163+ 
164+### 路由策略对比演示 (demo_adaptive_strategy.py)
165+ 
166+用模拟部署依次演示 Token 感知、RPM 限流、自适应三种策略的选路过程(无真实 API Key,无网络请求)。该脚本位于模块根目录(`intelli_router/` 下),自带包路径处理,可直接运行:
167+ 
168+```bash
169+python demo_adaptive_strategy.py
170+```
171+ 
172+输出依次为三段:Token 感知策略演示(选择 Token 剩余充足的部署)、RPM 限流策略演示(选择 RPM 配额充足的部署)、自适应策略演示(打印各部署的多维度评分与最终选择)。
173+ 
174+### 运行测试
175+ 
176+```bash
177+python3 -m pytest tests/ -v
178+```
179+ 
180+## 快速上手
181+ 
182+```python
183+import asyncio
184+from intelli_router import ReliableRouter, Deployment
185+ 
186+# 1. 定义部署端点
187+dep = Deployment(
188+ id="openai-1",
189+ model_name="gpt-4o-mini",
190+ api_key="sk-...",
191+ api_base="https://api.openai.com",
192+ provider="openai",
193+)
194+ 
195+# 2. 创建路由器
196+router = ReliableRouter(deployments=[dep], strategy="adaptive")
197+ 
198+# 3. 调用
199+async def main():
200+ resp = await router.completion(
201+ "gpt-4o-mini",
202+ [{"role": "user", "content": "你好"}],
203+ )
204+ print(resp["choices"][0]["message"]["content"])
205+ await router.close()
206+ 
207+asyncio.run(main())
208+```
209+ 
210+Streaming 用法:
211+ 
212+```python
213+# 原始 OpenAI 格式 chunk(dict)
214+async for chunk in router.stream_completion("gpt-4o-mini", messages):
215+ print(chunk["choices"][0]["delta"].get("content", ""), end="")
216+ 
217+# 或类型化 chunk(AssistantMessageChunk 属性访问)
218+async for chunk in router.stream(messages, model="gpt-4o-mini"):
219+ print(chunk.content or "", end="")
220+```
221+ 
222+多 Provider failover:
223+ 
224+```python
225+deps = [
226+ Deployment(id="main", model_name="gpt-4o-mini", api_key="sk-...",
227+ api_base="https://api.openai.com", provider="openai"),
228+ Deployment(id="backup", model_name="gpt-4o-mini", api_key="sk-...",
229+ api_base="https://api.openai.com", provider="openai"),
230+]
231+router = ReliableRouter(deployments=deps, num_retries=1, strategy="adaptive")
232+# 主端点失败时自动切换到备用端点
233+resp = await router.completion("gpt-4o-mini", messages)
234+```
235+ 
236+## 多 Provider 适配
237+ 
238+IntelliRouter 以 OpenAI 格式为内部标准格式,通过 Provider Adapter 自动完成与各厂商 API 的协议转换。调用者只需在 `Deployment` 中指定 `provider` 字段,无需关心底层协议差异。
239+ 
240+支持的 Provider:
241+ 
242+| Provider | `provider` 标识 | 说明 |
243+|----------|----------------|------|
244+| OpenAI | `openai` | 基准实现,直接透传 |
245+| Anthropic | `anthropic` | 完整协议转换(Messages API) |
246+| Google Gemini | `google-gemini` | 完整协议转换(generateContent) |
247+| DeepSeek | `deepseek` | OpenAI 兼容 + reasoning_content 字段注入 |
248+| DashScope (阿里云) | `dashscope` | OpenAI 兼容,端点路径不同 |
249+| SiliconFlow (硅基流动) | `siliconflow` | OpenAI 兼容 + tool_calls 字段清洗 |
250+| Zhipu (智谱) | `zhipu` | OpenAI 兼容,端点路径不同 |
251+| InferenceAffinity (vLLM) | `inference-affinity` | OpenAI 兼容 + KV cache 共享 |
252+| AWS Bedrock | `aws-bedrock` | Converse API(botocore SigV4 签名;`api_key` 可空,回退默认凭证链) |
253+ 
254+各 Provider 适配器的差异详见 [API.md](API.md) 的「Provider 适配器」一节。
255+ 
256+## 输出解析器 (Parser)
257+ 
258+内置两种输出解析器,用于将 LLM 响应解析为结构化数据:
259+ 
260+- **JsonOutputParser**:从 LLM 回复中提取 JSON,支持裸 JSON 和 ` ```json ` 代码块包裹格式,支持流式增量解析
261+- **MarkdownOutputParser**:将 Markdown 文本解析为结构化 `MarkdownContent`,包含 headers、code_blocks、links、images、tables、lists 等元素
262+ 
263+```python
264+from intelli_router import JsonOutputParser, MarkdownOutputParser
265+ 
266+# JSON 解析
267+parser = JsonOutputParser()
268+result = parser.parse(assistant_message) # -> dict/list
269+ 
270+# Markdown 解析
271+md_parser = MarkdownOutputParser()
272+content = md_parser.parse(assistant_message) # -> MarkdownContent
273+print(content.headers) # 所有标题
274+print(content.code_blocks) # 所有代码块
275+```
276+ 
277+## 类型定义 (Types)
278+ 
279+`intelli_router.types` 提供统一的类型化响应对象:
280+ 
281+- **`ToolCall`** — 工具调用信息(id、name、arguments)
282+- **`UsageMetadata`** — Token 用量统计(input_tokens、output_tokens、total_tokens)
283+- **`AssistantMessage`** — 完整的助手响应(content、tool_calls、usage)
284+- **`AssistantMessageChunk`** — 流式响应片段,支持 `+` 运算符累加合并
285+ 
286+```python
287+from intelli_router import AssistantMessage, AssistantMessageChunk
288+ 
289+# chunk 累加
290+full = AssistantMessageChunk()
291+async for chunk in router.stream(...):
292+ full = full + chunk # 自动合并 content、tool_calls、usage
293+```
294+ 
295+## 更多文档
296+ 
297+- [API.md](API.md) — 完整 API 参考
298+- [examples/demo_e2e.py](examples/demo_e2e.py) — 端到端演示(OpenAI / Anthropic / Gemini / Failover)
299+- [examples/demo_prometheus.py](examples/demo_prometheus.py) — Prometheus 指标导出演示
300+- [examples/demo_web_dashboard.py](examples/demo_web_dashboard.py) — Web 指标看板演示
301+ 
@@ -0,0 +1,278 @@
1+"""
2+Demo Adaptive Strategy - 自适应策略演示
3+ 
4+演示场景:
5+1. Token感知策略 - Token耗尽无缝切换
6+2. RPM限流策略 - RPM限流负载均衡
7+3. 自适应策略 - 多级决策树
8+"""
9+import sys
10+import os
11+# 添加包路径以支持直接运行
12+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
13+ 
14+import asyncio
15+import time
16+from dataclasses import dataclass, field
17+ 
18+from intelli_router.strategy.token_aware import TokenAwareStrategy
19+from intelli_router.strategy.rate_limit_aware import RateLimitAwareStrategy
20+from intelli_router.strategy.adaptive import AdaptiveStrategy
21+from intelli_router.core.state import LocalRouterState, TokenUsage, RPMTracker, LatencyRecord
22+from intelli_router.core.deployment import Deployment, DeploymentStatus
23+from intelli_router.core.context import RoutingContext
24+ 
25+ 
26+def create_demo_state() -> LocalRouterState:
27+ """创建演示状态"""
28+ state = LocalRouterState()
29+ 
30+ # 部署1: 健康, Token剩余5000, RPM剩余30, 平均延迟0.5秒
31+ state.health_state["dep1"] = True
32+ state.token_usage["dep1"] = TokenUsage(used=5000, limit=10000)
33+ tracker1 = RPMTracker(rpm_limit=60)
34+ for _ in range(30):
35+ tracker1.add_request()
36+ state.rpm_tracker["dep1"] = tracker1
37+ state.latencies["dep1"] = [
38+ LatencyRecord(latency=0.5, tokens=100, normalized=0.005, timestamp=time.time())
39+ ]
40+ 
41+ # 部署2: 健康, Token剩余2000, RPM剩余50, 平均延迟0.2秒
42+ state.health_state["dep2"] = True
43+ state.token_usage["dep2"] = TokenUsage(used=8000, limit=10000)
44+ tracker2 = RPMTracker(rpm_limit=60)
45+ for _ in range(10):
46+ tracker2.add_request()
47+ state.rpm_tracker["dep2"] = tracker2
48+ state.latencies["dep2"] = [
49+ LatencyRecord(latency=0.2, tokens=100, normalized=0.002, timestamp=time.time())
50+ ]
51+ 
52+ # 部署3: 不健康(运行期冷却记录在 state 中——state 是唯一事实源,
53+ # Deployment 对象自身的 status 看不到运行期状态)
54+ state.health_state["dep3"] = False
55+ state.deployment_status["dep3"] = DeploymentStatus.COOLDOWN
56+ state.cooldown_until["dep3"] = time.time() + 3600
57+ 
58+ return state
59+ 
60+ 
61+def filter_available(
62+ deployments: list[Deployment], state: LocalRouterState
63+) -> list[Deployment]:
64+ """按 state(唯一事实源)过滤可用部署。
65+ 
66+ 策略层契约:传给策略的列表已过滤。演示直接使用策略(不经
67+ ReliableRouter),因此在这里自行完成同样的过滤。
68+ """
69+ now = time.time()
70+ available = []
71+ for dep in deployments:
72+ status = state.deployment_status.get(dep.id, DeploymentStatus.HEALTHY)
73+ if status == DeploymentStatus.COOLDOWN:
74+ if now < state.cooldown_until.get(dep.id, 0):
75+ continue
76+ available.append(dep)
77+ return available
78+ 
79+ 
80+def create_demo_deployments() -> list[Deployment]:
81+ """创建演示部署"""
82+ return [
83+ Deployment(
84+ model_name="gpt-4",
85+ api_key="sk-key1",
86+ api_base="http://localhost:8001/v1",
87+ id="dep1",
88+ tpm=10000,
89+ rpm=60
90+ ),
91+ Deployment(
92+ model_name="gpt-4",
93+ api_key="sk-key2",
94+ api_base="http://localhost:8002/v1",
95+ id="dep2",
96+ tpm=10000,
97+ rpm=60
98+ ),
99+ Deployment(
100+ model_name="gpt-4",
101+ api_key="sk-key3",
102+ api_base="http://localhost:8003/v1",
103+ id="dep3",
104+ tpm=10000,
105+ rpm=60
106+ ),
107+ ]
108+ 
109+ 
110+async def demo_token_aware():
111+ """演示Token感知策略"""
112+ print("\n=== Token感知策略演示 ===")
113+ 
114+ state = create_demo_state()
115+ deployments = create_demo_deployments()
116+ strategy = TokenAwareStrategy(state=state, token_threshold=1000, exploration_ratio=0.0)
117+ 
118+ context = RoutingContext(
119+ model="gpt-4",
120+ messages=[{"role": "user", "content": "Hello!"}]
121+ )
122+ 
123+ # 选择部署(列表先按 state 过滤——策略层契约要求)
124+ selected = await strategy.select_deployment(
125+ filter_available(deployments, state), context
126+ )
127+ print(f"选择的部署: {selected.id}")
128+ print(f" - Token剩余: {state.get_token_remaining(selected.id)}")
129+ print(f" - Token使用率: {state.get_token_utilization(selected.id):.2%}")
130+ 
131+ # 模拟请求成功(策略的 on_success 是 no-op——router 才是 state 的
132+ # 唯一写入方——因此直接更新 state,使展示数值真实递增)
133+ state.on_success(selected.id, latency=0.5, tokens=100)
134+ print(f"\n请求成功后:")
135+ print(f" - Token已使用: {state.token_usage[selected.id].used}")
136+ print(f" - Token剩余: {state.token_usage[selected.id].remaining}")
137+ 
138+ 
139+async def demo_rate_limit_aware():
140+ """演示RPM限流策略"""
141+ print("\n=== RPM限流策略演示 ===")
142+ 
143+ state = create_demo_state()
144+ deployments = create_demo_deployments()
145+ strategy = RateLimitAwareStrategy(state=state, rpm_threshold=10, exploration_ratio=0.0)
146+ 
147+ context = RoutingContext(
148+ model="gpt-4",
149+ messages=[{"role": "user", "content": "Hello!"}]
150+ )
151+ 
152+ # 选择部署(列表先按 state 过滤——策略层契约要求)
153+ selected = await strategy.select_deployment(
154+ filter_available(deployments, state), context
155+ )
156+ print(f"选择的部署: {selected.id}")
157+ print(f" - RPM剩余: {state.get_rpm_remaining(selected.id)}")
158+ print(f" - RPM使用率: {state.get_rpm_utilization(selected.id):.2%}")
159+ 
160+ # 模拟请求成功(策略的 on_success 是 no-op——router 才是 state 的
161+ # 唯一写入方——因此直接更新 state,使展示数值真实递增)
162+ state.on_success(selected.id, latency=0.3, tokens=50)
163+ print(f"\n请求成功后:")
164+ print(f" - 当前RPM: {state.rpm_tracker[selected.id].current_rpm}")
165+ print(f" - RPM剩余: {state.rpm_tracker[selected.id].remaining}")
166+ 
167+ 
168+async def demo_adaptive():
169+ """演示自适应策略"""
170+ print("\n=== 自适应策略演示 ===")
171+ 
172+ state = create_demo_state()
173+ deployments = create_demo_deployments()
174+ strategy = AdaptiveStrategy(
175+ state=state,
176+ token_threshold=1000,
177+ rpm_threshold=10,
178+ exploration_ratio=0.0,
179+ w_health=1.0,
180+ w_token=0.5,
181+ w_rpm=0.3,
182+ w_latency=0.2
183+ )
184+ 
185+ context = RoutingContext(
186+ model="gpt-4",
187+ messages=[{"role": "user", "content": "Hello!"}]
188+ )
189+ 
190+ # 计算各部署得分
191+ print("\n部署评分:")
192+ now = time.time()
193+ for d in filter_available(deployments, state):
194+ score = strategy._calculate_score(d, now)
195+ print(f" {d.id}: 得分={score:.3f}")
196+ print(f" - 健康: {state.health_state.get(d.id, False)}")
197+ print(f" - Token剩余: {state.get_token_remaining(d.id)}")
198+ print(f" - RPM剩余: {state.get_rpm_remaining(d.id)}")
199+ print(f" - 平均延迟: {state.get_average_latency(d.id):.3f}")
200+ 
201+ # 选择部署(列表先按 state 过滤——策略层契约要求)
202+ selected = await strategy.select_deployment(
203+ filter_available(deployments, state), context
204+ )
205+ print(f"\n选择的部署: {selected.id}")
206+ 
207+ # 模拟请求成功
208+ # 说明:策略的 on_success 是 no-op(router 才是 state 的唯一写入方),
209+ # 演示直接调用策略不经 router,因此这里手动更新 state 以展示请求后的变化;
210+ # 读取处用 .get() 容错(total_requests 等统计仅 state.on_success 才写)。
211+ state.on_success(selected.id, latency=0.4, tokens=80)
212+ print(f"\n请求成功后:")
213+ print(f" - Token已使用: {state.token_usage[selected.id].used}")
214+ print(f" - 当前RPM: {state.rpm_tracker[selected.id].current_rpm}")
215+ print(f" - 总请求数: {state.total_requests.get(selected.id, 0)}")
216+ 
217+ 
218+async def demo_token_exhaustion():
219+ """演示Token耗尽场景"""
220+ print("\n=== Token耗尽无缝切换演示 ===")
221+ 
222+ state = create_demo_state()
223+ deployments = create_demo_deployments()
224+ 
225+ # 设置所有部署Token都快耗尽
226+ state.token_usage["dep1"] = TokenUsage(used=9900, limit=10000) # 剩余100
227+ state.token_usage["dep2"] = TokenUsage(used=9950, limit=10000) # 剩余50
228+ state.token_usage["dep3"] = TokenUsage(used=9990, limit=10000) # 剩余10
229+ 
230+ strategy = TokenAwareStrategy(state=state, token_threshold=1000, exploration_ratio=0.0)
231+ context = RoutingContext(
232+ model="gpt-4",
233+ messages=[{"role": "user", "content": "Hello!"}]
234+ )
235+ 
236+ # 选择部署(列表先按 state 过滤——策略层契约要求)
237+ selected = await strategy.select_deployment(
238+ filter_available(deployments, state), context
239+ )
240+ print(f"Token快耗尽时选择的部署: {selected.id}")
241+ print(f" - Token剩余: {state.token_usage[selected.id].remaining}")
242+ 
243+ # 模拟多次请求直到耗尽(策略 on_success 是 no-op——router 才是
244+ # state 的唯一写入方——因此这里手动累计 token 使用量)
245+ for i in range(3):
246+ state.token_usage[selected.id].used += 50
247+ print(f"\n第{i+1}次请求后:")
248+ print(f" - Token剩余: {state.token_usage[selected.id].remaining}")
249+ 
250+ if state.token_usage[selected.id].remaining <= 0:
251+ print(" - Token已耗尽,切换到下一个部署")
252+ # 在实际场景中,会重新选择部署
253+ available = filter_available(
254+ [d for d in deployments if d.id != selected.id], state
255+ )
256+ if available:
257+ selected = available[0]
258+ print(f" - 切换到: {selected.id}")
259+ 
260+ 
261+async def main():
262+ """主演示函数"""
263+ print("=" * 60)
264+ print("自适应策略演示")
265+ print("=" * 60)
266+ 
267+ await demo_token_aware()
268+ await demo_rate_limit_aware()
269+ await demo_adaptive()
270+ await demo_token_exhaustion()
271+ 
272+ print("\n" + "=" * 60)
273+ print("演示完成")
274+ print("=" * 60)
275+ 
276+ 
277+if __name__ == "__main__":
278+ asyncio.run(main())
@@ -0,0 +1,236 @@
1+"""
2+intelli_router 端到端 Demo
3+ 
4+演示场景:
5+ 1. OpenAI 真实调用
6+ 2. Anthropic 真实调用
7+ 3. Gemini 真实调用
8+ 4. Failover — dead endpoint 自动切换到 healthy endpoint
9+ 5. All dead — 所有 endpoint 不可用,抛出 RouterError
10+ 
11+使用方式:
12+ export OPENAI_API_KEY="sk-..."
13+ export ANTHROPIC_API_KEY="sk-ant-..."
14+ export GEMINI_API_KEY="AIza..."
15+ 
16+ python examples/demo_e2e.py
17+ 
18+没有配置 key 的场景会自动 skip。
19+"""
20+ 
21+import os
22+import asyncio
23+import time
24+ 
25+from intelli_router.core.deployment import Deployment
26+from intelli_router.router.reliable_router import ReliableRouter
27+from intelli_router.utils.exceptions import RouterError
28+ 
29+# ---------------------------------------------------------------------------
30+# 配置
31+# ---------------------------------------------------------------------------
32+ 
33+MESSAGE = [{"role": "user", "content": "回复三个中文字符:你好世界"}]
34+ 
35+OPENAI_KEY = os.environ.get("OPENAI_API_KEY", "")
36+ANTHROPIC_KEY = os.environ.get("ANTHROPIC_API_KEY", "")
37+GEMINI_KEY = os.environ.get("GEMINI_API_KEY", "")
38+ 
39+DEAD_BASE = "http://localhost:19999" # 没有服务监听的端口
40+ 
41+MODELS = {
42+ "openai": "gpt-4o-mini",
43+ "anthropic": "claude-3-haiku-20240307",
44+ "gemini": "gemini-1.5-flash",
45+}
46+ 
47+ 
48+# ---------------------------------------------------------------------------
49+# 场景
50+# ---------------------------------------------------------------------------
51+ 
52+ 
53+async def scene_openai():
54+ """场景 1:OpenAI 真实调用"""
55+ print("\n=== scene: OpenAI real ===")
56+ dep = Deployment(
57+ id="openai-1",
58+ model_name=MODELS["openai"],
59+ api_key=OPENAI_KEY,
60+ api_base="https://api.openai.com",
61+ provider="openai",
62+ )
63+ router = ReliableRouter(
64+ deployments=[dep],
65+ num_retries=0,
66+ strategy="simple-shuffle",
67+ )
68+ t0 = time.time()
69+ resp = await router.completion(MODELS["openai"], MESSAGE)
70+ cost = time.time() - t0
71+ print(f" response: {resp['choices'][0]['message']['content']}")
72+ print(f" latency: {cost:.2f}s")
73+ print(f" usage: {resp['usage']}")
74+ await router.close()
75+ 
76+ 
77+async def scene_anthropic():
78+ """场景 2:Anthropic 真实调用"""
79+ print("\n=== scene: Anthropic real ===")
80+ dep = Deployment(
81+ id="anthropic-1",
82+ model_name=MODELS["anthropic"],
83+ api_key=ANTHROPIC_KEY,
84+ api_base="https://api.anthropic.com",
85+ provider="anthropic",
86+ )
87+ router = ReliableRouter(
88+ deployments=[dep],
89+ num_retries=0,
90+ strategy="simple-shuffle",
91+ )
92+ t0 = time.time()
93+ resp = await router.completion(MODELS["anthropic"], MESSAGE)
94+ cost = time.time() - t0
95+ print(f" response: {resp['choices'][0]['message']['content']}")
96+ print(f" latency: {cost:.2f}s")
97+ print(f" usage: {resp['usage']}")
98+ await router.close()
99+ 
100+ 
101+async def scene_gemini():
102+ """场景 3:Gemini 真实调用"""
103+ print("\n=== scene: Gemini real ===")
104+ dep = Deployment(
105+ id="gemini-1",
106+ model_name=MODELS["gemini"],
107+ api_key=GEMINI_KEY,
108+ api_base="https://generativelanguage.googleapis.com",
109+ provider="google-gemini",
110+ )
111+ router = ReliableRouter(
112+ deployments=[dep],
113+ num_retries=0,
114+ strategy="simple-shuffle",
115+ )
116+ t0 = time.time()
117+ resp = await router.completion(MODELS["gemini"], MESSAGE)
118+ cost = time.time() - t0
119+ print(f" response: {resp['choices'][0]['message']['content']}")
120+ print(f" latency: {cost:.2f}s")
121+ print(f" usage: {resp['usage']}")
122+ await router.close()
123+ 
124+ 
125+async def scene_failover():
126+ """场景 4:Failover — dead endpoint 自动切换到 healthy
127+ 
128+ 两个 deployment 指向同一模型 "gpt-4o-mini":
129+ - openai-dead: api_base 指向不存在的 localhost:19999
130+ - openai-real: 指向真实 OpenAI
131+ 
132+ ReliableRouter 首次选到 dead 后在 state 中记失败并置 cooldown,
133+ 重试选到 real,验证 fallback 成功。
134+ """
135+ print("\n=== scene: Failover ===")
136+ dead = Deployment(
137+ id="openai-dead",
138+ model_name=MODELS["openai"],
139+ api_key="fake-key",
140+ api_base=DEAD_BASE,
141+ provider="openai",
142+ )
143+ real = Deployment(
144+ id="openai-real",
145+ model_name=MODELS["openai"],
146+ api_key=OPENAI_KEY,
147+ api_base="https://api.openai.com",
148+ provider="openai",
149+ )
150+ router = ReliableRouter(
151+ deployments=[dead, real],
152+ num_retries=1,
153+ strategy="adaptive", # adaptive 策略打分;失败计数/冷却由 ReliableRouter 统一写 state
154+ )
155+ t0 = time.time()
156+ resp = await router.completion(MODELS["openai"], MESSAGE)
157+ cost = time.time() - t0
158+ 
159+ print(f" primary deployment (dead): {dead.id} → {DEAD_BASE}")
160+ print(f" fallback deployment (healthy): {real.id} → https://api.openai.com")
161+ print(f" response: {resp['choices'][0]['message']['content']}")
162+ print(f" latency: {cost:.2f}s")
163+ 
164+ stats = router.get_stats()
165+ print(f" after call status:")
166+ for dep_id, status in stats["deployment_status"].items():
167+ print(f" {dep_id}: {status}")
168+ 
169+ await router.close()
170+ 
171+ 
172+async def scene_all_dead():
173+ """场景 5:All dead — 所有 endpoint 不可用
174+ 
175+ 两个 deployment 都指向 localhost:19999,预期抛出 RouterError。
176+ """
177+ print("\n=== scene: All dead ===")
178+ dead1 = Deployment(
179+ id="dead-1",
180+ model_name=MODELS["openai"],
181+ api_key="fake-key",
182+ api_base=DEAD_BASE,
183+ provider="openai",
184+ )
185+ dead2 = Deployment(
186+ id="dead-2",
187+ model_name=MODELS["openai"],
188+ api_key="fake-key",
189+ api_base=DEAD_BASE,
190+ provider="openai",
191+ )
192+ router = ReliableRouter(
193+ deployments=[dead1, dead2],
194+ num_retries=1,
195+ strategy="adaptive",
196+ )
197+ try:
198+ await router.completion(MODELS["openai"], MESSAGE)
199+ print(" ERROR: expected RouterError but got success")
200+ except RouterError as e:
201+ print(f" caught expected RouterError ✓")
202+ print(f" error: {e}")
203+ await router.close()
204+ 
205+ 
206+# ---------------------------------------------------------------------------
207+# main
208+# ---------------------------------------------------------------------------
209+ 
210+ 
211+async def main():
212+ print("intelli_router 端到端 Demo")
213+ print("=" * 50)
214+ 
215+ if OPENAI_KEY:
216+ await scene_openai()
217+ await scene_failover()
218+ await scene_all_dead()
219+ else:
220+ print("\n[skip] OPENAI_API_KEY 未设置,跳过 OpenAI / failover / all-dead 场景")
221+ 
222+ if ANTHROPIC_KEY:
223+ await scene_anthropic()
224+ else:
225+ print("\n[skip] ANTHROPIC_API_KEY 未设置,跳过 Anthropic 场景")
226+ 
227+ if GEMINI_KEY:
228+ await scene_gemini()
229+ else:
230+ print("\n[skip] GEMINI_API_KEY 未设置,跳过 Gemini 场景")
231+ 
232+ print("\n=== done ===")
233+ 
234+ 
235+if __name__ == "__main__":
236+ asyncio.run(main())
@@ -0,0 +1,192 @@
1+"""
2+IntelliRouter Prometheus 指标导出 Demo
3+ 
4+演示 Prometheus 指标暴露。使用模拟请求,无需真实 API Key。
5+ 
6+使用方式:
7+ pip install prometheus-client
8+ python examples/demo_prometheus.py
9+ 
10+验证(默认端口 9091,可通过 METRICS_PORT 环境变量修改):
11+ curl http://localhost:9091/metrics | grep intelli_router
12+"""
13+ 
14+import asyncio
15+import os
16+import random
17+import signal
18+import sys
19+ 
20+from intelli_router import (
21+ ReliableRouter,
22+ Deployment,
23+ EventBus,
24+ MetricsCollector,
25+ LoggingHook,
26+)
27+from intelli_router.router.base_router import BaseRouter
28+ 
29+ 
30+# ---------------------------------------------------------------------------
31+# 模拟 Deployments
32+# ---------------------------------------------------------------------------
33+DEPLOYMENTS = [
34+ Deployment(
35+ id="azure-east",
36+ model_name="gpt-4",
37+ provider="openai",
38+ api_key="fake-key-1",
39+ api_base="http://localhost:19999",
40+ ),
41+ Deployment(
42+ id="openai-main",
43+ model_name="gpt-4",
44+ provider="openai",
45+ api_key="fake-key-2",
46+ api_base="http://localhost:19998",
47+ ),
48+ Deployment(
49+ id="anthropic-1",
50+ model_name="claude-3",
51+ provider="anthropic",
52+ api_key="fake-key-3",
53+ api_base="http://localhost:19997",
54+ ),
55+]
56+ 
57+ 
58+# ---------------------------------------------------------------------------
59+# Mock:模拟不同 deployment 的延迟和失败
60+# ---------------------------------------------------------------------------
61+async def mock_completion(self, model, messages, deployment=None, **kwargs):
62+ if deployment is None:
63+ raise RuntimeError("No deployment")
64+ 
65+ # 不同 deployment 模拟不同特性
66+ profiles = {
67+ "azure-east": {"latency": (0.3, 0.8), "fail_rate": 0.05},
68+ "openai-main": {"latency": (0.5, 1.5), "fail_rate": 0.10},
69+ "anthropic-1": {"latency": (0.8, 2.0), "fail_rate": 0.15},
70+ }
71+ profile = profiles.get(deployment.id, {"latency": (0.5, 1.0), "fail_rate": 0.1})
72+ 
73+ latency = random.uniform(*profile["latency"])
74+ await asyncio.sleep(latency)
75+ 
76+ if random.random() < profile["fail_rate"]:
77+ error_types = [
78+ RuntimeError("Connection timeout"),
79+ RuntimeError("Rate limit exceeded"),
80+ RuntimeError("Internal server error"),
81+ ]
82+ raise random.choice(error_types)
83+ 
84+ tokens_prompt = random.randint(50, 300)
85+ tokens_completion = random.randint(20, 200)
86+ return {
87+ "choices": [{"message": {"content": "Hello!"}, "finish_reason": "stop"}],
88+ "usage": {
89+ "prompt_tokens": tokens_prompt,
90+ "completion_tokens": tokens_completion,
91+ "total_tokens": tokens_prompt + tokens_completion,
92+ },
93+ }
94+ 
95+ 
96+async def main():
97+ print("=" * 60)
98+ print(" IntelliRouter Prometheus Demo")
99+ print("=" * 60)
100+ print()
101+ port = int(os.environ.get("METRICS_PORT", "9091"))
102+ print(f" 指标端口: http://localhost:{port}/metrics")
103+ print(" 模拟 3 个 deployment (gpt-4 x2, claude-3 x1)")
104+ print(" 按 Ctrl+C 退出")
105+ print()
106+ 
107+ # 设置 EventBus
108+ bus = EventBus()
109+ 
110+ # Prometheus 指标采集
111+ metrics = MetricsCollector(enable_prometheus=True)
112+ metrics.expose_prometheus(port=port)
113+ bus.register(metrics)
114+ 
115+ # 同时开启文本日志(方便观察)
116+ bus.register(LoggingHook(format="text"))
117+ 
118+ # 创建 Router
119+ router = ReliableRouter(
120+ deployments=DEPLOYMENTS,
121+ strategy="simple-shuffle",
122+ num_retries=2,
123+ event_bus=bus,
124+ )
125+ 
126+ # Monkey-patch
127+ original_completion = BaseRouter.completion
128+ BaseRouter.completion = mock_completion
129+ 
130+ print(" Prometheus HTTP server 已启动")
131+ print(" 验证: curl http://localhost:9091/metrics | grep intelli_router")
132+ print()
133+ print(" 开始模拟请求...\n")
134+ 
135+ try:
136+ request_num = 0
137+ while True:
138+ request_num += 1
139+ 
140+ # 随机选择模型
141+ model = random.choice(["gpt-4", "gpt-4", "gpt-4", "claude-3"])
142+ 
143+ try:
144+ await router.completion(model, [{"role": "user", "content": f"Request #{request_num}"}])
145+ except Exception:
146+ pass
147+ 
148+ # 模拟流量间隔
149+ await asyncio.sleep(random.uniform(0.2, 0.8))
150+ 
151+ # 每 20 个请求打印一次汇总
152+ if request_num % 20 == 0:
153+ stats = metrics.get_stats()
154+ print(f"\n --- 已完成 {request_num} 个请求 ---")
155+ print(f" 成功: {stats['successful']} "
156+ f"失败: {stats['failed']} "
157+ f"重试: {stats['retries']} "
158+ f"Token: {stats['tokens']['total']}")
159+ if stats['latency']['count'] > 0:
160+ print(f" 延迟: avg={stats['latency']['avg']:.2f}s "
161+ f"min={stats['latency']['min']:.2f}s "
162+ f"max={stats['latency']['max']:.2f}s")
163+ print()
164+ 
165+ except KeyboardInterrupt:
166+ print("\n\n 正在停止...")
167+ finally:
168+ BaseRouter.completion = original_completion
169+ 
170+ # 打印最终统计
171+ stats = metrics.get_stats()
172+ print("\n ========== 最终统计 ==========")
173+ print(f" 总请求: {stats['total_requests']}")
174+ print(f" 成功: {stats['successful']}")
175+ print(f" 失败: {stats['failed']}")
176+ print(f" 重试: {stats['retries']}")
177+ print(f" 耗尽: {stats['exhausted']}")
178+ if stats['latency']['count'] > 0:
179+ print(f" 平均延迟: {stats['latency']['avg']:.2f}s")
180+ print(f" 总 Token: {stats['tokens']['total']}")
181+ if stats['errors_by_type']:
182+ print(f" 错误分布: {dict(stats['errors_by_type'])}")
183+ print()
184+ print(" Prometheus 指标示例 (最终值):")
185+ print(" intelli_router_requests_total{status='success'} =", stats['successful'])
186+ print(" intelli_router_retries_total =", stats['retries'])
187+ print(" intelli_router_tokens_total =", stats['tokens']['total'])
188+ print()
189+ 
190+ 
191+if __name__ == "__main__":
192+ asyncio.run(main())
@@ -0,0 +1,158 @@
1+"""
2+IntelliRouter Web 指标看板 Demo
3+ 
4+启动一个轻量 Web 服务,在浏览器中实时展示路由指标。
5+使用模拟请求,无需真实 API Key。
6+ 
7+使用方式:
8+ python examples/demo_web_dashboard.py
9+ 
10+ 然后浏览器打开 http://localhost:8080
11+"""
12+ 
13+import asyncio
14+import os
15+import random
16+ 
17+from intelli_router import (
18+ ReliableRouter,
19+ Deployment,
20+ EventBus,
21+ MetricsCollector,
22+ MetricsWebServer,
23+)
24+from intelli_router.router.base_router import BaseRouter
25+ 
26+ 
27+# ---------------------------------------------------------------------------
28+# 模拟 Deployments
29+# ---------------------------------------------------------------------------
30+DEPLOYMENTS = [
31+ Deployment(
32+ id="azure-east",
33+ model_name="gpt-4",
34+ provider="openai",
35+ api_key="fake-key-1",
36+ api_base="http://localhost:19999",
37+ ),
38+ Deployment(
39+ id="openai-main",
40+ model_name="gpt-4",
41+ provider="openai",
42+ api_key="fake-key-2",
43+ api_base="http://localhost:19998",
44+ ),
45+ Deployment(
46+ id="anthropic-1",
47+ model_name="claude-3",
48+ provider="anthropic",
49+ api_key="fake-key-3",
50+ api_base="http://localhost:19997",
51+ ),
52+ Deployment(
53+ id="deepseek-1",
54+ model_name="deepseek-chat",
55+ provider="deepseek",
56+ api_key="fake-key-4",
57+ api_base="http://localhost:19996",
58+ ),
59+]
60+ 
61+ 
62+# ---------------------------------------------------------------------------
63+# Mock
64+# ---------------------------------------------------------------------------
65+async def mock_completion(self, model, messages, deployment=None, **kwargs):
66+ if deployment is None:
67+ raise RuntimeError("No deployment")
68+ 
69+ profiles = {
70+ "azure-east": {"latency": (0.2, 0.6), "fail_rate": 0.03},
71+ "openai-main": {"latency": (0.4, 1.2), "fail_rate": 0.08},
72+ "anthropic-1": {"latency": (0.5, 1.5), "fail_rate": 0.12},
73+ "deepseek-1": {"latency": (0.3, 0.9), "fail_rate": 0.06},
74+ }
75+ profile = profiles.get(deployment.id, {"latency": (0.5, 1.0), "fail_rate": 0.1})
76+ 
77+ latency = random.uniform(*profile["latency"])
78+ await asyncio.sleep(latency)
79+ 
80+ if random.random() < profile["fail_rate"]:
81+ errors = ["TimeoutError", "RateLimitError", "ConnectionError", "ServerError"]
82+ raise RuntimeError(random.choice(errors))
83+ 
84+ tokens_prompt = random.randint(50, 300)
85+ tokens_completion = random.randint(20, 200)
86+ return {
87+ "choices": [{"message": {"content": "OK"}, "finish_reason": "stop"}],
88+ "usage": {
89+ "prompt_tokens": tokens_prompt,
90+ "completion_tokens": tokens_completion,
91+ "total_tokens": tokens_prompt + tokens_completion,
92+ },
93+ }
94+ 
95+ 
96+async def main():
97+ port = int(os.environ.get("WEB_PORT", "8080"))
98+ 
99+ print("=" * 60)
100+ print(" IntelliRouter Web Dashboard Demo")
101+ print("=" * 60)
102+ print()
103+ print(f" Web 看板: http://localhost:{port}")
104+ print(" 模拟 4 个 deployment,持续发送请求")
105+ print(" 按 Ctrl+C 退出")
106+ print()
107+ 
108+ # 设置
109+ bus = EventBus()
110+ metrics = MetricsCollector()
111+ bus.register(metrics)
112+ 
113+ server = MetricsWebServer(metrics, port=port)
114+ server.start()
115+ 
116+ router = ReliableRouter(
117+ deployments=DEPLOYMENTS,
118+ strategy="simple-shuffle",
119+ num_retries=2,
120+ event_bus=bus,
121+ )
122+ 
123+ # Monkey-patch
124+ original = BaseRouter.completion
125+ BaseRouter.completion = mock_completion
126+ 
127+ print(f" 服务已启动,请在浏览器中打开: http://localhost:{port}")
128+ print()
129+ 
130+ try:
131+ request_num = 0
132+ while True:
133+ request_num += 1
134+ model = random.choice(["gpt-4", "gpt-4", "claude-3", "deepseek-chat"])
135+ try:
136+ await router.completion(model, [{"role": "user", "content": f"req-{request_num}"}])
137+ except Exception:
138+ pass
139+ await asyncio.sleep(random.uniform(0.1, 0.4))
140+ 
141+ if request_num % 50 == 0:
142+ stats = metrics.get_stats()
143+ print(f" [{request_num} reqs] "
144+ f"success={stats['successful']} "
145+ f"failed={stats['failed']} "
146+ f"retries={stats['retries']} "
147+ f"tokens={stats['tokens']['total']}")
148+ 
149+ except KeyboardInterrupt:
150+ print("\n 停止中...")
151+ finally:
152+ server.stop()
153+ BaseRouter.completion = original
154+ print(" 已退出。")
155+ 
156+ 
157+if __name__ == "__main__":
158+ asyncio.run(main())
Aintelli_router/intelli_router/__init__.py+77-0文件内容审核中,请稍后刷新重试
Binary files do not support preview
Binary files do not support preview
Binary files do not support preview
Binary files do not support preview
Aintelli_router/intelli_router/cache/__init__.py+6-0文件内容审核中,请稍后刷新重试
Binary files do not support preview
Binary files do not support preview
Aintelli_router/intelli_router/cache/local_cache.py+160-0文件内容审核中,请稍后刷新重试
@@ -0,0 +1,8 @@
1+"""
2+SDK LLM Core Module
3+"""
4+from .deployment import Deployment, DeploymentStatus
5+from .state import LocalRouterState, LatencyRecord
6+from .context import RoutingContext
7+ 
8+__all__ = ['Deployment', 'DeploymentStatus', 'LocalRouterState', 'LatencyRecord', 'RoutingContext']
Binary files do not support preview
Binary files do not support preview
Binary files do not support preview
Binary files do not support preview
Binary files do not support preview
Binary files do not support preview
@@ -0,0 +1,81 @@
1+"""
2+SDK LLM Core - 路由上下文
3+ 
4+RoutingContext: 请求级上下文
5+"""
6+from dataclasses import dataclass, field
7+from typing import Optional, List, Dict, Any, TYPE_CHECKING
8+import time
9+ 
10+from .deployment import Deployment
11+ 
12+if TYPE_CHECKING:
13+ from .deployment import DeploymentStatus
14+ 
15+@dataclass
16+class RoutingContext:
17+ """
18+ 路由上下文 - 请求级别
19+ 
20+ Attributes:
21+ model: str 请求模型
22+ messages: List[Dict[str, str]] 消息列表
23+ kwargs: Dict[str, Any] 其他参数
24+ selected_deployment: Optional[Deployment] 选中的部署
25+ attempted_deployments: List[str] 尝试过的部署
26+ start_time: float 开时时间
27+ end_time: Optional[float] 束时间
28+ response: Optional[Any] 果果
29+ error: Optional[Exception] 误
30+ request_tags: List[str] 求签
31+ """
32+ # 请求信息
33+ model: str
34+ messages: List[Dict[str, str]]
35+ kwargs: Dict[str, Any] = field(default_factory=dict)
36+ 
37+ # 路由状态
38+ selected_deployment: Optional[Deployment] = None
39+ attempted_deployments: List[str] = field(default_factory=list)
40+ 
41+ # 时间追踪
42+ start_time: float = field(default_factory=time.time)
43+ end_time: Optional[float] = None
44+ # 结果
45+ response: Optional[Any] = None
46+ error: Optional[Exception] = None
47+ # 标签
48+ request_tags: List[str] = field(default_factory=list)
49+ 
50+ 
51+ def mark_attempt(self, deployment: Deployment) -> None:
52+ """标记尝试过的部署"""
53+ self.attempted_deployments.append(deployment.id)
54+ 
55+ def set_success(self, deployment: Deployment, response: Any) -> None:
56+ """标记成功"""
57+ self.selected_deployment = deployment
58+ self.response = response
59+ self.end_time = time.time()
60+ 
61+ def set_failure(self, error: Exception) -> None:
62+ """标记失败"""
63+ self.error = error
64+ self.end_time = time.time()
65+ 
66+ @property
67+ def latency(self) -> float:
68+ """获取请求延迟"""
69+ if self.end_time is None:
70+ return 0.0
71+ return self.end_time - self.start_time
72+ 
73+ def to_log_dict(self) -> Dict[str, Any]:
74+ """转换为日志字典"""
75+ return {
76+ "model": self.model,
77+ "selected_deployment": self.selected_deployment.id if self.selected_deployment else None,
78+ "latency": self.latency,
79+ "attempted": self.attempted_deployments,
80+ "success": self.error is None,
81+ }
Aintelli_router/intelli_router/core/deployment.py+146-0文件内容审核中,请稍后刷新重试
Aintelli_router/intelli_router/core/state.py+368-0文件内容审核中,请稍后刷新重试
@@ -0,0 +1,6 @@
1+"""
2+SDK LLM Health Module
3+"""
4+from .checker import SDKHealthChecker, HealthCheckResult
5+ 
6+__all__ = ["SDKHealthChecker", "HealthCheckResult"]
Binary files do not support preview
Binary files do not support preview
Aintelli_router/intelli_router/health/checker.py+244-0文件内容审核中,请稍后刷新重试
@@ -0,0 +1,17 @@
1+"""IntelliRouter 可观测性子系统"""
2+from .events import RoutingEvent, RoutingEventType
3+from .handler import EventHandler
4+from .bus import EventBus
5+from .logging_hook import LoggingHook
6+from .metrics import MetricsCollector
7+from .web_dashboard import MetricsWebServer
8+ 
9+__all__ = [
10+ "RoutingEvent",
11+ "RoutingEventType",
12+ "EventHandler",
13+ "EventBus",
14+ "LoggingHook",
15+ "MetricsCollector",
16+ "MetricsWebServer",
17+]
@@ -0,0 +1,51 @@
1+"""事件总线 - 管理 EventHandler 注册和事件分发"""
2+import logging
3+from typing import List
4+ 
5+from .events import RoutingEvent
6+from .handler import EventHandler
7+ 
8+logger = logging.getLogger(__name__)
9+ 
10+ 
11+class EventBus:
12+ """事件总线
13+ 
14+ 管理 EventHandler 的注册和事件分发。
15+ 无 handler 注册时 emit() 几乎零开销。
16+ 事件通过直接 await 分发,单个 handler 异常不影响其他 handler 和路由主路径。
17+ """
18+ 
19+ def __init__(self):
20+ self._handlers: List[EventHandler] = []
21+ 
22+ @property
23+ def handlers(self) -> List[EventHandler]:
24+ """已注册的 handler 列表(只读副本)"""
25+ return list(self._handlers)
26+ 
27+ def register(self, handler: EventHandler) -> None:
28+ """注册一个事件处理器"""
29+ self._handlers.append(handler)
30+ 
31+ def unregister(self, handler: EventHandler) -> None:
32+ """注销一个事件处理器"""
33+ self._handlers.remove(handler)
34+ 
35+ async def emit(self, event: RoutingEvent) -> None:
36+ """分发事件到所有已注册的处理器
37+ 
38+ 每个 handler 依次 await。如果某个 handler 抛异常,
39+ 异常被捕获并记录日志,不会影响后续 handler 或请求路径。
40+ """
41+ if not self._handlers:
42+ return
43+ for handler in self._handlers:
44+ try:
45+ await handler.handle_event(event)
46+ except Exception:
47+ logger.debug(
48+ "EventHandler %s failed for event %s",
49+ handler.name, event.event_type.value,
50+ exc_info=True,
51+ )
Aintelli_router/intelli_router/observability/events.py+99-0文件内容审核中,请稍后刷新重试
@@ -0,0 +1,22 @@
1+"""事件处理器抽象基类"""
2+from abc import ABC, abstractmethod
3+ 
4+from .events import RoutingEvent
5+ 
6+ 
7+class EventHandler(ABC):
8+ """事件处理器基类
9+ 
10+ 用户/集成方实现此接口来处理路由事件。
11+ 实现应避免抛出异常,内部处理错误。
12+ """
13+ 
14+ @abstractmethod
15+ async def handle_event(self, event: RoutingEvent) -> None:
16+ """处理一个路由事件"""
17+ ...
18+ 
19+ @property
20+ def name(self) -> str:
21+ """处理器名称(用于日志标识)"""
22+ return self.__class__.__name__
@@ -0,0 +1,71 @@
1+"""结构化日志事件处理器"""
2+import json
3+import logging
4+from typing import Optional
5+ 
6+from .events import RoutingEvent
7+from .handler import EventHandler
8+ 
9+ 
10+class LoggingHook(EventHandler):
11+ """标准日志 Hook
12+ 
13+ 将路由事件输出到 Python logging 系统。
14+ 支持 JSON 和人类可读文本两种格式。
15+ 
16+ 用法:
17+ hook = LoggingHook() # JSON 格式,INFO 级别
18+ hook = LoggingHook(format="text") # 人类可读文本
19+ hook = LoggingHook(logger_name="my.logger") # 自定义 logger
20+ """
21+ 
22+ def __init__(
23+ self,
24+ logger_name: str = "intelli_router",
25+ level: int = logging.INFO,
26+ format: str = "json",
27+ ):
28+ """
29+ Args:
30+ logger_name: Python logger 名称
31+ level: 日志级别
32+ format: 输出格式 - "json" 或 "text"
33+ """
34+ self._logger = logging.getLogger(logger_name)
35+ self._level = level
36+ self._format = format
37+ 
38+ async def handle_event(self, event: RoutingEvent) -> None:
39+ """将事件格式化并输出到 logger"""
40+ message = self._format_event(event)
41+ self._logger.log(self._level, message)
42+ 
43+ def _format_event(self, event: RoutingEvent) -> str:
44+ if self._format == "json":
45+ return self._format_json(event)
46+ return self._format_text(event)
47+ 
48+ def _format_json(self, event: RoutingEvent) -> str:
49+ return json.dumps(event.to_dict(), ensure_ascii=False)
50+ 
51+ def _format_text(self, event: RoutingEvent) -> str:
52+ parts = [
53+ f"[{event.event_type.value}]",
54+ f"req={event.request_id[:8]}",
55+ f"model={event.model}",
56+ ]
57+ if event.deployment_id:
58+ parts.append(f"dep={event.deployment_id}")
59+ if event.provider:
60+ parts.append(f"provider={event.provider}")
61+ if event.latency is not None:
62+ parts.append(f"lat={event.latency:.3f}s")
63+ if event.total_tokens is not None:
64+ parts.append(f"tokens={event.total_tokens}")
65+ if event.attempt > 0:
66+ parts.append(f"attempt={event.attempt}/{event.total_attempts}")
67+ if event.error_message:
68+ parts.append(f"err={event.error_message}")
69+ if event.chunk_count is not None:
70+ parts.append(f"chunks={event.chunk_count}")
71+ return " ".join(parts)
Aintelli_router/intelli_router/observability/metrics.py+725-0文件内容审核中,请稍后刷新重试
Aintelli_router/intelli_router/observability/web_dashboard.py+469-0文件内容审核中,请稍后刷新重试
Aintelli_router/intelli_router/parser/json_parser.py+106-0文件内容审核中,请稍后刷新重试
Aintelli_router/intelli_router/parser/markdown_parser.py+260-0文件内容审核中,请稍后刷新重试
Aintelli_router/intelli_router/provider/anthropic_provider.py+460-0文件内容审核中,请稍后刷新重试
Aintelli_router/intelli_router/provider/base_provider.py+329-0文件内容审核中,请稍后刷新重试
Aintelli_router/intelli_router/provider/bedrock_provider.py+544-0文件内容审核中,请稍后刷新重试
Aintelli_router/intelli_router/provider/gemini_provider.py+314-0文件内容审核中,请稍后刷新重试
Aintelli_router/intelli_router/router/__init__.py+7-0文件内容审核中,请稍后刷新重试
Aintelli_router/intelli_router/router/base_router.py+490-0文件内容审核中,请稍后刷新重试
Aintelli_router/intelli_router/router/reliable_router.py+1731-0文件内容审核中,请稍后刷新重试
Aintelli_router/intelli_router/types.py+244-0文件内容审核中,请稍后刷新重试
Aintelli_router/intelli_router/utils/exceptions.py+272-0文件内容审核中,请稍后刷新重试
Aintelli_router/tests/test_cache_local_cache.py+232-0文件内容审核中,请稍后刷新重试
Aintelli_router/tests/test_core_deployment.py+269-0文件内容审核中,请稍后刷新重试
Aintelli_router/tests/test_health_checker.py+517-0文件内容审核中,请稍后刷新重试
Aintelli_router/tests/test_observability_events.py+143-0文件内容审核中,请稍后刷新重试
Aintelli_router/tests/test_observability_metrics.py+953-0文件内容审核中,请稍后刷新重试
Aintelli_router/tests/test_observability_web_dashboard.py+566-0文件内容审核中,请稍后刷新重试
Aintelli_router/tests/test_parsers.py+173-0文件内容审核中,请稍后刷新重试
Aintelli_router/tests/test_provider_adapters.py+2193-0文件内容审核中,请稍后刷新重试
Aintelli_router/tests/test_public_api.py+54-0文件内容审核中,请稍后刷新重试
Aintelli_router/tests/test_reliable_router.py+1442-0文件内容审核中,请稍后刷新重试
Aintelli_router/tests/test_router_base_router.py+988-0文件内容审核中,请稍后刷新重试
Aintelli_router/tests/test_router_reliable_router.py+1297-0文件内容审核中,请稍后刷新重试
Aintelli_router/tests/test_router_system.py+590-0文件内容审核中,请稍后刷新重试
Aintelli_router/tests/test_types_streaming.py+186-0文件内容审核中,请稍后刷新重试
Aintelli_router/tests/test_utils_exceptions.py+141-0文件内容审核中,请稍后刷新重试