Skip to content

Commit d6a945c

Browse files
committed
feat: sync model catalog and update admin/chat flows
1 parent 6a4ba09 commit d6a945c

28 files changed

Lines changed: 600 additions & 105 deletions

.github/workflows/cloudflare-workers.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,23 @@ permissions:
2222
contents: read
2323

2424
jobs:
25+
validate-model-catalog:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
31+
- name: Setup Python
32+
uses: actions/setup-python@v5
33+
with:
34+
python-version: "3.12"
35+
36+
- name: Verify model catalog consistency
37+
run: python scripts/check_model_catalog_sync.py
38+
2539
deploy-cloudflare:
2640
if: ${{ (github.event_name == 'workflow_dispatch' && (github.event.inputs.deploy_target == 'cloudflare' || github.event.inputs.deploy_target == 'both')) || (github.event_name == 'push' && github.ref == 'refs/heads/main') }}
41+
needs: validate-model-catalog
2742
runs-on: ubuntu-latest
2843
steps:
2944
- name: Checkout
@@ -222,6 +237,7 @@ jobs:
222237

223238
build-docker:
224239
if: ${{ (github.event_name == 'workflow_dispatch' && (github.event.inputs.deploy_target == 'docker' || github.event.inputs.deploy_target == 'both')) || (github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))) }}
240+
needs: validate-model-catalog
225241
runs-on: ubuntu-latest
226242
permissions:
227243
contents: read

README.cloudflare.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
- **KV**:缓存 `/images/*` 的图片/视频资源(从 `assets.grok.com` 代理抓取)
1212
- **每天 0 点统一清除**:通过 KV `expiration` + Workers Cron 定时清理元数据(`wrangler.toml` 已配置,默认按北京时间 00:00)
1313
- **前端移动端适配一致生效**:Workers 与 FastAPI/Docker 复用同一套 `/static/*` 资源,包含手机端抽屉导航、表格横向滚动、API Key 居中悬浮新增弹窗等交互
14+
- **模型集合与主 README 对齐**:严格移除旧模型名并同步新增模型(含 `grok-4.20-beta`
15+
- **聊天重试能力一致生效**`/chat``/admin/chat` 支持“重试上一条回答”与“图片加载失败点击重试”
1416

1517
> 原 Python/FastAPI 版本仍保留用于本地/Docker;Cloudflare 部署请按本文件走 Worker 版本。
1618
@@ -143,6 +145,19 @@ python scripts/smoke_test.py --base-url https://<你的域名或workers.dev>
143145
3. `wrangler d1 migrations apply DB --remote --config wrangler.ci.toml`
144146
4. `wrangler deploy`
145147

148+
### 仓库级部署自检(建议)
149+
150+
在触发一键部署前,可先在仓库根目录运行:
151+
152+
```bash
153+
uv run pytest -q
154+
npm run typecheck
155+
python scripts/check_model_catalog_sync.py
156+
npx wrangler deploy --dry-run --config wrangler.toml
157+
docker compose -f docker-compose.yml config
158+
docker compose -f docker-compose.yml -f docker-compose.build.yml config
159+
```
160+
146161
触发策略保持不变:
147162
- `push``main`:自动触发 Cloudflare 部署作业
148163
- `workflow_dispatch`:可手动选择 `cloudflare/docker/both`
@@ -194,7 +209,7 @@ python scripts/smoke_test.py --base-url https://<你的域名或workers.dev>
194209
## 8) 接口
195210

196211
- POST /v1/chat/completions (supports stream: true)
197-
- GET /v1/models
212+
- GET /v1/models (model set aligns with `readme.md`, including latest additions/removals)
198213
- GET /v1/images/method: returns current image-generation mode (legacy or imagine_ws_experimental) for /chat and /admin/chat UI switching
199214
- POST /v1/images/generations: experimental mode supports size (aspect-ratio mapping) and concurrency (1..3)
200215
- POST /v1/images/edits: only accepts grok-imagine-1.0-edit

app/services/grok/imagine_generation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ def resolve_aspect_ratio(size: Optional[str]) -> str:
2727
"720x1280": "9:16",
2828
"864x1536": "9:16",
2929
"1024x1536": "2:3",
30+
"1024x1792": "2:3",
3031
"512x768": "2:3",
3132
"768x1024": "2:3",
3233
"1536x1024": "3:2",
34+
"1792x1024": "3:2",
3335
"768x512": "3:2",
3436
"1024x768": "3:2",
3537
}

