Skip to content

Commit d673683

Browse files
committed
text-node that has replace variable refererences like {{variableName}} and implemented in a simple google gemini flash prompt flow example
1 parent 1cb7d02 commit d673683

File tree

4 files changed

+129
-39
lines changed

4 files changed

+129
-39
lines changed

examples-test-flows/google-gemini-flash-simple-prompt.json

Lines changed: 86 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
"nodes": [
99
{
1010
"id": "1bc4104f-6c09-4bd2-9a65-9ed23137a1db",
11-
"x": 3387.9412992094503,
12-
"y": 1553.4911809888213,
11+
"x": 3386.3467324818757,
12+
"y": 1554.3180990996912,
1313
"width": 111.7109375,
1414
"height": 112,
1515
"nodeType": "Shape",
1616
"nodeInfo": {
1717
"type": "json-node",
1818
"formValues": {
19-
"json": "{\n \"contents\": [{\n \"parts\":[{\"text\": \"Explain how AI works\"}]\n }]\n}"
19+
"json": "{\n \"contents\": [{\n \"parts\":[{\"@set:text\": \"input\"}]\n }]\n}"
2020
},
2121
"nodeCannotBeReplaced": true,
2222
"showFormOnlyInPopup": true,
@@ -45,8 +45,8 @@
4545
"id": "8144d095-7110-43d4-96fb-8683bb78c353",
4646
"x": 4003.48228233086,
4747
"y": 1511.442820331771,
48-
"width": 120.00028243731548,
49-
"height": 272.0000021485332,
48+
"width": 120.00011977661892,
49+
"height": 272.00001609819054,
5050
"nodeType": "Shape",
5151
"nodeInfo": {
5252
"type": "show-input",
@@ -60,10 +60,10 @@
6060
},
6161
{
6262
"id": "c3a8bd9e-f4d5-46db-9384-b1de17a33c5f",
63-
"x": 4673.813641176501,
64-
"y": 1514.1354499719885,
65-
"width": 119.99988179708753,
66-
"height": 272.0000883964047,
63+
"x": 4673.813395137549,
64+
"y": 1515.2820578688627,
65+
"width": 119.99966907871476,
66+
"height": 272.00001609819054,
6767
"nodeType": "Shape",
6868
"nodeInfo": {
6969
"type": "show-input",
@@ -75,10 +75,67 @@
7575
"isSettingsPopup": true
7676
}
7777
},
78+
{
79+
"id": "c99ece2b-9de3-409d-af22-cb6fa0f677cb",
80+
"x": 4313.803391261389,
81+
"y": 1494.0914007909573,
82+
"width": 200,
83+
"height": 100,
84+
"nodeType": "Shape",
85+
"nodeInfo": {
86+
"type": "expression",
87+
"formValues": {
88+
"expression": "candidates[0].content.parts[0].text",
89+
"inputType": "number"
90+
},
91+
"showFormOnlyInPopup": true,
92+
"isSettingsPopup": true,
93+
"supportsPreview": true
94+
}
95+
},
96+
{
97+
"id": "9f1f3e1c-787f-406f-b52b-b6db3e7b85dd",
98+
"x": 3117.576582938058,
99+
"y": 1576.330740260205,
100+
"width": 74.7109375,
101+
"height": 80,
102+
"nodeType": "Shape",
103+
"nodeInfo": {
104+
"type": "text-node",
105+
"formValues": {
106+
"text": "Input data is received in a typescript object specified below, it is in the subject property:\n\n```ts\nconst input = {\n subject: \"{{subject}}\"\n}\n```\n\nExplain in detail the subject that is in the subject property in the incoming input data object, specified above"
107+
},
108+
"nodeCannotBeReplaced": true,
109+
"showFormOnlyInPopup": true,
110+
"useInCompositionOnly": false,
111+
"keepPopupOpenAfterUpdate": true
112+
}
113+
},
114+
{
115+
"id": "8b7d6c8d-1806-4596-a47a-514038cffe13",
116+
"x": 3149.212398108586,
117+
"y": 1326.8614462943667,
118+
"width": 174.42183422340463,
119+
"height": 83.99991573929128,
120+
"nodeType": "Shape",
121+
"nodeInfo": {
122+
"type": "scope-variable",
123+
"formValues": {
124+
"variableName": "subject",
125+
"initialValue": "AI",
126+
"fieldType": "value",
127+
"fieldValueType": "string",
128+
"enumValues": [],
129+
"initialEnumValue": ""
130+
},
131+
"isVariable": true,
132+
"nodeCannotBeReplaced": true
133+
}
134+
},
78135
{
79136
"id": "6a22f828-b47c-4123-bde9-6ebe2940cc0a",
80-
"x": 3499.6522367094503,
81-
"y": 1609.4911809888213,
137+
"x": 3498.0576699818757,
138+
"y": 1610.3180990996912,
82139
"endX": 3663.063721988264,
83140
"endY": 1611.6351069890657,
84141
"startNodeId": "1bc4104f-6c09-4bd2-9a65-9ed23137a1db",
@@ -107,7 +164,7 @@
107164
},
108165
{
109166
"id": "ea98148d-52be-473c-be87-8f0fbd6e771b",
110-
"x": 4123.4825647681755,
167+
"x": 4123.482402107479,
111168
"y": 1541.442820331771,
112169
"endX": 4313.803391261389,
113170
"endY": 1544.0914007909573,
@@ -120,31 +177,12 @@
120177
"layer": 1,
121178
"nodeInfo": {}
122179
},
123-
{
124-
"id": "c99ece2b-9de3-409d-af22-cb6fa0f677cb",
125-
"x": 4313.803391261389,
126-
"y": 1494.0914007909573,
127-
"width": 200,
128-
"height": 100,
129-
"nodeType": "Shape",
130-
"nodeInfo": {
131-
"type": "expression",
132-
"formValues": {
133-
"expression": "candidates[0].content.parts[0].text",
134-
"inputType": "number"
135-
},
136-
"showFormOnlyInPopup": true,
137-
"isSettingsPopup": true,
138-
"supportsPreview": true,
139-
"taskType": "expression"
140-
}
141-
},
142180
{
143181
"id": "3735612d-a425-45c2-ae8f-8a3adfcde306",
144182
"x": 4513.803391261389,
145183
"y": 1544.0914007909573,
146-
"endX": 4673.813641176501,
147-
"endY": 1544.1354499719885,
184+
"endX": 4673.813395137549,
185+
"endY": 1545.2820578688627,
148186
"startNodeId": "c99ece2b-9de3-409d-af22-cb6fa0f677cb",
149187
"endNodeId": "c3a8bd9e-f4d5-46db-9384-b1de17a33c5f",
150188
"startThumbName": "output",
@@ -153,6 +191,21 @@
153191
"nodeType": "Connection",
154192
"layer": 1,
155193
"nodeInfo": {}
194+
},
195+
{
196+
"id": "3595bb23-681a-43d1-b8c5-0a3cd2b68bfc",
197+
"x": 3192.287520438058,
198+
"y": 1616.330740260205,
199+
"endX": 3386.3467324818757,
200+
"endY": 1610.3180990996912,
201+
"startNodeId": "9f1f3e1c-787f-406f-b52b-b6db3e7b85dd",
202+
"endNodeId": "1bc4104f-6c09-4bd2-9a65-9ed23137a1db",
203+
"startThumbName": "output",
204+
"endThumbName": "input",
205+
"lineType": "BezierCubic",
206+
"nodeType": "Connection",
207+
"layer": 1,
208+
"nodeInfo": {}
156209
}
157210
]
158211
}

libs/visual-programming-system/src/components/meta-view-dialog/meta-view-dialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const showMetaViewDialog = (
6060
}
6161
>
6262
<div
63-
class="overflow-visible whitespace-pre flex flex-col gap-4"
63+
class="overflow-visible whitespace-pre-wrap flex flex-col gap-4"
6464
getElement={(element: HTMLDivElement) =>
6565
(divElement = element as HTMLDivElement)
6666
}

libs/web-flow-executor/src/nodes/raw-text.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
visualNodeFactory,
1515
} from '@devhelpr/visual-programming-system';
1616
import { NodeInfo } from '../types/node-info';
17+
import { getVariablePayloadInputUtils } from './variable-payload-input-utils/variable-payload-input-utils';
18+
import { replaceVariablesInString } from '../utils/replace-variables-in-string';
1719

