diff --git a/.gitignore b/.gitignore index a547bf3..8a182f4 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ dist-ssr *.njsproj *.sln *.sw? +__pycache__/ diff --git a/src/App.jsx b/src/App.jsx index 5f3df15..f983349 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,5 +1,6 @@ // 📦 Imports import React, { useState, useRef } from 'react'; +import SettingsModal from './SettingsModal'; import ReactFlow, { Background, Controls, @@ -13,6 +14,17 @@ import html2canvas from 'html2canvas'; import { saveAs } from 'file-saver'; // 🧠 Initial State & Helpers +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 initialNodes = []; const initialEdges = []; let nodeId = 1; @@ -27,7 +39,7 @@ const getColor = (type) => { }; // 🤖 AI Logic with Domino Effect Thinking (Updated: Using Puter AI API) -const createAIChildren = async (text, parentId, setNodes, setEdges, stopGenerationRef) => { +const createAIChildren = async (text, parentId, setNodes, setEdges, stopGenerationRef, systemPrompt) => { try { if (stopGenerationRef.current) return; const res = await axios.post( @@ -37,17 +49,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 } ] @@ -96,7 +98,7 @@ Return only 3 outputs: one of each type.` // Recursively expand each child one level deep for (const n of newNodes) { if (stopGenerationRef.current) break; - await createAIChildren(n.data.label, n.id, setNodes, setEdges, stopGenerationRef); + await createAIChildren(n.data.label, n.id, setNodes, setEdges, stopGenerationRef, systemPrompt); } } catch (err) { @@ -113,9 +115,18 @@ export default function App() { const [edges, setEdges] = useState(initialEdges); const [prompt, setPrompt] = useState(''); const [loading, setLoading] = useState(false); + const [showSettings, setShowSettings] = useState(false); + const [systemPrompt, setSystemPrompt] = useState( + localStorage.getItem('systemPrompt') || defaultSystemPrompt + ); const stopGenerationRef = useRef(false); const reactFlowWrapper = useRef(null); + const handleSaveSystemPrompt = (newPrompt) => { + setSystemPrompt(newPrompt); + localStorage.setItem('systemPrompt', newPrompt); + }; + const handleExport = () => { if (reactFlowWrapper.current) { html2canvas(reactFlowWrapper.current).then((canvas) => { @@ -150,7 +161,7 @@ export default function App() { setNodes([rootNode]); setEdges([]); - await createAIChildren(prompt, rootId, setNodes, setEdges, stopGenerationRef); + await createAIChildren(prompt, rootId, setNodes, setEdges, stopGenerationRef, systemPrompt); setPrompt(''); setLoading(false); @@ -164,7 +175,7 @@ export default function App() { const onNodeClick = async (_event, node) => { stopGenerationRef.current = false; setLoading(true); - await createAIChildren(node.data.label, node.id, setNodes, setEdges, stopGenerationRef); + await createAIChildren(node.data.label, node.id, setNodes, setEdges, stopGenerationRef, systemPrompt); setLoading(false); }; @@ -246,9 +257,30 @@ export default function App() { > Export as PNG + + setShowSettings(false)} + /> + {/* 🧠 ReactFlow Canvas */}
{ + const [newPrompt, setNewPrompt] = useState(systemPrompt); + + const handleSave = () => { + onSave(newPrompt); + onClose(); + }; + + if (!show) { + return null; + } + + return ( +
+
+

Settings

+