app/services/grok/model.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,41 +45,49 @@ class ModelService:
4545
model_id="grok-3",
4646
grok_model="grok-3",
4747
rate_limit_model="grok-3",
48-
model_mode="MODEL_MODE_AUTO",
48+
model_mode="MODEL_MODE_GROK_3",
4949
cost=Cost.LOW,
5050
display_name="Grok 3"
5151
),
5252
ModelInfo(
53-
model_id="grok-3-fast",
53+
model_id="grok-3-mini",
5454
grok_model="grok-3",
5555
rate_limit_model="grok-3",
56+
model_mode="MODEL_MODE_GROK_3_MINI_THINKING",
5657
cost=Cost.LOW,
57-
model_mode="MODEL_MODE_FAST",
58-
display_name="Grok 3 Fast"
58+
display_name="Grok 3 Mini"
59+
),
60+
ModelInfo(
61+
model_id="grok-3-thinking",
62+
grok_model="grok-3",
63+
rate_limit_model="grok-3",
64+
model_mode="MODEL_MODE_GROK_3_THINKING",
65+
cost=Cost.LOW,
66+
display_name="Grok 3 Thinking"
5967
),
6068
ModelInfo(
6169
model_id="grok-4",
6270
grok_model="grok-4",
6371
rate_limit_model="grok-4",
64-
model_mode="MODEL_MODE_AUTO",
72+
model_mode="MODEL_MODE_GROK_4",
6573
cost=Cost.LOW,
6674
display_name="Grok 4"
6775
),
6876
ModelInfo(
6977
model_id="grok-4-mini",
70-
grok_model="grok-4-mini-thinking-tahoe",
71-
rate_limit_model="grok-4-mini-thinking-tahoe",
78+
grok_model="grok-4-mini",
79+
rate_limit_model="grok-4-mini",
7280
model_mode="MODEL_MODE_GROK_4_MINI_THINKING",
7381
cost=Cost.LOW,
7482
display_name="Grok 4 Mini"
7583
),
7684
ModelInfo(
77-
model_id="grok-4-fast",
85+
model_id="grok-4-thinking",
7886
grok_model="grok-4",
7987
rate_limit_model="grok-4",
80-
model_mode="MODEL_MODE_FAST",
88+
model_mode="MODEL_MODE_GROK_4_THINKING",
8189
cost=Cost.LOW,
82-
display_name="Grok 4 Fast"
90+
display_name="Grok 4 Thinking"
8391
),
8492
ModelInfo(
8593
model_id="grok-4-heavy",
@@ -91,12 +99,12 @@ class ModelService:
9199
display_name="Grok 4 Heavy"
92100
),
93101
ModelInfo(
94-
model_id="grok-4.1",
102+
model_id="grok-4.1-mini",
95103
grok_model="grok-4-1-thinking-1129",
96104
rate_limit_model="grok-4-1-thinking-1129",
97-
model_mode="MODEL_MODE_AUTO",
105+
model_mode="MODEL_MODE_GROK_4_1_MINI_THINKING",
98106
cost=Cost.LOW,
99-
display_name="Grok 4.1"
107+
display_name="Grok 4.1 Mini"
100108
),
101109
ModelInfo(
102110
model_id="grok-4.1-fast",
@@ -111,7 +119,7 @@ class ModelService:
111119
grok_model="grok-4-1-thinking-1129",
112120
rate_limit_model="grok-4-1-thinking-1129",
113121
model_mode="MODEL_MODE_EXPERT",
114-
cost=Cost.LOW,
122+
cost=Cost.HIGH,
115123
display_name="Grok 4.1 Expert"
116124
),
117125
ModelInfo(
@@ -122,6 +130,14 @@ class ModelService:
122130
cost=Cost.HIGH,
123131
display_name="Grok 4.1 Thinking"
124132
),
133+
ModelInfo(
134+
model_id="grok-4.20-beta",
135+
grok_model="grok-420",
136+
rate_limit_model="grok-420",
137+
model_mode="MODEL_MODE_GROK_420",
138+
cost=Cost.LOW,
139+
display_name="Grok 4.20 Beta"
140+
),
125141
ModelInfo(
126142
model_id="grok-imagine-1.0",
127143
grok_model="grok-3",

app/static/cache/cache.html

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,11 @@ <h2 class="text-2xl font-semibold tracking-tight">缓存管理</h2>
197197
</dialog>
198198

199199
<script src="/static/common/admin-auth.js?v=3"></script>
200-
<script src="/static/common/header.js?v=3"></script>
200+
<script src="/static/common/header.js?v=4"></script>
201201
<script src="/static/common/footer.js?v=1"></script>
202202
<script src="/static/common/toast.js"></script>
203203
<script src="/static/cache/cache.js?v=5"></script>
204204
<script src="/static/common/draggable.js"></script>
205205
</body>
206206

207207
</html>
208-
209-
210-

app/static/chat/chat.css

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,34 @@
9595
margin-top: 8px;
9696
}
9797

