From 9d1d6c40884651aeba5d08f65c8a82d2fdc030d8 Mon Sep 17 00:00:00 2001 From: hanle Date: Thu, 12 Mar 2026 18:01:35 +0800 Subject: [PATCH] feat: add custom instructions feature to AIPolishDialog --- src/components/shared/ai/AIPolishDialog.tsx | 44 ++++++++++++++++++--- src/i18n/locales/en.json | 4 ++ src/i18n/locales/zh.json | 4 ++ src/routes/api/polish.ts | 9 ++++- 4 files changed, 54 insertions(+), 7 deletions(-) diff --git a/src/components/shared/ai/AIPolishDialog.tsx b/src/components/shared/ai/AIPolishDialog.tsx index 7244d3b..3bd47a9 100644 --- a/src/components/shared/ai/AIPolishDialog.tsx +++ b/src/components/shared/ai/AIPolishDialog.tsx @@ -16,6 +16,8 @@ import { DialogTitle } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; +import { Label } from "@/components/ui/label"; +import { Textarea } from "@/components/ui/textarea"; import { useAIConfigStore } from "@/store/useAIConfigStore"; import { AI_MODEL_CONFIGS } from "@/config/ai"; import { cn } from "@/lib/utils"; @@ -49,6 +51,7 @@ export default function AIPolishDialog({ const t = useTranslations("aiPolishDialog"); const [isPolishing, setIsPolishing] = useState(false); const [polishedContent, setPolishedContent] = useState(""); + const [customInstructions, setCustomInstructions] = useState(""); const { selectedModel, doubaoApiKey, @@ -106,7 +109,8 @@ export default function AIPolishDialog({ apiKey, apiEndpoint: selectedModel === "openai" ? openaiApiEndpoint : undefined, model: config.requiresModelId ? modelId : config.defaultModel, - modelType: selectedModel + modelType: selectedModel, + customInstructions: customInstructions.trim() || undefined }), signal: abortControllerRef.current.signal }); @@ -153,14 +157,13 @@ export default function AIPolishDialog({ }, [polishedContent]); useEffect(() => { - if (open) { - handlePolish(); - } else { + if (!open) { if (abortControllerRef.current) { abortControllerRef.current.abort(); abortControllerRef.current = null; } setPolishedContent(""); + setCustomInstructions(""); } }, [open]); @@ -231,10 +234,39 @@ export default function AIPolishDialog({ > {isPolishing ? t("description.polishing") - : t("description.finished")} + : polishedContent + ? t("description.finished") + : t("description.ready")} +
+ +