mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Let system prompt be configurable in System Settings (EJS template)
This commit is contained in:
14 files changed
+271
-124
No files matched your search
@@ -5,12 +5,14 @@ import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion';
|
||||
import { useIsMobile } from "@/hooks/useIsMobile";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useAppContext } from "@/hooks/useAppContext";
|
||||
import { useOffline } from "@/hooks/useOffline";
|
||||
import { useToast } from "@/hooks/useToast";
|
||||
import { defaultSystemPrompt } from "@/lib/system";
|
||||
|
||||
export function SystemSettings() {
|
||||
const { t } = useTranslation();
|
||||
@@ -31,6 +33,7 @@ export function SystemSettings() {
|
||||
const [fsPathTmpInput, setFsPathTmpInput] = useState(config.fsPathTmp);
|
||||
const [fsPathPluginsInput, setFsPathPluginsInput] = useState(config.fsPathPlugins);
|
||||
const [sentryDsnInput, setSentryDsnInput] = useState(config.sentryDsn);
|
||||
const [systemPromptInput, setSystemPromptInput] = useState(config.systemPrompt || defaultSystemPrompt);
|
||||
|
||||
// Check which settings differ from defaults
|
||||
const isModified = useMemo(() => ({
|
||||
@@ -46,6 +49,7 @@ export function SystemSettings() {
|
||||
fsPathTmp: config.fsPathTmp !== defaultConfig.fsPathTmp,
|
||||
fsPathPlugins: config.fsPathPlugins !== defaultConfig.fsPathPlugins,
|
||||
sentryDsn: config.sentryDsn !== defaultConfig.sentryDsn,
|
||||
systemPrompt: (config.systemPrompt || defaultSystemPrompt) !== (defaultConfig.systemPrompt || defaultSystemPrompt),
|
||||
}), [config, defaultConfig]);
|
||||
|
||||
// Restore functions
|
||||
@@ -120,6 +124,12 @@ export function SystemSettings() {
|
||||
updateConfig((current) => ({ ...current, sentryDsn: defaultValue }));
|
||||
};
|
||||
|
||||
const restoreSystemPrompt = () => {
|
||||
const defaultValue = defaultSystemPrompt;
|
||||
setSystemPromptInput(defaultValue);
|
||||
updateConfig((current) => ({ ...current, systemPrompt: defaultValue }));
|
||||
};
|
||||
|
||||
// Service Worker state
|
||||
const [swState, setSwState] = useState<string>('');
|
||||
const [isUpdatingSW, setIsUpdatingSW] = useState(false);
|
||||
@@ -912,6 +922,53 @@ export function SystemSettings() {
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
|
||||
{/* System Prompt Configuration */}
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<AccordionItem value="system-prompt" className="border rounded-lg">
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<div className="flex items-center gap-2">
|
||||
<h4 className="text-sm font-medium">{t('systemPrompt')}</h4>
|
||||
{isModified.systemPrompt && (
|
||||
<div className="h-2 w-2 rounded-full bg-yellow-500" title={t('modified')} />
|
||||
)}
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="py-1 space-y-2">
|
||||
<div className="flex gap-2 flex-col">
|
||||
<Textarea
|
||||
id="system-prompt"
|
||||
placeholder="Enter EJS template..."
|
||||
value={systemPromptInput}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
setSystemPromptInput(value);
|
||||
updateConfig((current) => ({
|
||||
...current,
|
||||
systemPrompt: value,
|
||||
}));
|
||||
}}
|
||||
className="flex-1 font-mono text-xs min-h-[400px]"
|
||||
/>
|
||||
{isModified.systemPrompt && (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={restoreSystemPrompt}
|
||||
className="w-full"
|
||||
>
|
||||
<RotateCcw className="h-4 w-4 mr-2" />
|
||||
{t('restoreToDefault')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t('systemPromptDescription')}
|
||||
</p>
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user