Skip to content
Draft
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
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.

63 changes: 47 additions & 16 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 @@ -16,6 +17,17 @@ import { saveAs } from 'file-saver';
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) {
Expand All @@ -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(
Expand All @@ -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 }
]
Expand Down Expand Up @@ -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) {
Expand All @@ -113,9 +115,18 @@ export default function App() {
const [edges, setEdges] = useState(initialEdges);
const [prompt, setPrompt] = useState('');
const [loading, setLoading] = useState(false);
const [isSettingsModalOpen, setIsSettingsModalOpen] = 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) => {
Expand Down Expand Up @@ -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);
Expand All @@ -164,12 +175,18 @@ 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);
};

return (
<div style={{ height: '100vh', width: '100vw', backgroundColor: '#111', display: 'flex', flexDirection: 'column' }}>
<SettingsModal
isOpen={isSettingsModalOpen}
onClose={() => setIsSettingsModalOpen(false)}
systemPrompt={systemPrompt}
onSave={handleSaveSystemPrompt}
/>
{/* 🔝 Header */}
<div style={{
padding: '1rem 2rem',
Expand All @@ -184,7 +201,21 @@ export default function App() {
</div>

{/* 🔍 Prompt Input */}
<div style={{ display: 'flex', gap: '0.75rem' }}>
<div style={{ display: 'flex', gap: '0.75rem', alignItems: 'center' }}>
<button
onClick={() => setIsSettingsModalOpen(true)}
style={{
padding: '10px 20px',
backgroundColor: '#777',
color: 'white',
border: '1px solid #ccc',
borderRadius: '8px',
fontWeight: 'bold',
cursor: 'pointer',
}}
>
Settings
</button>
<input
type="text"
value={prompt}
Expand Down
94 changes: 94 additions & 0 deletions src/SettingsModal.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// 📦 Imports
import React, { useState } from 'react';

// ⚙️ SettingsModal Component
export default function SettingsModal({
isOpen,
onClose,
systemPrompt,
onSave,
}) {
const [prompt, setPrompt] = useState(systemPrompt);

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

if (!isOpen) {
return null;
}

return (
<div style={{
position: 'fixed',
top: 0,
left: 0,
right: 0,
bottom: 0,
backgroundColor: 'rgba(0, 0, 0, 0.7)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
zIndex: 1000,
}}>
<div style={{
backgroundColor: '#333',
padding: '2rem',
borderRadius: '12px',
width: '500px',
color: '#fff',
}}>
<h2>Custom AI Instructions</h2>
<p style={{ color: '#ccc', fontSize: '0.9rem', marginBottom: '1rem' }}>
Tweak the AI's "system prompt" to change its behavior. For example, you could ask it to be a specific character, or to generate different kinds of ideas.
</p>
<textarea
value={prompt}
onChange={(e) => setPrompt(e.target.value)}
style={{
width: '100%',
height: '200px',
backgroundColor: '#222',
color: '#fff',
border: '1px solid #555',
borderRadius: '8px',
padding: '10px',
fontSize: '1rem',
marginBottom: '1rem',
}}
/>
<div style={{ display: 'flex', justifyContent: 'flex-end', gap: '1rem' }}>
<button
onClick={onClose}
style={{
padding: '10px 20px',
backgroundColor: '#555',
color: 'white',
border: 'none',
borderRadius: '8px',
fontWeight: 'bold',
cursor: 'pointer',
}}
>
Cancel
</button>
<button
onClick={handleSave}
style={{
padding: '10px 20px',
backgroundColor: '#00bcd4',
color: 'white',
border: 'none',
borderRadius: '8px',
fontWeight: 'bold',
cursor: 'pointer',
}}
>
Save
</button>
</div>
</div>
</div>
);
}