旧后端在消息保存后自动分类,改写成 Bun 时漏了:只有外部 AI 版本和手动提交带的提示词会分类, 学生在 AI 对话和引导里发的提问都没有层级。现在回复存库后在后台分类(失败或断开的提问不分类)。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9f3f7187e1
commit
9fee688d95
2 files changed
+29
-4
No files matched your search
+8
-2
@@ -15,6 +15,7 @@ import {
|
||||
userFacingError,
|
||||
type ChatMessage,
|
||||
} from "./services/llm"
|
||||
import { classifyMessage, inBackground } from "./services/classifier"
|
||||
|
||||
type Kind = "prompt" | "guidance"
|
||||
|
||||
@@ -116,11 +117,12 @@ async function handlePrompt(ws: WS, data: any) {
|
||||
const model = String(data.model ?? "")
|
||||
if (!prompt) return
|
||||
|
||||
ws.data.pendingUserMessageId = insertMessage({
|
||||
const userMessageId = insertMessage({
|
||||
conversation_id: ws.data.conversationId,
|
||||
role: "user",
|
||||
content: prompt,
|
||||
})
|
||||
ws.data.pendingUserMessageId = userMessageId
|
||||
try {
|
||||
const history: ChatMessage[] = conversationHistory(ws.data.conversationId).map((m) => ({
|
||||
role: m.role as ChatMessage["role"],
|
||||
@@ -146,6 +148,8 @@ async function handlePrompt(ws: WS, data: any) {
|
||||
code_css: code.css,
|
||||
code_js: code.js,
|
||||
})
|
||||
// 有了回复,这条提问才留下来;在后台打 L1–L6 层级
|
||||
inBackground(classifyMessage(userMessageId))
|
||||
ws.data.pendingUserMessageId = null
|
||||
send(ws, { type: "complete", code, message_id: messageId })
|
||||
} finally {
|
||||
@@ -157,12 +161,13 @@ async function handleGuidance(ws: WS, data: any) {
|
||||
const prompt = String(data.content ?? "").trim()
|
||||
if (!prompt) return
|
||||
|
||||
ws.data.pendingUserMessageId = insertMessage({
|
||||
const userMessageId = insertMessage({
|
||||
conversation_id: ws.data.conversationId,
|
||||
role: "user",
|
||||
content: prompt,
|
||||
source: "guidance",
|
||||
})
|
||||
ws.data.pendingUserMessageId = userMessageId
|
||||
ws.data.guidanceHistory.push({ role: "user", content: prompt })
|
||||
try {
|
||||
let full: string
|
||||
@@ -185,6 +190,7 @@ async function handleGuidance(ws: WS, data: any) {
|
||||
content: clean,
|
||||
source: "guidance",
|
||||
})
|
||||
inBackground(classifyMessage(userMessageId))
|
||||
ws.data.pendingUserMessageId = null
|
||||
send(ws, { type: "complete", message_id: messageId, is_ready: isReady })
|
||||
} finally {
|
||||
|
||||
Reference in new issue
Block a user