File size: 6,154 Bytes
00a8527
3b9a1cc
 
244482b
3b9a1cc
 
 
 
 
00a8527
244482b
3b9a1cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244482b
 
3b9a1cc
244482b
 
3b9a1cc
 
244482b
 
3b9a1cc
 
 
 
244482b
3b9a1cc
244482b
 
6d93c5b
 
244482b
3b9a1cc
244482b
6d93c5b
 
 
 
 
 
 
 
 
 
00a8527
6d93c5b
 
 
00a8527
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244482b
 
 
 
3b9a1cc
244482b
 
 
 
 
3b9a1cc
 
244482b
3b9a1cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244482b
00a8527
 
 
 
 
 
 
244482b
 
 
 
3b9a1cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import React, { useCallback, useEffect, useState } from 'react';
import ReactFlow, { Controls, useNodesState, useEdgesState, addEdge, Node, Edge } from 'reactflow';
import { FiFile } from 'react-icons/fi';

import 'reactflow/dist/base.css';
import './index.css';
import TurboNode, { TurboNodeData } from './TurboNode';
import TurboEdge from './TurboEdge';
import FunctionIcon from './FunctionIcon';
import Sidebar from './Sidebar';

const initialNodes: Node<TurboNodeData>[] = [
  {
    id: '1',
    position: { x: 0, y: 0 },
    data: {
      icon: <FunctionIcon />,
      title: 'LLM Provider',
      subline: 'Select the LLM provider',
      inputFields: [],
      options: [
        { id: 'provider-openai', label: 'OpenAI', checked: true },
        { id: 'provider-azure', label: 'Azure', checked: false },
        { id: 'provider-cohere', label: 'Cohere', checked: false },
        { id: 'provider-huggingface', label: 'Hugging Face', checked: false },
        { id: 'provider-anthropic', label: 'Anthropic', checked: false },
      ],
    },
    type: 'turbo',
  },
  {
    id: '2',
    position: { x: 250, y: 0 },
    data: {
      icon: <FunctionIcon />,
      title: 'Model Selection',
      subline: 'Choose the LLM model',
      inputFields: [],
      options: [
        { id: 'model-gpt-3.5-turbo', label: 'GPT-3.5-turbo', checked: true },
        { id: 'model-gpt-4', label: 'GPT-4', checked: false },
        { id: 'model-claude', label: 'Claude', checked: false },
        { id: 'model-flan-t5', label: 'Flan-T5', checked: false },
      ],
    },
    type: 'turbo',
  },
  {
    id: '3',
    position: { x: 500, y: 0 },
    data: {
      icon: <FunctionIcon />,
      title: 'Prompt Engineering',
      subline: 'Configure prompt settings',
      inputFields: [
        { id: 'prompt-template', label: 'Prompt Template', value: '' },
        { id: 'prompt-examples', label: 'Prompt Examples', value: '' },
      ],
      options: [
        { id: 'prompt-fewshot', label: 'Few-shot Learning', checked: false },
        { id: 'prompt-cot', label: 'Chain-of-Thought', checked: false },
      ],
    },
    type: 'turbo',
  },
  {
    id: '4',
    position: { x: 750, y: 0 },
    data: {
      icon: <FunctionIcon />,
      title: 'API Settings',
      subline: 'Set API parameters',
      inputFields: [
        { id: 'api-key', label: 'API Key', value: '' },
        { id: 'api-base', label: 'API Base URL', value: '' },
      ],
      options: [
        { id: 'api-streaming', label: 'Enable Streaming', checked: false },
        { id: 'api-retry', label: 'Enable Auto-Retry', checked: true },
      ],
    },
    type: 'turbo',
  },
  {
    id: '5',
    position: { x: 1000, y: 0 },
    data: {
      icon: <FiFile />,
      title: 'Output',
      subline: 'Generated output from LLM',
    },
    type: 'turbo',
  },
];

const initialEdges: Edge[] = [
  {
    id: 'e1-2',
    source: '1',
    target: '2',
  },
  {
    id: 'e2-3',
    source: '2',
    target: '3',
  },
  {
    id: 'e3-4',
    source: '3',
    target: '4',
  },
  {
    id: 'e4-5',
    source: '4',
    target: '5',
  },
];

const nodeTypes = {
  turbo: TurboNode,
};

const edgeTypes = {
  turbo: TurboEdge,
};

const defaultEdgeOptions = {
  type: 'turbo',
  markerEnd: 'edge-circle',
};

const App = () => {
  const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);
  const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);
  const [recursiveSteps, setRecursiveSteps] = useState(1);
  const [inputData, setInputData] = useState('');

  const onConnect = useCallback((params) => setEdges((els) => addEdge(params, els)), []);

  const addRecursiveStep = () => {
    setRecursiveSteps((prevSteps) => prevSteps + 1);
  };

  const removeRecursiveStep = () => {
    if (recursiveSteps > 1) {
      setRecursiveSteps((prevSteps) => prevSteps - 1);
    }
  };

  const handleInputChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
    setInputData(event.target.value);
  };

  useEffect(() => {
    // Update nodes based on recursive steps and input data
    // You can modify the nodes array or create new nodes dynamically
    // based on the recursiveSteps and inputData values
    // For example:
    // const newNodes = [...nodes];
    // for (let i = 0; i < recursiveSteps; i++) {
    //   newNodes.push({
    //     id: `recursive-${i}`,
    //     position: { x: 100 * i, y: 200 },
    //     data: {
    //       icon: <FunctionIcon />,
    //       title: `Recursive Step ${i + 1}`,
    //       subline: 'Recursive prompt',
    //       inputFields: [
    //         { id: `recursive-input-${i}`, label: `Input ${i + 1}`, value: '' },
    //       ],
    //       options: [],
    //     },
    //     type: 'turbo',
    //   });
    // }
    // setNodes(newNodes);
  }, [recursiveSteps, inputData]);

  return (
    <div className="flow-container">
      <ReactFlow
        nodes={nodes}
        edges={edges}
        onNodesChange={onNodesChange}
        onEdgesChange={onEdgesChange}
        onConnect={onConnect}
        fitView
        nodeTypes={nodeTypes}
        edgeTypes={edgeTypes}
        defaultEdgeOptions={defaultEdgeOptions}
      >
        <Controls showInteractive={false} />
        <svg>
          <defs>
            <linearGradient id="edge-gradient">
              <stop offset="0%" stopColor="#ae53ba" />
              <stop offset="100%" stopColor="#2a8af6" />
            </linearGradient>

            <marker
              id="edge-circle"
              viewBox="-5 -5 10 10"
              refX="0"
              refY="0"
              markerUnits="strokeWidth"
              markerWidth="10"
              markerHeight="10"
              orient="auto"
            >
              <circle stroke="#2a8af6" strokeOpacity="0.75" r="2" cx="0" cy="0" />
            </marker>
          </defs>
        </svg>
      </ReactFlow>
      <Sidebar
        recursiveSteps={recursiveSteps}
        addRecursiveStep={addRecursiveStep}
        removeRecursiveStep={removeRecursiveStep}
        inputData={inputData}
        handleInputChange={handleInputChange}
      />
    </div>
  );
};

export default App;