98+
.msg-actions {
99+
margin-top: 10px;
100+
display: flex;
101+
justify-content: flex-end;
102+
}
103+
104+
.chat-retry-btn {
105+
border: 1px solid var(--border);
106+
border-radius: 9999px;
107+
background: #fff;
108+
color: var(--accents-7);
109+
font-size: 12px;
110+
line-height: 1;
111+
padding: 6px 10px;
112+
transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
113+
}
114+
115+
.chat-retry-btn:hover {
116+
border-color: #000;
117+
color: #000;
118+
background: rgba(0, 0, 0, 0.02);
119+
}
120+
121+
.chat-retry-btn:disabled {
122+
opacity: 0.6;
123+
cursor: not-allowed;
124+
}
125+
98126
.composer {
99127
margin-top: 12px;
100128
border-top: 1px solid var(--border);
@@ -180,6 +208,44 @@
180208
display: block;
181209
}
182210

211+
.img-retry {
212+
width: 100%;
213+
min-height: 120px;
214+
border: 1px dashed var(--border);
215+
border-radius: 12px;
216+
background: rgba(0, 0, 0, 0.02);
217+
color: var(--accents-5);
218+
font-size: 12px;
219+
display: inline-flex;
220+
align-items: center;
221+
justify-content: center;
222+
text-align: center;
223+
padding: 12px;
224+
cursor: pointer;
225+
transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
226+
}
227+
228+
.img-retry:hover {
229+
border-color: #000;
230+
color: #000;
231+
background: rgba(0, 0, 0, 0.04);
232+
}
233+
234+
.img-retry.loading {
235+
opacity: 0.72;
236+
cursor: wait;
237+
}
238+
239+
.msg-bubble .img-retry {
240+
margin-top: 8px;
241+
}
242+
243+
.result-card .img-retry,
244+
.waterfall-item .img-retry {
245+
min-height: 180px;
246+
border-radius: 0;
247+
}
248+
183249
.result-placeholder {
184250
min-height: 140px;
185251
display: flex;

app/static/chat/chat.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<link href="https://cdn.jsdelivr.net/npm/geist@1.0.0/dist/fonts/geist-sans/style.css" rel="stylesheet">
1111
<link href="https://cdn.jsdelivr.net/npm/geist@1.0.0/dist/fonts/geist-mono/style.css" rel="stylesheet">
1212
<link href="/static/common/common.css?v=3" rel="stylesheet">
13-
<link href="/static/chat/chat.css?v=3" rel="stylesheet">
13+
<link href="/static/chat/chat.css?v=4" rel="stylesheet">
1414
<link href="/static/common/toast.css" rel="stylesheet">
1515
</head>
1616

@@ -199,7 +199,7 @@
199199
</main>
200200

201201
<script src="/static/common/toast.js"></script>
202-
<script src="/static/chat/chat.js?v=4"></script>
202+
<script src="/static/chat/chat.js?v=5"></script>
203203
</body>
204204

205205
</html>

0 commit comments

Comments
 (0)