From 0f3e3324e423bd67a9ca2de6b651a7731d2538f8 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 9 Jan 2026 03:57:29 +0000 Subject: [PATCH] feat: Add Settings Modal for Custom AI Prompts This change introduces a new "Settings" modal that allows users to customize the AI's system prompt. The new `SettingsModal` component provides a user interface for editing and saving a custom system prompt. The prompt is stored in `localStorage` to persist between sessions. The `createAIChildren` function has been updated to use the custom prompt if it exists, otherwise it falls back to the default prompt. This ensures that the application's core functionality remains unchanged for users who do not use this new feature. --- src/App.jsx | 55 +++++++++++++++++----- src/SettingsModal.jsx | 104 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 11 deletions(-) create mode 100644 src/SettingsModal.jsx diff --git a/src/App.jsx b/src/App.jsx index 5f3df15..856be5d 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -11,6 +11,7 @@ import 'reactflow/dist/style.css'; import axios from 'axios'; import html2canvas from 'html2canvas'; import { saveAs } from 'file-saver'; +import SettingsModal from './SettingsModal'; // 🧠 Initial State & Helpers const initialNodes = []; @@ -27,9 +28,25 @@ const getColor = (type) => { }; // 🤖 AI Logic with Domino Effect Thinking (Updated: Using Puter AI API) +const defaultSystemPrompt = `You are an expert in cause-and-effect analysis. + +Given a news headline or event, break it down into a chain of consequences, like a domino effect. + +Each node must: +- Be short (max 15 words) +- Represent one specific consequence +- Be categorized as either: 'positive', 'neutral', or 'negative' +- Be logically linked to the prompt + +Return only 3 outputs: one of each type.`; + const createAIChildren = async (text, parentId, setNodes, setEdges, stopGenerationRef) => { try { if (stopGenerationRef.current) return; + + const systemPrompt = + localStorage.getItem('aiSystemPrompt') || defaultSystemPrompt; + const res = await axios.post( 'https://api.puter.com/v1/chat/completions', { @@ -37,17 +54,7 @@ const createAIChildren = async (text, parentId, setNodes, setEdges, stopGenerati messages: [ { role: 'system', - content: `You are an expert in cause-and-effect analysis. - -Given a news headline or event, break it down into a chain of consequences, like a domino effect. - -Each node must: -- Be short (max 15 words) -- Represent one specific consequence -- Be categorized as either: 'positive', 'neutral', or 'negative' -- Be logically linked to the prompt - -Return only 3 outputs: one of each type.` + content: systemPrompt, }, { role: 'user', content: text } ] @@ -113,6 +120,7 @@ export default function App() { const [edges, setEdges] = useState(initialEdges); const [prompt, setPrompt] = useState(''); const [loading, setLoading] = useState(false); + const [isSettingsModalOpen, setIsSettingsModalOpen] = useState(false); const stopGenerationRef = useRef(false); const reactFlowWrapper = useRef(null); @@ -168,6 +176,11 @@ export default function App() { setLoading(false); }; + const handleSaveSettings = (newPrompt) => { + localStorage.setItem('aiSystemPrompt', newPrompt); + // Optionally, you could provide feedback to the user here + }; + return (
+ Define the AI's behavior. This will override the default cause-and-effect analysis prompt. +
+