refactor: 后端从 Django 换成 Bun + SQLite
Django 多个 worker 内存占用 1-2 GB,换成 Bun 单进程后约 25 MB, 同时去掉 Postgres 和 Redis,只剩 Caddy + Bun 两个容器。 - server/:Hono + bun:sqlite + Bun 原生 WebSocket,接口与原 django-ninja 保持兼容;表结构、时间/UUID 存储格式、密码哈希与 Django 一致,旧数据可直接使用 - 评分加权、贝叶斯平滑、成绩册的计算结果与原实现逐位一致(复刻 Python round/sum) - scripts/:Postgres → SQLite 迁移、新建超管、提示词层级标注、重算分数 - 前端:Django Admin 去掉后,用户新建/修改改为页面内弹窗; 非超管的挑战公开按钮置灰 - 权限不足返回 JSON 403(原来是重定向到不存在的登录页) - docker-compose / Caddyfile / dev.sh / CLAUDE.md 更新,删除 AGENTS.md - 服务器切换步骤见 docs/migrate-to-bun.md Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
47d4679984
commit
26f05d1d76
297 files changed
+4659
-42956
No files matched your search
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* 用大模型给学生提示词标注布鲁姆认知层级(L1-L6)。
|
||||
*
|
||||
* bun scripts/classify-prompts.ts [--task-id N] [--force] [--dry-run]
|
||||
*
|
||||
* 默认只处理还没有层级的用户消息;--force 重新标注全部。
|
||||
*/
|
||||
import { parseArgs } from "node:util"
|
||||
import { all } from "../src/db"
|
||||
import { classifyMessage } from "../src/services/classifier"
|
||||
import { llmConfigured } from "../src/services/llm"
|
||||
|
||||
const { values } = parseArgs({
|
||||
options: {
|
||||
"task-id": { type: "string" },
|
||||
force: { type: "boolean", default: false },
|
||||
"dry-run": { type: "boolean", default: false },
|
||||
},
|
||||
})
|
||||
|
||||
const where = ["m.role = 'user'"]
|
||||
const params: Record<string, unknown> = {}
|
||||
if (values["task-id"]) {
|
||||
where.push("c.task_id = $task_id")
|
||||
params.task_id = Number(values["task-id"])
|
||||
}
|
||||
if (!values.force) where.push("m.prompt_level IS NULL")
|
||||
|
||||
const ids = all<{ id: number }>(
|
||||
`SELECT m.id FROM prompt_message m JOIN prompt_conversation c ON c.id = m.conversation_id
|
||||
WHERE ${where.join(" AND ")} ORDER BY m.created, m.id`,
|
||||
params,
|
||||
).map((r) => r.id)
|
||||
|
||||
console.log(`找到 ${ids.length} 条消息需要标注`)
|
||||
if (values["dry-run"]) process.exit(0)
|
||||
if (!llmConfigured()) {
|
||||
console.error("没有配置 LLM_API_KEY")
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
for (const [i, id] of ids.entries()) {
|
||||
const level = await classifyMessage(id)
|
||||
console.log(`[${i + 1}/${ids.length}] msg#${id} → ${level ? `L${level}` : "(跳过)"}`)
|
||||
await Bun.sleep(300)
|
||||
}
|
||||
console.log("完成")
|
||||
Reference in new issue
Block a user