Update src/App.tsx
Browse files- src/App.tsx +149 -68
src/App.tsx
CHANGED
|
@@ -1,96 +1,177 @@
|
|
| 1 |
-
import React, { useCallback
|
| 2 |
-
import ReactFlow, {
|
| 3 |
-
|
| 4 |
-
MiniMap,
|
| 5 |
-
Controls,
|
| 6 |
-
Background,
|
| 7 |
-
useNodesState,
|
| 8 |
-
useEdgesState,
|
| 9 |
-
} from 'reactflow';
|
| 10 |
|
| 11 |
-
import
|
| 12 |
-
import
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
const nodeTypes = {
|
| 18 |
-
|
| 19 |
};
|
| 20 |
|
| 21 |
-
const
|
| 22 |
-
|
| 23 |
};
|
| 24 |
|
| 25 |
-
const
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
const
|
| 28 |
const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);
|
| 29 |
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);
|
| 30 |
-
const [recursiveSteps, setRecursiveSteps] = useState(1);
|
| 31 |
-
const [inputData, setInputData] = useState('');
|
| 32 |
-
|
| 33 |
-
const onConnect = useCallback((params) => setEdges((eds) => addEdge(params, eds)), []);
|
| 34 |
-
|
| 35 |
-
const edgesWithUpdatedTypes = edges.map((edge) => {
|
| 36 |
-
if (edge.sourceHandle) {
|
| 37 |
-
const edgeType = nodes.find((node) => node.type === 'custom').data.selects[edge.sourceHandle];
|
| 38 |
-
edge.type = edgeType;
|
| 39 |
-
}
|
| 40 |
|
| 41 |
-
|
| 42 |
-
});
|
| 43 |
-
|
| 44 |
-
const addRecursiveStep = () => {
|
| 45 |
-
setRecursiveSteps((prevSteps) => prevSteps + 1);
|
| 46 |
-
};
|
| 47 |
-
|
| 48 |
-
const removeRecursiveStep = () => {
|
| 49 |
-
if (recursiveSteps > 1) {
|
| 50 |
-
setRecursiveSteps((prevSteps) => prevSteps - 1);
|
| 51 |
-
}
|
| 52 |
-
};
|
| 53 |
-
|
| 54 |
-
const handleInputChange = (event) => {
|
| 55 |
-
setInputData(event.target.value);
|
| 56 |
-
};
|
| 57 |
|
| 58 |
return (
|
| 59 |
<div className="flow-container">
|
| 60 |
<ReactFlow
|
| 61 |
nodes={nodes}
|
| 62 |
-
edges={
|
| 63 |
onNodesChange={onNodesChange}
|
| 64 |
onEdgesChange={onEdgesChange}
|
| 65 |
onConnect={onConnect}
|
| 66 |
-
onInit={onInit}
|
| 67 |
fitView
|
| 68 |
-
attributionPosition="top-right"
|
| 69 |
nodeTypes={nodeTypes}
|
|
|
|
|
|
|
| 70 |
>
|
| 71 |
-
<
|
| 72 |
-
<
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
</ReactFlow>
|
| 75 |
-
<div className="options-panel">
|
| 76 |
-
<div>
|
| 77 |
-
<label>Recursive Steps:</label>
|
| 78 |
-
<input
|
| 79 |
-
type="number"
|
| 80 |
-
value={recursiveSteps}
|
| 81 |
-
min={1}
|
| 82 |
-
onChange={(e) => setRecursiveSteps(parseInt(e.target.value))}
|
| 83 |
-
/>
|
| 84 |
-
<button onClick={addRecursiveStep}>+</button>
|
| 85 |
-
<button onClick={removeRecursiveStep}>-</button>
|
| 86 |
-
</div>
|
| 87 |
-
<div>
|
| 88 |
-
<label>Input Data:</label>
|
| 89 |
-
<textarea value={inputData} onChange={handleInputChange} />
|
| 90 |
-
</div>
|
| 91 |
-
</div>
|
| 92 |
</div>
|
| 93 |
);
|
| 94 |
};
|
| 95 |
|
| 96 |
-
export default
|
|
|
|
| 1 |
+
import React, { useCallback } from 'react';
|
| 2 |
+
import ReactFlow, { Controls, useNodesState, useEdgesState, addEdge, Node, Edge } from 'reactflow';
|
| 3 |
+
import { FiFile } from 'react-icons/fi';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
import 'reactflow/dist/base.css';
|
| 6 |
+
import './index.css';
|
| 7 |
+
import TurboNode, { TurboNodeData } from './TurboNode';
|
| 8 |
+
import TurboEdge from './TurboEdge';
|
| 9 |
+
import FunctionIcon from './FunctionIcon';
|
| 10 |
|
| 11 |
+
const initialNodes: Node<TurboNodeData>[] = [
|
| 12 |
+
{
|
| 13 |
+
id: '1',
|
| 14 |
+
position: { x: 0, y: 0 },
|
| 15 |
+
data: {
|
| 16 |
+
icon: <FunctionIcon />,
|
| 17 |
+
title: 'LLM Provider',
|
| 18 |
+
subline: 'Select the LLM provider',
|
| 19 |
+
inputFields: [],
|
| 20 |
+
options: [
|
| 21 |
+
{ id: 'provider-openai', label: 'OpenAI', checked: true },
|
| 22 |
+
{ id: 'provider-azure', label: 'Azure', checked: false },
|
| 23 |
+
{ id: 'provider-cohere', label: 'Cohere', checked: false },
|
| 24 |
+
{ id: 'provider-huggingface', label: 'Hugging Face', checked: false },
|
| 25 |
+
{ id: 'provider-anthropic', label: 'Anthropic', checked: false },
|
| 26 |
+
],
|
| 27 |
+
},
|
| 28 |
+
type: 'turbo',
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
id: '2',
|
| 32 |
+
position: { x: 250, y: 0 },
|
| 33 |
+
data: {
|
| 34 |
+
icon: <FunctionIcon />,
|
| 35 |
+
title: 'Model Selection',
|
| 36 |
+
subline: 'Choose the LLM model',
|
| 37 |
+
inputFields: [],
|
| 38 |
+
options: [
|
| 39 |
+
{ id: 'model-gpt-3.5-turbo', label: 'GPT-3.5-turbo', checked: true },
|
| 40 |
+
{ id: 'model-gpt-4', label: 'GPT-4', checked: false },
|
| 41 |
+
{ id: 'model-claude', label: 'Claude', checked: false },
|
| 42 |
+
{ id: 'model-flan-t5', label: 'Flan-T5', checked: false },
|
| 43 |
+
],
|
| 44 |
+
},
|
| 45 |
+
type: 'turbo',
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
id: '3',
|
| 49 |
+
position: { x: 500, y: 0 },
|
| 50 |
+
data: {
|
| 51 |
+
icon: <FunctionIcon />,
|
| 52 |
+
title: 'Prompt Engineering',
|
| 53 |
+
subline: 'Configure prompt settings',
|
| 54 |
+
inputFields: [
|
| 55 |
+
{ id: 'prompt-template', label: 'Prompt Template', value: '' },
|
| 56 |
+
{ id: 'prompt-examples', label: 'Prompt Examples', value: '' },
|
| 57 |
+
],
|
| 58 |
+
options: [
|
| 59 |
+
{ id: 'prompt-fewshot', label: 'Few-shot Learning', checked: false },
|
| 60 |
+
{ id: 'prompt-cot', label: 'Chain-of-Thought', checked: false },
|
| 61 |
+
],
|
| 62 |
+
},
|
| 63 |
+
type: 'turbo',
|
| 64 |
+
},
|
| 65 |
+
{
|
| 66 |
+
id: '4',
|
| 67 |
+
position: { x: 750, y: 0 },
|
| 68 |
+
data: {
|
| 69 |
+
icon: <FunctionIcon />,
|
| 70 |
+
title: 'API Settings',
|
| 71 |
+
subline: 'Set API parameters',
|
| 72 |
+
inputFields: [
|
| 73 |
+
{ id: 'api-key', label: 'API Key', value: '' },
|
| 74 |
+
{ id: 'api-base', label: 'API Base URL', value: '' },
|
| 75 |
+
],
|
| 76 |
+
options: [
|
| 77 |
+
{ id: 'api-streaming', label: 'Enable Streaming', checked: false },
|
| 78 |
+
{ id: 'api-retry', label: 'Enable Auto-Retry', checked: true },
|
| 79 |
+
],
|
| 80 |
+
},
|
| 81 |
+
type: 'turbo',
|
| 82 |
+
},
|
| 83 |
+
{
|
| 84 |
+
id: '5',
|
| 85 |
+
position: { x: 1000, y: 0 },
|
| 86 |
+
data: {
|
| 87 |
+
icon: <FiFile />,
|
| 88 |
+
title: 'Output',
|
| 89 |
+
subline: 'Generated output from LLM',
|
| 90 |
+
},
|
| 91 |
+
type: 'turbo',
|
| 92 |
+
},
|
| 93 |
+
];
|
| 94 |
+
|
| 95 |
+
const initialEdges: Edge[] = [
|
| 96 |
+
{
|
| 97 |
+
id: 'e1-2',
|
| 98 |
+
source: '1',
|
| 99 |
+
target: '2',
|
| 100 |
+
},
|
| 101 |
+
{
|
| 102 |
+
id: 'e2-3',
|
| 103 |
+
source: '2',
|
| 104 |
+
target: '3',
|
| 105 |
+
},
|
| 106 |
+
{
|
| 107 |
+
id: 'e3-4',
|
| 108 |
+
source: '3',
|
| 109 |
+
target: '4',
|
| 110 |
+
},
|
| 111 |
+
{
|
| 112 |
+
id: 'e4-5',
|
| 113 |
+
source: '4',
|
| 114 |
+
target: '5',
|
| 115 |
+
},
|
| 116 |
+
];
|
| 117 |
|
| 118 |
const nodeTypes = {
|
| 119 |
+
turbo: TurboNode,
|
| 120 |
};
|
| 121 |
|
| 122 |
+
const edgeTypes = {
|
| 123 |
+
turbo: TurboEdge,
|
| 124 |
};
|
| 125 |
|
| 126 |
+
const defaultEdgeOptions = {
|
| 127 |
+
type: 'turbo',
|
| 128 |
+
markerEnd: 'edge-circle',
|
| 129 |
+
};
|
| 130 |
|
| 131 |
+
const App = () => {
|
| 132 |
const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);
|
| 133 |
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
+
const onConnect = useCallback((params) => setEdges((els) => addEdge(params, els)), []);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
return (
|
| 138 |
<div className="flow-container">
|
| 139 |
<ReactFlow
|
| 140 |
nodes={nodes}
|
| 141 |
+
edges={edges}
|
| 142 |
onNodesChange={onNodesChange}
|
| 143 |
onEdgesChange={onEdgesChange}
|
| 144 |
onConnect={onConnect}
|
|
|
|
| 145 |
fitView
|
|
|
|
| 146 |
nodeTypes={nodeTypes}
|
| 147 |
+
edgeTypes={edgeTypes}
|
| 148 |
+
defaultEdgeOptions={defaultEdgeOptions}
|
| 149 |
>
|
| 150 |
+
<Controls showInteractive={false} />
|
| 151 |
+
<svg>
|
| 152 |
+
<defs>
|
| 153 |
+
<linearGradient id="edge-gradient">
|
| 154 |
+
<stop offset="0%" stopColor="#ae53ba" />
|
| 155 |
+
<stop offset="100%" stopColor="#2a8af6" />
|
| 156 |
+
</linearGradient>
|
| 157 |
+
|
| 158 |
+
<marker
|
| 159 |
+
id="edge-circle"
|
| 160 |
+
viewBox="-5 -5 10 10"
|
| 161 |
+
refX="0"
|
| 162 |
+
refY="0"
|
| 163 |
+
markerUnits="strokeWidth"
|
| 164 |
+
markerWidth="10"
|
| 165 |
+
markerHeight="10"
|
| 166 |
+
orient="auto"
|
| 167 |
+
>
|
| 168 |
+
<circle stroke="#2a8af6" strokeOpacity="0.75" r="2" cx="0" cy="0" />
|
| 169 |
+
</marker>
|
| 170 |
+
</defs>
|
| 171 |
+
</svg>
|
| 172 |
</ReactFlow>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
</div>
|
| 174 |
);
|
| 175 |
};
|
| 176 |
|
| 177 |
+
export default App;
|