T-02-core-api.html
20.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>T-02 — 核心 API 服务 — llm-call-platform</title>
<style>
/* === Magic-Vision 设计系统 === */
:root {
--color-primary: #2563eb; --color-primary-light: #dbeafe; --color-primary-dark: #1e40af;
--color-success: #16a34a; --color-success-light: #dcfce7;
--color-warning: #d97706; --color-warning-light: #fef3c7;
--color-danger: #dc2626; --color-danger-light: #fee2e2;
--color-pending: #6b7280; --color-pending-light: #f3f4f6;
--color-bg: #ffffff; --color-bg-secondary: #f8fafc;
--color-border: #e2e8f0; --color-text: #1e293b;
--color-text-secondary: #64748b; --color-text-muted: #94a3b8;
--font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
--font-mono: "SF Mono", "Fira Code", Menlo, Consolas, monospace;
--radius: 8px; --radius-sm: 4px;
--shadow: 0 1px 3px rgba(0,0,0,0.1); --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font-family); background: var(--color-bg-secondary); color: var(--color-text); line-height: 1.6; min-height: 100vh; }
.container { max-width: 1200px; margin: 0 auto; padding: 24px; }
/* 通用组件 */
.badge { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 0.75rem; font-weight: 600; }
.badge-confirmed { background: var(--color-success-light); color: var(--color-success); }
.badge-pending { background: var(--color-pending-light); color: var(--color-pending); }
.badge-doubt { background: var(--color-warning-light); color: var(--color-warning); }
.priority { display: inline-block; padding: 1px 8px; border-radius: 4px; font-size: 0.7rem; font-weight: 700; }
.priority-p0 { background: var(--color-danger-light); color: var(--color-danger); }
.priority-p1 { background: var(--color-warning-light); color: var(--color-warning); }
.priority-p2 { background: var(--color-primary-light); color: var(--color-primary); }
.card { background: var(--color-bg); border: 1px solid var(--color-border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; overflow: hidden; }
.card-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; background: var(--color-bg-secondary); border-bottom: 1px solid var(--color-border); }
.card-title { margin: 0; font-size: 1rem; font-weight: 600; }
.card-body { padding: 20px; }
.accordion { border: 1px solid var(--color-border); border-radius: var(--radius); margin-bottom: 12px; }
.accordion-summary { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; cursor: pointer; font-weight: 600; background: var(--color-bg-secondary); list-style: none; }
.accordion-summary::-webkit-details-marker { display: none; }
.accordion[open] .accordion-summary { border-bottom: 1px solid var(--color-border); }
.accordion-content { padding: 20px; }
.tabs { margin-bottom: 24px; }
.tab-nav { display: flex; gap: 0; border-bottom: 2px solid var(--color-border); margin-bottom: 20px; }
.tab-btn { padding: 10px 20px; border: none; background: none; cursor: pointer; font-size: 0.9rem; font-weight: 500; color: var(--color-text-secondary); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.2s; }
.tab-btn:hover { color: var(--color-text); }
.tab-btn.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.data-table th { padding: 12px 14px; text-align: left; font-weight: 600; background: var(--color-bg-secondary); border-bottom: 2px solid var(--color-border); font-size: 0.78rem; text-transform: uppercase; color: var(--color-text-secondary); }
.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
.data-table tbody tr:hover { background: var(--color-bg-secondary); }
.stack-tag { display: inline-block; padding: 2px 8px; margin: 2px; background: var(--color-primary-light); color: var(--color-primary-dark); border-radius: 4px; font-size: 0.75rem; font-weight: 500; }
.tree { font-family: var(--font-mono); font-size: 0.875rem; line-height: 2; }
.tree-node { padding: 2px 0; }
.tree-children { padding-left: 24px; border-left: 1px dashed var(--color-border); margin-left: 8px; }
.tree-icon { margin-right: 6px; }
.tree-comment { color: var(--color-text-muted); font-size: 0.8rem; font-family: var(--font-family); margin-left: 8px; }
/* 顶部导航栏 */
.top-nav { display: flex; align-items: center; justify-content: space-between; padding: 16px 28px; background: var(--color-bg); border-bottom: 1px solid var(--color-border); box-shadow: var(--shadow); position: sticky; top: 0; z-index: 100; }
.nav-left { display: flex; align-items: center; gap: 8px; }
.nav-title { margin: 0; font-size: 1.25rem; }
.nav-right { display: flex; align-items: center; gap: 12px; }
.nav-version { font-size: 0.85rem; color: var(--color-text-secondary); }
.nav-links { display: flex; align-items: center; gap: 6px; }
.nav-label { font-size: 0.8rem; color: var(--color-text-muted); }
.nav-link { padding: 4px 12px; border-radius: var(--radius-sm); text-decoration: none; font-size: 0.85rem; font-weight: 500; color: var(--color-primary); border: 1px solid var(--color-primary-light); transition: all 0.2s; }
.nav-link:hover { background: var(--color-primary-light); }
.back-link { color: var(--color-text-secondary); text-decoration: none; font-size: 0.85rem; padding: 4px 10px; border-radius: var(--radius-sm); transition: all 0.2s; }
.back-link:hover { color: var(--color-primary); background: var(--color-primary-light); }
/* Hero 标题卡片 */
.hero-card { display: flex; align-items: center; justify-content: space-between; padding: 24px; background: linear-gradient(135deg, var(--color-primary-light) 0%, var(--color-bg) 100%); border: 1px solid var(--color-border); border-radius: var(--radius); box-shadow: var(--shadow-md); margin-bottom: 24px; }
.hero-title { margin: 0 0 8px; font-size: 1.5rem; }
.hero-goal { margin: 0; color: var(--color-text-secondary); font-size: 1rem; }
/* 页脚 */
.footer { text-align: center; padding: 32px; color: var(--color-text-muted); font-size: 0.8rem; }
/* 信息网格 */
.info-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; border: 1px solid var(--color-border); border-radius: var(--radius); overflow: hidden; margin-bottom: 24px; }
.info-item { display: flex; flex-direction: column; padding: 12px 16px; border-bottom: 1px solid var(--color-border); border-right: 1px solid var(--color-border); }
.info-item:nth-child(3n) { border-right: none; }
.info-full { grid-column: 1 / -1; border-right: none; }
.info-label { font-size: 0.72rem; text-transform: uppercase; color: var(--color-text-muted); margin-bottom: 4px; font-weight: 600; letter-spacing: 0.05em; }
.info-value { font-size: 0.9rem; }
.info-value code { font-family: var(--font-mono); background: var(--color-bg-secondary); padding: 1px 6px; border-radius: 3px; font-size: 0.85rem; }
/* 导航中心 */
.nav-card { background: var(--color-bg); border: 1px solid var(--color-border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; overflow: hidden; transition: box-shadow 0.2s; }
.nav-card:hover { box-shadow: var(--shadow-md); }
.nav-card-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 24px; background: var(--color-bg-secondary); border-bottom: 1px solid var(--color-border); }
.nav-card-title { display: flex; align-items: center; gap: 10px; font-size: 1rem; font-weight: 600; }
.nav-card-icon { font-size: 1.2rem; }
.nav-card-date { font-size: 0.75rem; color: var(--color-text-muted); }
.nav-card-body { padding: 8px 0; }
.nav-card-body.empty { padding: 20px 24px; color: var(--color-text-muted); font-style: italic; text-align: center; }
.nav-file-link { display: flex; align-items: center; padding: 8px 24px; text-decoration: none; color: var(--color-text); font-size: 0.9rem; transition: background 0.15s; }
.nav-file-link:hover { background: var(--color-primary-light); color: var(--color-primary); }
.nav-file-link .file-icon { margin-right: 10px; font-size: 0.85rem; flex-shrink: 0; }
.nav-file-link .file-desc { margin-left: auto; font-size: 0.78rem; color: var(--color-text-muted); }
/* Toast */
.toast { position: fixed; bottom: 20px; right: 20px; background: #1f2937; color: #fff; padding: 10px 18px; border-radius: 6px; font-size: 13px; opacity: 0; transition: opacity .2s; z-index: 200; }
.toast.show { opacity: 1; }
/* 交互图 */
.diagram-container { background: var(--color-bg-secondary); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 24px; margin-bottom: 24px; overflow-x: auto; }
.interaction-svg, .flow-svg, .dep-svg { width: 100%; height: auto; }
.node-box { fill: var(--color-bg); stroke-width: 2; }
.node-t01 { stroke: var(--color-primary); }
.node-t02 { stroke: var(--color-success); }
.node-db { stroke: var(--color-warning); }
.node-title { font-size: 0.85rem; font-weight: 700; fill: var(--color-text); }
.node-subtitle { font-size: 0.7rem; fill: var(--color-text-secondary); }
.edge { stroke: var(--color-text-muted); stroke-width: 2; }
.edge-label { font-size: 0.7rem; fill: var(--color-text-secondary); }
/* 技术栈卡片网格 */
.tech-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; margin-bottom: 24px; }
.tech-card { position: relative; padding: 20px; border: 1px solid var(--color-border); border-radius: var(--radius); background: var(--color-bg); box-shadow: var(--shadow); border-top: 3px solid var(--color-pending); }
.tech-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.tech-card.dimension-frontend { border-top-color: var(--color-primary); }
.tech-card.dimension-backend { border-top-color: var(--color-success); }
.tech-card.dimension-database { border-top-color: var(--color-warning); }
.tech-card.dimension-cache { border-top-color: #e11d48; }
.tech-card.dimension-deploy { border-top-color: #7c3aed; }
.tech-card.dimension-disabled { opacity: 0.55; border-top-color: var(--color-border); }
.tech-card-icon { font-size: 1.5rem; margin-bottom: 8px; }
.tech-dimension { margin: 0 0 12px; font-size: 0.95rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-text-secondary); }
.tech-choice, .tech-reason, .tech-alt { font-size: 0.85rem; margin-bottom: 8px; color: var(--color-text); }
.tech-na { font-size: 0.85rem; color: var(--color-text-muted); font-style: italic; }
.tech-card .badge { position: absolute; top: 16px; right: 16px; }
/* 技术栈页面增强 */
.tech-section { margin-bottom: 24px; }
.tech-section-title { display: flex; align-items: center; gap: 8px; font-size: 1.1rem; font-weight: 700; padding: 12px 0; border-bottom: 2px solid var(--color-border); margin-bottom: 16px; color: var(--color-text); }
.tech-card { transition: all 0.2s ease; }
.tech-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.tech-stack-summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 24px; }
.tech-stack-item { display: flex; flex-direction: column; align-items: center; padding: 16px; background: var(--color-bg); border: 1px solid var(--color-border); border-radius: var(--radius); text-align: center; }
.tech-stack-icon { font-size: 1.8rem; margin-bottom: 6px; }
.tech-stack-name { font-size: 0.85rem; font-weight: 600; color: var(--color-text); }
.tech-stack-role { font-size: 0.72rem; color: var(--color-text-muted); }
/* 变更记录 */
.changelog-card { border: 1px solid var(--color-border); border-radius: var(--radius); margin-bottom: 16px; overflow: hidden; box-shadow: var(--shadow); }
.changelog-header { display: flex; align-items: center; gap: 12px; padding: 14px 20px; background: var(--color-bg-secondary); border-bottom: 1px solid var(--color-border); }
.changelog-date { font-family: var(--font-mono); font-size: 0.82rem; color: var(--color-primary); font-weight: 600; white-space: nowrap; }
.changelog-tag { display: inline-block; padding: 2px 10px; border-radius: 10px; font-size: 0.7rem; font-weight: 600; }
.changelog-tag-add { background: var(--color-success-light); color: var(--color-success); }
.changelog-tag-modify { background: var(--color-warning-light); color: var(--color-warning); }
.changelog-tag-delete { background: var(--color-danger-light); color: var(--color-danger); }
.changelog-body { padding: 14px 20px; }
.changelog-desc { font-size: 0.9rem; line-height: 1.7; }
.changelog-scope { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.changelog-scope-item { padding: 2px 10px; background: var(--color-primary-light); color: var(--color-primary); border-radius: 4px; font-size: 0.75rem; font-weight: 500; }
.changelog-empty { text-align: center; padding: 40px; color: var(--color-text-muted); font-style: italic; }
</style>
</head>
<body>
<nav class="top-nav">
<div class="nav-left">
<a href="../index.html" class="back-link" title="返回文档导航中心">🏠 导航</a>
<a href="overview.html" class="back-link">← 返回总览</a>
<h1 class="nav-title"><span class="tech-id">T-02</span> 核心 API 服务</h1>
</div>
<div class="nav-right">
<span class="badge badge-confirmed">已确认</span>
</div>
</nav>
<main class="container">
<div class="hero-card">
<div class="hero-left">
<h2 class="hero-title"><span class="tech-id" style="font-size:1.1em;margin-right:8px">T-02</span> 核心 API 服务</h2>
<p class="hero-goal"><strong>实现目标:</strong>基于 FastAPI 的 REST API 服务,提供 LLM 同步/异步调用入口、任务编排、调用策略调度、统计查询等核心能力</p>
</div>
</div>
<div class="tabs">
<div class="tab-nav">
<button class="tab-btn active" onclick="switchTab(event, 'tab-tech')">技术栈</button>
<button class="tab-btn" onclick="switchTab(event, 'tab-modules')">功能覆盖</button>
<button class="tab-btn" onclick="switchTab(event, 'tab-note')">方案说明</button>
<button class="tab-btn" onclick="switchTab(event, 'tab-changelog')">📋 变更记录</button>
</div>
<div class="tab-content active" id="tab-tech">
<div class="tech-section">
<div class="tech-section-title">技术栈</div>
<div class="tech-grid">
<div class="tech-card dimension-backend">
<div class="tech-card-icon">⚙️</div>
<div class="tech-dimension">后端</div>
<div class="tech-choice"><strong>选型:</strong>Python 3.11+ FastAPI</div>
<div class="tech-reason"><strong>理由:</strong>用户确认 — 异步原生支持,自动生成 OpenAPI 文档,高性能(基于 Starlette + Uvicorn)</div>
<div class="tech-alt"><strong>备选:</strong>Flask + 扩展、Django REST Framework</div>
</div>
<div class="tech-card dimension-backend">
<div class="tech-card-icon">🔌</div>
<div class="tech-dimension">API 风格</div>
<div class="tech-choice"><strong>选型:</strong>RESTful API</div>
<div class="tech-reason"><strong>理由:</strong>用户确认 — 通用性强,FastAPI 原生支持,对外友好</div>
<div class="tech-alt"><strong>备选:</strong>gRPC、GraphQL</div>
</div>
<div class="tech-card dimension-backend">
<div class="tech-card-icon">🗄️</div>
<div class="tech-dimension">ORM</div>
<div class="tech-choice"><strong>选型:</strong>SQLAlchemy 2.0 + async(aiomysql)</div>
<div class="tech-reason"><strong>理由:</strong>用户确认 — 成熟稳定,原生 async/await 支持,与 FastAPI 配合良好</div>
<div class="tech-alt"><strong>备选:</strong>SQLModel、Django ORM</div>
</div>
<div class="tech-card dimension-backend">
<div class="tech-card-icon">🔐</div>
<div class="tech-dimension">认证方式</div>
<div class="tech-choice"><strong>选型:</strong>JWT(PyJWT)</div>
<div class="tech-reason"><strong>理由:</strong>用户确认 — 无状态 Token 认证,适合 API 服务</div>
<div class="tech-alt"><strong>备选:</strong>FastAPI OAuth2、内网信任模式</div>
</div>
<div class="tech-card dimension-deploy">
<div class="tech-card-icon">📦</div>
<div class="tech-dimension">部署</div>
<div class="tech-choice"><strong>选型:</strong>Docker + Nginx 容器化部署</div>
<div class="tech-reason"><strong>理由:</strong>用户确认 — 与前端统一容器化管理,Nginx 反向代理</div>
<div class="tech-alt"><strong>备选:</strong>裸机部署 systemd</div>
</div>
</div>
</div>
</div>
<div class="tab-content" id="tab-modules">
<table class="data-table module-table">
<thead><tr><th>编号</th><th>功能名称</th><th>需求描述</th><th>优先级</th><th>主表</th><th>备注</th></tr></thead>
<tbody>
<tr>
<td>F-08</td>
<td>同步模型调用</td>
<td>POST /api/v1/calls/sync — 接收调用请求,实时调用模型并返回结果,支持 6 种模板类型</td>
<td><span class="priority priority-p0">P0</span></td>
<td>call_service.py</td>
<td></td>
</tr>
<tr>
<td>F-09</td>
<td>异步模型调用</td>
<td>POST /api/v1/calls/async — 提交异步任务,返回 taskId,通过 Celery 异步处理</td>
<td><span class="priority priority-p0">P0</span></td>
<td>call_service.py</td>
<td></td>
</tr>
<tr>
<td>F-10</td>
<td>任务结果查询</td>
<td>GET /api/v1/calls/{task_id} — 查询异步任务的执行状态和结果</td>
<td><span class="priority priority-p0">P0</span></td>
<td>call_service.py</td>
<td></td>
</tr>
<tr>
<td>F-11</td>
<td>批量任务查询</td>
<td>POST /api/v1/calls/batch — 批量查询多个任务的执行结果</td>
<td><span class="priority priority-p1">P1</span></td>
<td>call_service.py</td>
<td></td>
</tr>
<tr>
<td>F-12</td>
<td>模型配置管理 API</td>
<td>CRUD 接口管理模型账号配置、调用策略配置、提示词模板</td>
<td><span class="priority priority-p0">P0</span></td>
<td>config_routes.py</td>
<td></td>
</tr>
<tr>
<td>F-13</td>
<td>调用统计 API</td>
<td>按时间/模型/状态维度聚合调用次数、成功率、Token 消耗等统计数据</td>
<td><span class="priority priority-p1">P1</span></td>
<td>statistics_service.py</td>
<td></td>
</tr>
<tr>
<td>F-14</td>
<td>调用日志查询 API</td>
<td>多维度检索调用日志,支持分页、模糊搜索、时间范围筛选</td>
<td><span class="priority priority-p0">P0</span></td>
<td>log_routes.py</td>
<td></td>
</tr>
<tr>
<td>F-15</td>
<td>JWT 认证中间件</td>
<td>统一的 JWT Token 校验,白名单接口放行,过期自动刷新</td>
<td><span class="priority priority-p1">P1</span></td>
<td>core/auth.py</td>
<td></td>
</tr>
</tbody>
</table>
</div>
<div class="tab-content" id="tab-note">
<div class="card">
<div class="card-body"><p>采用 <strong>FastAPI + SQLAlchemy 2.0 async + JWT 认证</strong> 的 Python 后端服务。对外暴露 RESTful API,支持同步直接调用和异步任务提交两种模式。内部集成 T-03 LLM 适配引擎,通过工厂模式创建模型适配器。异步任务通过 Celery 提交到 T-04 调度器处理。所有调用记录写入 T-05 数据存储层。</p><p>借鉴现有 Java 项目的设计经验:保留 6 种模板类型(通用/质检/图像/带参/录音总结/员工复盘)的业务模式,但用 Python 重新实现,并通过可配置策略增强灵活性。</p></div>
</div>
</div>
<div class="tab-content" id="tab-changelog">
<div class="card">
<div class="card-header"><h3 class="card-title">📋 变更记录</h3></div>
<div class="card-body">
<div class="changelog-empty">暂无变更记录</div>
</div>
</div>
</div>
</div>
</main>
<footer class="footer">Magic-Vision-Spec · T-02 核心 API 服务 · v1.0</footer>
<script>
function switchTab(event, tabId) {
document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
event.target.classList.add('active');
document.getElementById(tabId).classList.add('active');
}
</script>
</body>
</html>