feat: 新增学习引导提示词与任务类型

This commit is contained in:
2026-10-09 19:26:50 +08:00
parent e359e58ff2
commit fb3c6f9933
4 changed files with 67 additions and 5 deletions
+10 -2
View File
@@ -14,12 +14,12 @@
import { randomUUID, createHash } from "node:crypto";
import { chat, isAvailable, loadConfig, LlmError, type ChatMessage } from "./llm/client.js";
import { withRetry, isRetryableLlmError, type RetryOptions } from "./llm/retry.js";
import { aggregateReportPrompt, compareRecallPrompt, generateMindMapPrompt } from "./llm/prompts.js";
import { aggregateReportPrompt, compareRecallPrompt, generateMindMapPrompt, guidancePrompt } from "./llm/prompts.js";
import { logStore } from "./admin/store.js";
// ---- 类型 ----
export type TaskType = "aggregate-report" | "generate-mind-map" | "compare-recall";
export type TaskType = "aggregate-report" | "generate-mind-map" | "compare-recall" | "guidance";
export type TaskStatus = "pending" | "running" | "done" | "failed";
@@ -381,6 +381,7 @@ export class TaskQueue {
function callOptionsFor(type: TaskType): { temperature: number; maxTokens: number } {
if (type === "compare-recall") return { temperature: 0.2, maxTokens: 4096 };
if (type === "generate-mind-map") return { temperature: 0.3, maxTokens: 4096 };
if (type === "guidance") return { temperature: 0.7, maxTokens: 1024 };
return { temperature: 0.3, maxTokens: 2048 };
}
@@ -429,6 +430,9 @@ export function parseResult(type: TaskType, raw: string, model = ""): unknown {
if (type === "generate-mind-map") {
return { outline: text, model };
}
if (type === "guidance") {
return { reply: text, model };
}
const clean = text.replace(/^```(?:json)?\s*/, "").replace(/\s*```$/, "");
return JSON.parse(clean);
}
@@ -453,6 +457,10 @@ export function buildMessages(task: TaskRecord): ChatMessage[] {
fragments ?? [],
);
}
case "guidance": {
const history = (p.history as ChatMessage[] | undefined) ?? [];
return guidancePrompt(p.taskName as string, p.concept as string, history);
}
case "compare-recall": {
return compareRecallPrompt(
p.taskName as string,