diff --git a/packages/ui/src/assets/images/embed.svg b/packages/ui/src/assets/images/embed.svg new file mode 100644 index 00000000..d20ceab0 --- /dev/null +++ b/packages/ui/src/assets/images/embed.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/ui/src/ui-component/dialog/APICodeDialog.js b/packages/ui/src/ui-component/dialog/APICodeDialog.js index f160c44d..1bd1dcb1 100644 --- a/packages/ui/src/ui-component/dialog/APICodeDialog.js +++ b/packages/ui/src/ui-component/dialog/APICodeDialog.js @@ -18,6 +18,7 @@ import { SET_CHATFLOW } from 'store/actions' import pythonSVG from 'assets/images/python.svg' import javascriptSVG from 'assets/images/javascript.svg' import cURLSVG from 'assets/images/cURL.svg' +import EmbedSVG from 'assets/images/embed.svg' // API import apiKeyApi from 'api/apikey' @@ -117,11 +118,21 @@ const getFormDataExamplesForCurl = (configData) => { return finalStr } +const embedCode = (chatflowid) => { + return `` +} + const APICodeDialog = ({ show, dialogProps, onCancel }) => { const portalElement = document.getElementById('portal') const navigate = useNavigate() const dispatch = useDispatch() - const codes = ['Python', 'JavaScript', 'cURL'] + const codes = ['Embed', 'Python', 'JavaScript', 'cURL'] const [value, setValue] = useState(0) const [keyOptions, setKeyOptions] = useState([]) const [apiKeys, setAPIKeys] = useState([]) @@ -196,6 +207,8 @@ output = query({ return `curl ${baseURL}/api/v1/prediction/${dialogProps.chatflowid} \\ -X POST \\ -d '{"question": "Hey, how are you?"}'` + } else if (codeLang === 'Embed') { + return embedCode(dialogProps.chatflowid) } return '' } @@ -236,6 +249,8 @@ output = query({ -X POST \\ -d '{"question": "Hey, how are you?"}' -H "Authorization: Bearer ${selectedApiKey?.apiKey}"` + } else if (codeLang === 'Embed') { + return embedCode(dialogProps.chatflowid) } return '' } @@ -243,7 +258,7 @@ output = query({ const getLang = (codeLang) => { if (codeLang === 'Python') { return 'python' - } else if (codeLang === 'JavaScript') { + } else if (codeLang === 'JavaScript' || codeLang === 'Embed') { return 'javascript' } else if (codeLang === 'cURL') { return 'bash' @@ -256,6 +271,8 @@ output = query({ return pythonSVG } else if (codeLang === 'JavaScript') { return javascriptSVG + } else if (codeLang === 'Embed') { + return EmbedSVG } else if (codeLang === 'cURL') { return cURLSVG } @@ -458,11 +475,7 @@ curl ${baseURL}/api/v1/prediction/${dialogProps.chatflowid} \\ {codes.map((codeLang, index) => ( + code } iconPosition='start' key={index} @@ -472,19 +485,29 @@ curl ${baseURL}/api/v1/prediction/${dialogProps.chatflowid} \\ ))} -
- onApiKeySelected(newValue)} - value={dialogProps.chatflowApiKeyId ?? chatflowApiKeyId ?? 'Choose an API key'} - /> -
+ {value !== 0 && ( +
+ onApiKeySelected(newValue)} + value={dialogProps.chatflowApiKeyId ?? chatflowApiKeyId ?? 'Choose an API key'} + /> +
+ )}
{codes.map((codeLang, index) => ( + {value === 0 && ( + <> + + Paste this anywhere in the {``} tag of your html file + +
+ + )} - - {checkboxVal && getConfigApi.data && getConfigApi.data.length > 0 && ( + {value !== 0 && } + {value !== 0 && checkboxVal && getConfigApi.data && getConfigApi.data.length > 0 && ( <> { setAPIDialogProps({ - title: 'Use this chatflow with API', + title: 'Embed in website or use as API', chatflowid: chatflow.id, chatflowApiKeyId: chatflow.apikeyid })