(codeLang)
| 352 | } |
| 353 | |
| 354 | const getCode = (codeLang) => { |
| 355 | if (isWebhookFlow) return getWebhookCode(codeLang, null) |
| 356 | if (codeLang === 'Python') { |
| 357 | return `import requests |
| 358 | |
| 359 | API_URL = "${baseURL}/api/v1/prediction/${dialogProps.chatflowid}" |
| 360 | |
| 361 | def query(payload): |
| 362 | response = requests.post(API_URL, json=payload) |
| 363 | return response.json() |
| 364 | |
| 365 | output = 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 | |
| 385 | query({"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) |
no test coverage detected