refactor: 重构 inference 模块架构,引入设计模式并分组文件

- 新增 protocol.py 协议层,Template Method 模式消除流/非流分支 45% 重复
- SSEBuilder 统一 SSE 构造,StopChecker 独立 stop_sequence 检测
- AnthropicHandler 追踪已产出文本,修复 stop 时重复 delta
- server.py 路由从约 100 行缩减至 3 行
- 拆分为 core/(cache/executor/scheduler/task)和 api/(protocol/server)
- 外部保持二级导入路径(from astrai.inference import Name)
- 删除所有分隔线注释,代码按语义自然分组
This commit is contained in:
2026-05-14 17:42:37 +08:00
parent 466c2e1efd
commit 2196c34c52
21 changed files with 743 additions and 485 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ from typing import Any, Dict
import torch
from astrai.config import ModelConfig
from astrai.inference.cache import PagedCache
from astrai.inference import PagedCache
from astrai.model.transformer import Transformer
+1 -1
View File
@@ -3,7 +3,7 @@ from pathlib import Path
import torch
from astrai.inference.server import run_server
from astrai.inference import run_server
def main():