Skip to content

Commit 1cb7d02

Browse files
committed
google gemini flash api simple prompt implementation in flow
1 parent 70e1dca commit 1cb7d02

File tree

2 files changed

+168
-3
lines changed

2 files changed

+168
-3
lines changed
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
{
2+
"schemaType": "flow",
3+
"schemaVersion": "0.0.1",
4+
"id": "1234",
5+
"flows": {
6+
"flow": {
7+
"flowType": "flow",
8+
"nodes": [
9+
{
10+
"id": "1bc4104f-6c09-4bd2-9a65-9ed23137a1db",
11+
"x": 3387.9412992094503,
12+
"y": 1553.4911809888213,
13+
"width": 111.7109375,
14+
"height": 112,
15+
"nodeType": "Shape",
16+
"nodeInfo": {
17+
"type": "json-node",
18+
"formValues": {
19+
"json": "{\n \"contents\": [{\n \"parts\":[{\"text\": \"Explain how AI works\"}]\n }]\n}"
20+
},
21+
"nodeCannotBeReplaced": true,
22+
"showFormOnlyInPopup": true,
23+
"useInCompositionOnly": false,
24+
"keepPopupOpenAfterUpdate": true
25+
}
26+
},
27+
{
28+
"id": "e8bad215-deb0-42d9-a3e1-156090717777",
29+
"x": 3663.063721988264,
30+
"y": 1511.6351069890657,
31+
"width": 200,
32+
"height": 200,
33+
"nodeType": "Shape",
34+
"nodeInfo": {
35+
"type": "fetch",
36+
"formValues": {
37+
"url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=[openai-key]",
38+
"http-method": "post",
39+
"headers": ""
40+
},
41+
"isSettingsPopup": true
42+
}
43+
},
44+
{
45+
"id": "8144d095-7110-43d4-96fb-8683bb78c353",
46+
"x": 4003.48228233086,
47+
"y": 1511.442820331771,
48+
"width": 120.00028243731548,
49+
"height": 272.0000021485332,
50+
"nodeType": "Shape",
51+
"nodeInfo": {
52+
"type": "show-input",
53+
"formValues": {
54+
"name": "",
55+
"data-type": "default"
56+
},
57+
"initializeOnStartFlow": true,
58+
"isSettingsPopup": true
59+
}
60+
},
61+
{
62+
"id": "c3a8bd9e-f4d5-46db-9384-b1de17a33c5f",
63+
"x": 4673.813641176501,
64+
"y": 1514.1354499719885,
65+
"width": 119.99988179708753,
66+
"height": 272.0000883964047,
67+
"nodeType": "Shape",
68+
"nodeInfo": {
69+
"type": "show-input",
70+
"formValues": {
71+
"name": "",
72+
"data-type": "default"
73+
},
74+
"initializeOnStartFlow": true,
75+
"isSettingsPopup": true
76+
}
77+
},
78+
{
79+
"id": "6a22f828-b47c-4123-bde9-6ebe2940cc0a",
80+
"x": 3499.6522367094503,
81+
"y": 1609.4911809888213,
82+
"endX": 3663.063721988264,
83+
"endY": 1611.6351069890657,
84+
"startNodeId": "1bc4104f-6c09-4bd2-9a65-9ed23137a1db",
85+
"endNodeId": "e8bad215-deb0-42d9-a3e1-156090717777",
86+
"startThumbName": "output",
87+
"endThumbName": "input",
88+
"lineType": "BezierCubic",
89+
"nodeType": "Connection",
90+
"layer": 1,
91+
"nodeInfo": {}
92+
},
93+
{
94+
"id": "41770511-b5bf-4014-9b95-1dee2abd53de",
95+
"x": 3863.063721988264,
96+
"y": 1541.6351069890657,
97+
"endX": 4003.48228233086,
98+
"endY": 1541.442820331771,
99+
"startNodeId": "e8bad215-deb0-42d9-a3e1-156090717777",
100+
"endNodeId": "8144d095-7110-43d4-96fb-8683bb78c353",
101+
"startThumbName": "output",
102+
"endThumbName": "input",
103+
"lineType": "BezierCubic",
104+
"nodeType": "Connection",
105+
"layer": 1,
106+
"nodeInfo": {}
107+
},
108+
{
109+
"id": "ea98148d-52be-473c-be87-8f0fbd6e771b",
110+
"x": 4123.4825647681755,
111+
"y": 1541.442820331771,
112+
"endX": 4313.803391261389,
113+
"endY": 1544.0914007909573,
114+
"startNodeId": "8144d095-7110-43d4-96fb-8683bb78c353",
115+
"endNodeId": "c99ece2b-9de3-409d-af22-cb6fa0f677cb",
116+
"startThumbName": "output",
117+
"endThumbName": "input",
118+
"lineType": "BezierCubic",
119+
"nodeType": "Connection",
120+
"layer": 1,
121+
"nodeInfo": {}
122+
},
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+
},
142+
{
143+
"id": "3735612d-a425-45c2-ae8f-8a3adfcde306",
144+
"x": 4513.803391261389,
145+
"y": 1544.0914007909573,
146+
"endX": 4673.813641176501,
147+
"endY": 1544.1354499719885,
148+
"startNodeId": "c99ece2b-9de3-409d-af22-cb6fa0f677cb",
149+
"endNodeId": "c3a8bd9e-f4d5-46db-9384-b1de17a33c5f",
150+
"startThumbName": "output",
151+
"endThumbName": "input",
152+
"lineType": "BezierCubic",
153+
"nodeType": "Connection",
154+
"layer": 1,
155+
"nodeInfo": {}
156+
}
157+
]
158+
}
159+
},
160+
"compositions": {}
161+
}

libs/web-flow-executor/src/nodes/fetch.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,16 @@ export const getFetch: NodeTaskFactory<NodeInfo> = (
133133
try {
134134
sendFetchState('fetching');
135135

136+
const openAIKey = canvasAppInstance?.isContextOnly
137+
? process.env?.['openai_api_key'] ?? ''
138+
: canvasAppInstance?.getTempData('openai-key') ?? '';
139+
136140
let url = node?.nodeInfo?.formValues?.['url'] ?? '';
137141
if (url.startsWith('/')) {
138142
url = canvasAppInstance?.getApiUrlRoot() + url.substring(1);
139143
}
144+
url = url.replace('[openai-key]', openAIKey);
145+
140146
const responseType =
141147
node?.nodeInfo?.formValues?.['response-type'] ?? 'json';
142148
const httpMethod =
@@ -146,9 +152,7 @@ export const getFetch: NodeTaskFactory<NodeInfo> = (
146152
const headersString = node?.nodeInfo?.formValues?.['headers'] ?? '';
147153
if (headersString) {
148154
const headersArray = headersString.split('\n');
149-
const openAIKey = canvasAppInstance?.isContextOnly
150-
? process.env?.['openai_api_key'] ?? ''
151-
: canvasAppInstance?.getTempData('openai-key') ?? '';
155+
152156
headersArray.forEach((header: string) => {
153157
const headerArray = header.split(':');
154158
if (headerArray.length === 2) {

0 commit comments

Comments
 (0)