From e1cbc0d5d43bde3aea1a2f392c098df80eea118d Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 7 Aug 2023 20:31:32 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(utils.ts):=20fix=20missing?= =?UTF-8?q?=20closing=20bracket=20in=20getChatInputField=20function=20?= =?UTF-8?q?=E2=9C=A8=20feat(utils.ts):=20add=20getChatInputField=20functio?= =?UTF-8?q?n=20to=20retrieve=20the=20chat=20input=20field=20based=20on=20t?= =?UTF-8?q?he=20current=20flow=20and=20tabs=20state?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/utils/utils.ts | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/frontend/src/utils/utils.ts b/src/frontend/src/utils/utils.ts index 462e72084..615e06d64 100644 --- a/src/frontend/src/utils/utils.ts +++ b/src/frontend/src/utils/utils.ts @@ -248,6 +248,26 @@ export function buildTweakObject(tweak) { return tweakString; } +/** + * Function to get Chat Input Field + * @param {FlowType} flow - The current flow. + * @param {TabsState} tabsState - The current tabs state. + * @returns {string} - The chat input field + */ +export function getChatInputField(flow: FlowType, tabsState?: TabsState) { + let chat_input_field = "text"; + + if ( + tabsState[flow.id] && + tabsState[flow.id].formKeysData && + tabsState[flow.id].formKeysData.input_keys + ) { + chat_input_field = Object.keys( + tabsState[flow.id].formKeysData.input_keys + )[0]; + } + return chat_input_field; + /** * Function to get the python code for the API * @param {string} flowId - The id of the flow @@ -365,6 +385,7 @@ export function getWidgetCode(flow: FlowType, tabsState?: TabsState): string { const flowId = flow.id; const flowName = flow.name; const inputs = buildInputs(tabsState, flow.id); + let chat_input_field = getChatInputField(flow, tabsState); return ` @@ -377,11 +398,9 @@ chat_input_field: Input key that you want the chat to send the user message with ${ tabsState[flow.id] && tabsState[flow.id].formKeysData ? `chat_inputs='${inputs}' - chat_input_field="${ - Object.keys(tabsState[flow.id].formKeysData.input_keys)[0] - }" + chat_input_field="${chat_input_field}" ` : "" - }host_url="http://localhost:7860" + }host_url="http://localhost:7860" >`; }