Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ dist-ssr
*.njsproj
*.sln
*.sw?

# Python cache
__pycache__/
10 changes: 0 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 53 additions & 15 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// 📦 Imports
import React, { useState, useRef } from 'react';
import SettingsModal from './SettingsModal';
import ReactFlow, {
Background,
Controls,
Expand All @@ -17,6 +18,18 @@ const initialNodes = [];
const initialEdges = [];
let nodeId = 1;

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 getColor = (type) => {
switch (type) {
case 'positive': return '#00c853';
Expand All @@ -27,7 +40,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(
Expand All @@ -37,17 +50,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 }
]
Expand Down Expand Up @@ -96,7 +99,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) {
Expand All @@ -113,6 +116,10 @@ export default function App() {
const [edges, setEdges] = useState(initialEdges);
const [prompt, setPrompt] = useState('');
const [loading, setLoading] = useState(false);
const [isSettingsOpen, setIsSettingsOpen] = useState(false);
const [systemPrompt, setSystemPrompt] = useState(
localStorage.getItem('customSystemPrompt') || defaultSystemPrompt
);
const stopGenerationRef = useRef(false);
const reactFlowWrapper = useRef(null);

Expand All @@ -126,6 +133,16 @@ export default function App() {
}
};

const handleSaveSystemPrompt = (newPrompt) => {
setSystemPrompt(newPrompt);
localStorage.setItem('customSystemPrompt', newPrompt);
};

const handleResetSystemPrompt = () => {
setSystemPrompt(defaultSystemPrompt);
localStorage.removeItem('customSystemPrompt');
};

const handleSubmit = async () => {
if (!prompt.trim()) return;
setLoading(true);
Expand All @@ -150,7 +167,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);
Expand All @@ -164,7 +181,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);
};

Expand Down Expand Up @@ -246,6 +263,20 @@ export default function App() {
>
Export as PNG
</button>
<button
onClick={() => setIsSettingsOpen(true)}
style={{
padding: '10px 20px',
backgroundColor: '#6c757d',
color: 'white',
border: 'none',
borderRadius: '8px',
fontWeight: 'bold',
cursor: 'pointer',
}}
>
Settings
</button>
</div>
</div>

Expand All @@ -265,6 +296,13 @@ export default function App() {
<Background variant="dots" gap={12} size={1} />
</ReactFlow>
</div>
<SettingsModal
isOpen={isSettingsOpen}
onClose={() => setIsSettingsOpen(false)}
onSave={handleSaveSystemPrompt}
onReset={handleResetSystemPrompt}
systemPrompt={systemPrompt}
/>
</div>
);
}
118 changes: 118 additions & 0 deletions src/SettingsModal.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import React, { useState, useEffect } from 'react';

const SettingsModal = ({ isOpen, onClose, onSave, onReset, systemPrompt }) => {
const [prompt, setPrompt] = useState(systemPrompt);

useEffect(() => {
setPrompt(systemPrompt);
}, [systemPrompt, isOpen]);

const handleSave = () => {
onSave(prompt);
onClose();
};

const handleReset = () => {
onReset();
onClose();
};

if (!isOpen) return null;

return (
<div style={styles.overlay}>
<div style={styles.modal} role="dialog" aria-labelledby="dialog-header">
<h2 id="dialog-header" style={styles.header}>AI Settings</h2>
<p style={styles.label}>System Prompt:</p>
<textarea
value={prompt}
onChange={(e) => setPrompt(e.target.value)}
style={styles.textarea}
placeholder="Enter custom AI system prompt..."
/>
<div style={styles.buttonContainer}>
<button onClick={handleSave} style={styles.saveButton}>Save</button>
<button onClick={handleReset} style={styles.resetButton}>Reset to Default</button>
<button onClick={onClose} style={styles.closeButton}>Close</button>
</div>
</div>
</div>
);
};

const styles = {
overlay: {
position: 'fixed',
top: 0,
left: 0,
right: 0,
bottom: 0,
backgroundColor: 'rgba(0, 0, 0, 0.7)',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
zIndex: 1000,
},
modal: {
backgroundColor: '#333',
padding: '2rem',
borderRadius: '12px',
width: '500px',
color: '#fff',
boxShadow: '0 5px 15px rgba(0,0,0,0.3)',
},
header: {
marginTop: 0,
marginBottom: '1.5rem',
borderBottom: '1px solid #555',
paddingBottom: '1rem',
},
label: {
marginBottom: '0.5rem',
color: '#ccc',
},
textarea: {
width: '100%',
minHeight: '150px',
padding: '10px',
borderRadius: '8px',
border: '1px solid #555',
color: '#fff',
backgroundColor: '#444',
marginBottom: '1.5rem',
boxSizing: 'border-box',
fontSize: '1rem',
},
buttonContainer: {
display: 'flex',
justifyContent: 'flex-end',
gap: '0.75rem',
},
saveButton: {
padding: '10px 20px',
backgroundColor: '#00bcd4',
color: 'white',
border: 'none',
borderRadius: '8px',
fontWeight: 'bold',
cursor: 'pointer',
},
resetButton: {
padding: '10px 20px',
backgroundColor: '#ff4d4d',
color: '#fff',
border: 'none',
borderRadius: '8px',
cursor: 'pointer',
},
closeButton: {
padding: '10px 20px',
backgroundColor: '#666',
color: 'white',
border: 'none',
borderRadius: '8px',
cursor: 'pointer',
},
};

export default SettingsModal;
Loading