1820
const fieldName = 'testt-input';
1921
const labelName = 'JSON';
@@ -57,11 +59,11 @@ export const getRawTextNode: NodeTaskFactory<NodeInfo> = (
5759
};
5860

5961
const compute = (
60-
_input: string,
61-
_loopIndex?: number,
62-
_payload?: any,
62+
input: string,
63+
loopIndex?: number,
64+
payload?: any,
6365
_thumbName?: string,
64-
_scopeId?: string
66+
scopeId?: string
6567
) => {
6668
clearErrorMessage?.();
6769
if (!node.nodeInfo || !node.nodeInfo.formValues?.['text']) {
@@ -73,7 +75,21 @@ export const getRawTextNode: NodeTaskFactory<NodeInfo> = (
7375
};
7476
}
7577

76-
const text = node.nodeInfo.formValues['text'] ?? '';
78+
const variablePayload = getVariablePayloadInputUtils(
79+
input,
80+
payload,
81+
'string',
82+
0,
83+
loopIndex ?? 0,
84+
scopeId,
85+
canvasAppInstance
86+
);
87+
88+
const text = replaceVariablesInString(
89+
node.nodeInfo.formValues['text'] ?? '',
90+
variablePayload
91+
);
92+
7793
currentSerializedInput = text;
7894
return {
7995
result: text,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export const replaceVariablesInString = (
2+
content: string,
3+
payload: Record<string, string> = {}
4+
) => {
5+
let resultContent = content;
6+
try {
7+
const matches = resultContent.match(/{{[\s\S]+?}}/gm);
8+
if (matches) {
9+
matches.map((match) => {
10+
const variableName = match.slice(2, -2);
11+
const info = payload[variableName];
12+
if (info) {
13+
resultContent = resultContent.replace(match, info);
14+
}
15+
});
16+
}
17+
} catch (error) {
18+
console.error('replaceVariablesInString error', error);
19+
}
20+
return resultContent;
21+
};

0 commit comments

Comments
 (0)