MCPcopy Create free account
hub / github.com/FlowiseAI/Flowise / getCode

Function getCode

packages/ui/src/views/chatflows/APICodeDialog.jsx:354–396  ·  view source on GitHub ↗
(codeLang)

Source from the content-addressed store, hash-verified

352 }
353
354 const getCode = (codeLang) => {
355 if (isWebhookFlow) return getWebhookCode(codeLang, null)
356 if (codeLang === 'Python') {
357 return `import requests
358
359API_URL = "${baseURL}/api/v1/prediction/${dialogProps.chatflowid}"
360
361def query(payload):
362 response = requests.post(API_URL, json=payload)
363 return response.json()
364
365output = query({
366 "question": "Hey, how are you?",
367})
368`
369 } else if (codeLang === 'JavaScript') {
370 return `async function query(data) {
371 const response = await fetch(
372 "${baseURL}/api/v1/prediction/${dialogProps.chatflowid}",
373 {
374 method: "POST",
375 headers: {
376 "Content-Type": "application/json"
377 },
378 body: JSON.stringify(data)
379 }
380 );
381 const result = await response.json();
382 return result;
383}
384
385query({"question": "Hey, how are you?"}).then((response) => {
386 console.log(response);
387});
388`
389 } else if (codeLang === 'cURL') {
390 return `curl ${baseURL}/api/v1/prediction/${dialogProps.chatflowid} \\
391 -X POST \\
392 -d '{"question": "Hey, how are you?"}' \\
393 -H "Content-Type: application/json"`
394 }
395 return ''
396 }
397
398 const getCodeWithAuthorization = (codeLang) => {
399 if (isWebhookFlow) return getWebhookCode(codeLang, selectedApiKey?.apiKey)

Callers 1

APICodeDialogFunction · 0.70

Calls 1

getWebhookCodeFunction · 0.85

Tested by

no test coverage detected