提示词修改

This commit is contained in:
fengxiangdebaozi committed 2026-05-14 10:51:29 +08:00
1 parent c79f5c5a7a
commit a7f1e89ce9
6 files changed
+389 -27

No files matched your search

@@ -0,0 +1,58 @@
import { useCallback, useSyncExternalStore } from "react";
import {
DEFAULT_QUESTIONS,
getRecommendedQuestions,
saveRecommendedQuestions,
type RecommendedQuestion,
} from "./index";
type Listener = () => void;
const listeners = new Set<Listener>();
let cached: RecommendedQuestion[] | null = null;
function getSnapshot(): RecommendedQuestion[] {
if (cached === null) {
cached = getRecommendedQuestions();
}
return cached;
}
function getServerSnapshot(): RecommendedQuestion[] {
return DEFAULT_QUESTIONS;
}
function subscribe(listener: Listener): () => void {
listeners.add(listener);
return () => listeners.delete(listener);
}
function emitChange() {
for (const l of listeners) l();
}
export function updateRecommendedQuestions(
questions: RecommendedQuestion[],
): void {
cached = questions;
saveRecommendedQuestions(questions);
emitChange();
}
export function useRecommendedQuestions(): [
RecommendedQuestion[],
(questions: RecommendedQuestion[]) => void,
] {
const questions = useSyncExternalStore(
subscribe,
getSnapshot,
getServerSnapshot,
);
const save = useCallback((qs: RecommendedQuestion[]) => {
updateRecommendedQuestions(qs);
}, []);
return [questions, save];
}
@@ -0,0 +1,57 @@
export interface RecommendedQuestion {
id: string;
title: string;
content: string;
}
const STORAGE_KEY = "deerflow.recommended-questions";
export const DEFAULT_QUESTIONS: RecommendedQuestion[] = [
{
id: "default-1",
title: "市场分析报告",
content:
"请帮我写一份关于当前 AI 市场的详细分析报告,包括市场规模、主要玩家和发展趋势。",
},
{
id: "default-2",
title: "制定学习计划",
content:
"请帮我制定一个为期 3 个月的 Python 编程学习计划,从基础到进阶,每周安排具体任务。",
},
{
id: "default-3",
title: "代码审查建议",
content:
"请帮我审查代码,找出潜在的问题、性能瓶颈以及改进建议,并给出修改示例。",
},
{
id: "default-4",
title: "数据分析方案",
content:
"请帮我设计一个用于分析用户行为数据的方案,包括数据收集、处理和可视化策略。",
},
{
id: "default-5",
title: "文章润色优化",
content: "请帮我润色以下文章,使其更加流畅、专业,并保持原意不变。",
},
];
export function getRecommendedQuestions(): RecommendedQuestion[] {
if (typeof window === "undefined") return DEFAULT_QUESTIONS;
const json = localStorage.getItem(STORAGE_KEY);
if (!json) return DEFAULT_QUESTIONS;
try {
const parsed = JSON.parse(json) as RecommendedQuestion[];
if (Array.isArray(parsed) && parsed.length > 0) return parsed;
} catch {}
return DEFAULT_QUESTIONS;
}
export function saveRecommendedQuestions(
questions: RecommendedQuestion[],
): void {
if (typeof window === "undefined") return;
localStorage.setItem(STORAGE_KEY, JSON.stringify(questions));
}