From cf78b47efd1f5e51880bb7970e90e196ee29b35b Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Thu, 18 Jul 2024 19:10:55 -0400 Subject: [PATCH 01/63] Inject message from user on conversation open. --- frontend/src/pages/chat/Chat.tsx | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index 2964882539..084a4a40ca 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -1,6 +1,7 @@ import { useRef, useState, useEffect, useContext, useLayoutEffect } from 'react' import { CommandBarButton, IconButton, Dialog, DialogType, Stack } from '@fluentui/react' import { SquareRegular, ShieldLockRegular, ErrorCircleRegular } from '@fluentui/react-icons' +import { useLocation } from 'react-router-dom' import ReactMarkdown from 'react-markdown' import remarkGfm from 'remark-gfm' @@ -45,6 +46,11 @@ const enum messageStatus { Done = 'Done' } +function useQuery() { + return new URLSearchParams(useLocation().search); +} + + const Chat = () => { const appStateContext = useContext(AppStateContext) const ui = appStateContext?.state.frontendSettings?.ui @@ -72,6 +78,24 @@ const Chat = () => { subText: errorMsg?.subtitle } + // Function to send a message to the chat server + const sendMessage = async (message: string) => { + try { + // Replace with your actual API call + const response = await fetch('/api/chat', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ message }), + }); + const data = await response.json(); + setMessages((prevMessages) => [...prevMessages, data]); + } catch (error) { + console.error('Error sending message:', error); + } + }; + const modalProps = { titleAriaId: 'labelId', subtitleAriaId: 'subTextId', @@ -739,6 +763,11 @@ const Chat = () => { ) } + // useEffect to send a message when the component mounts + useEffect(() => { + sendMessage('Feedback details: ' + URLSearchParams.toString()); + }, []); + return (
{showAuthMessage ? ( From 6574ef982f03d2025eef272800b3696a247c0a49 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Fri, 19 Jul 2024 01:54:59 -0400 Subject: [PATCH 02/63] Fix --- frontend/src/pages/chat/Chat.tsx | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index 084a4a40ca..71fff55813 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -78,24 +78,6 @@ const Chat = () => { subText: errorMsg?.subtitle } - // Function to send a message to the chat server - const sendMessage = async (message: string) => { - try { - // Replace with your actual API call - const response = await fetch('/api/chat', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ message }), - }); - const data = await response.json(); - setMessages((prevMessages) => [...prevMessages, data]); - } catch (error) { - console.error('Error sending message:', error); - } - }; - const modalProps = { titleAriaId: 'labelId', subtitleAriaId: 'subTextId', @@ -763,12 +745,14 @@ const Chat = () => { ) } - // useEffect to send a message when the component mounts - useEffect(() => { - sendMessage('Feedback details: ' + URLSearchParams.toString()); - }, []); - return ( +
{showAuthMessage ? ( From b06e179192b555d4efb1b4558680daa0b091bf78 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Fri, 19 Jul 2024 02:05:28 -0400 Subject: [PATCH 03/63] Try this --- frontend/src/pages/chat/Chat.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index 71fff55813..2dfd1ce793 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -745,14 +745,14 @@ const Chat = () => { ) } + // useEffect to send a message when the component mounts + useEffect(() => { + appStateContext?.state.isCosmosDBAvailable?.cosmosDB + ? makeApiRequestWithCosmosDB('Feedback details: ' + URLSearchParams.toString(), undefined) + : makeApiRequestWithoutCosmosDB('Feedback details: ' + URLSearchParams.toString(), undefined) + }, []); + return ( -
{showAuthMessage ? ( From 03750e0d543baf7dcacf776fd3fce21076e65133 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Sat, 20 Jul 2024 19:24:58 -0400 Subject: [PATCH 04/63] Try to fix --- frontend/src/pages/chat/Chat.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index 2dfd1ce793..9182ad892f 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -748,12 +748,12 @@ const Chat = () => { // useEffect to send a message when the component mounts useEffect(() => { appStateContext?.state.isCosmosDBAvailable?.cosmosDB - ? makeApiRequestWithCosmosDB('Feedback details: ' + URLSearchParams.toString(), undefined) - : makeApiRequestWithoutCosmosDB('Feedback details: ' + URLSearchParams.toString(), undefined) + ? makeApiRequestWithCosmosDB('Feedback details: ' + URLSearchParams, null) + : makeApiRequestWithoutCosmosDB('Feedback details: ' + URLSearchParams, null) }, []); - return ( -
+ return ( +
{showAuthMessage ? ( Date: Sun, 21 Jul 2024 15:43:14 -0400 Subject: [PATCH 05/63] Comment changes --- frontend/src/pages/chat/Chat.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index 9182ad892f..0fce5fd691 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -746,11 +746,11 @@ const Chat = () => { } // useEffect to send a message when the component mounts - useEffect(() => { + /* useEffect(() => { appStateContext?.state.isCosmosDBAvailable?.cosmosDB ? makeApiRequestWithCosmosDB('Feedback details: ' + URLSearchParams, null) : makeApiRequestWithoutCosmosDB('Feedback details: ' + URLSearchParams, null) - }, []); + }, []); */ return (
From 5f45bafe727e2750c25142bfe55fb3f0dd423541 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Sun, 21 Jul 2024 16:42:43 -0400 Subject: [PATCH 06/63] Try a fix --- frontend/src/pages/chat/Chat.tsx | 37 ++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index 0fce5fd691..e54759db1a 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -745,12 +745,37 @@ const Chat = () => { ) } - // useEffect to send a message when the component mounts - /* useEffect(() => { - appStateContext?.state.isCosmosDBAvailable?.cosmosDB - ? makeApiRequestWithCosmosDB('Feedback details: ' + URLSearchParams, null) - : makeApiRequestWithoutCosmosDB('Feedback details: ' + URLSearchParams, null) - }, []); */ + useEffect(() => { + const sendFeedback = async () => { + try { + const urlParams = new URLSearchParams(window.location.search).toString(); + const feedbackDetails = 'Feedback details: ' + urlParams; + + const controller = new AbortController(); + const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 second timeout + + const response = appStateContext?.state.isCosmosDBAvailable?.cosmosDB + ? await makeApiRequestWithCosmosDB(feedbackDetails, { signal: controller.signal }) + : await makeApiRequestWithoutCosmosDB(feedbackDetails, { signal: controller.signal }); + + clearTimeout(timeoutId); + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + + // Handle the response as needed + } catch (error) { + if (error.name === 'AbortError') { + console.error('Request timed out'); + } else { + console.error('An error occurred:', error); + } + } + }; + + sendFeedback(); + }, [appStateContext]); return (
From a46bd9875476eb91b3f085aaca36a8fb88ef3f59 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Sun, 21 Jul 2024 17:26:19 -0400 Subject: [PATCH 07/63] Try another change --- frontend/src/pages/chat/Chat.tsx | 50 ++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index e54759db1a..1b30595ca8 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -746,35 +746,43 @@ const Chat = () => { } useEffect(() => { - const sendFeedback = async () => { - try { - const urlParams = new URLSearchParams(window.location.search).toString(); - const feedbackDetails = 'Feedback details: ' + urlParams; + const handleWindowLoad = () => { + const sendFeedback = async () => { + try { + const urlParams = new URLSearchParams(window.location.search).toString(); + const feedbackDetails = 'Feedback details: ' + urlParams; - const controller = new AbortController(); - const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 second timeout + const controller = new AbortController(); + const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 second timeout - const response = appStateContext?.state.isCosmosDBAvailable?.cosmosDB - ? await makeApiRequestWithCosmosDB(feedbackDetails, { signal: controller.signal }) - : await makeApiRequestWithoutCosmosDB(feedbackDetails, { signal: controller.signal }); + const response = appStateContext?.state.isCosmosDBAvailable?.cosmosDB + ? await makeApiRequestWithCosmosDB(feedbackDetails, { signal: controller.signal }) + : await makeApiRequestWithoutCosmosDB(feedbackDetails, { signal: controller.signal }); - clearTimeout(timeoutId); + clearTimeout(timeoutId); - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); - } + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } - // Handle the response as needed - } catch (error) { - if (error.name === 'AbortError') { - console.error('Request timed out'); - } else { - console.error('An error occurred:', error); + // Handle the response as needed + } catch (error) { + if (error.name === 'AbortError') { + console.error('Request timed out'); + } else { + console.error('An error occurred:', error); + } } - } + }; + + sendFeedback(); }; - sendFeedback(); + window.addEventListener('load', handleWindowLoad); + + return () => { + window.removeEventListener('load', handleWindowLoad); + }; }, [appStateContext]); return ( From e1a17d398a8009399c765184c72463fe614cf492 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Sun, 21 Jul 2024 18:51:35 -0400 Subject: [PATCH 08/63] Test --- frontend/src/pages/chat/Chat.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index 1b30595ca8..708597dd99 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -89,6 +89,11 @@ const Chat = () => { const NO_CONTENT_ERROR = 'No content in messages object.' useEffect(() => { + setErrorMsg({ + title: 'Test', + subtitle: window.location.search + }) + toggleErrorDialog() if ( appStateContext?.state.isCosmosDBAvailable?.status !== CosmosDBStatus.Working && appStateContext?.state.isCosmosDBAvailable?.status !== CosmosDBStatus.NotConfigured && @@ -745,6 +750,7 @@ const Chat = () => { ) } + /* useEffect(() => { const handleWindowLoad = () => { const sendFeedback = async () => { @@ -784,6 +790,7 @@ const Chat = () => { window.removeEventListener('load', handleWindowLoad); }; }, [appStateContext]); +*/ return (
From 11d4c4b69799dc6cf90571a78917ac3b814c32ae Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Sun, 21 Jul 2024 19:01:30 -0400 Subject: [PATCH 09/63] Test --- frontend/src/pages/chat/Chat.tsx | 5 ----- 1 file changed, 5 deletions(-) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index 708597dd99..fdeac707a7 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -89,11 +89,6 @@ const Chat = () => { const NO_CONTENT_ERROR = 'No content in messages object.' useEffect(() => { - setErrorMsg({ - title: 'Test', - subtitle: window.location.search - }) - toggleErrorDialog() if ( appStateContext?.state.isCosmosDBAvailable?.status !== CosmosDBStatus.Working && appStateContext?.state.isCosmosDBAvailable?.status !== CosmosDBStatus.NotConfigured && From 18b49c52db80b97cad605b7de5b3ad12cec5d409 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Sun, 21 Jul 2024 19:57:00 -0400 Subject: [PATCH 10/63] Fix er --- frontend/src/pages/chat/Chat.tsx | 42 -------------------------------- 1 file changed, 42 deletions(-) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index fdeac707a7..d25fa4eef4 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -745,48 +745,6 @@ const Chat = () => { ) } - /* - useEffect(() => { - const handleWindowLoad = () => { - const sendFeedback = async () => { - try { - const urlParams = new URLSearchParams(window.location.search).toString(); - const feedbackDetails = 'Feedback details: ' + urlParams; - - const controller = new AbortController(); - const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 second timeout - - const response = appStateContext?.state.isCosmosDBAvailable?.cosmosDB - ? await makeApiRequestWithCosmosDB(feedbackDetails, { signal: controller.signal }) - : await makeApiRequestWithoutCosmosDB(feedbackDetails, { signal: controller.signal }); - - clearTimeout(timeoutId); - - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); - } - - // Handle the response as needed - } catch (error) { - if (error.name === 'AbortError') { - console.error('Request timed out'); - } else { - console.error('An error occurred:', error); - } - } - }; - - sendFeedback(); - }; - - window.addEventListener('load', handleWindowLoad); - - return () => { - window.removeEventListener('load', handleWindowLoad); - }; - }, [appStateContext]); -*/ - return (
{showAuthMessage ? ( From 8f5dcec853373dcf2b993b9b3134a1dac5f68085 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Sun, 21 Jul 2024 20:16:33 -0400 Subject: [PATCH 11/63] Try again --- frontend/src/pages/chat/Chat.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index d25fa4eef4..7c3255a326 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -114,6 +114,11 @@ const Chat = () => { useEffect(() => { if (!appStateContext?.state.isLoading) { setLogo(ui?.chat_logo || ui?.logo || Contoso) + setErrorMsg({ + title: 'Looks like we made it!', + subtitle: useLocation().search + }) + toggleErrorDialog() } }, [appStateContext?.state.isLoading]) From 4df5e1eb30a6dd890d8d8c3521a9f4e5577adde9 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Sun, 21 Jul 2024 20:21:21 -0400 Subject: [PATCH 12/63] Try again --- frontend/src/pages/chat/Chat.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index 7c3255a326..04c63b0e6d 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -116,7 +116,7 @@ const Chat = () => { setLogo(ui?.chat_logo || ui?.logo || Contoso) setErrorMsg({ title: 'Looks like we made it!', - subtitle: useLocation().search + subtitle: 'This is a test.' }) toggleErrorDialog() } From fca7f9a8298dcc8678dfddca87bfdc52913f852b Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 01:09:07 -0400 Subject: [PATCH 13/63] Try this --- frontend/src/pages/chat/Chat.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index 04c63b0e6d..4b83f76a00 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -113,12 +113,12 @@ const Chat = () => { useEffect(() => { if (!appStateContext?.state.isLoading) { - setLogo(ui?.chat_logo || ui?.logo || Contoso) setErrorMsg({ title: 'Looks like we made it!', subtitle: 'This is a test.' }) toggleErrorDialog() + setLogo(ui?.chat_logo || ui?.logo || Contoso) } }, [appStateContext?.state.isLoading]) From 6bd3389f61595ccec5930c7a5f33e8547ec26418 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 01:34:01 -0400 Subject: [PATCH 14/63] Try again --- frontend/src/pages/chat/Chat.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index 4b83f76a00..7dacb1cf20 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -47,7 +47,7 @@ const enum messageStatus { } function useQuery() { - return new URLSearchParams(useLocation().search); + return new URLSearchParams(useLocation()); } @@ -118,7 +118,7 @@ const Chat = () => { subtitle: 'This is a test.' }) toggleErrorDialog() - setLogo(ui?.chat_logo || ui?.logo || Contoso) + //setLogo(ui?.chat_logo || ui?.logo || Contoso) } }, [appStateContext?.state.isLoading]) From eaa2e807b04a8222d39507f4d15e3f93efaa87ae Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 01:50:01 -0400 Subject: [PATCH 15/63] Try again --- frontend/src/pages/chat/Chat.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index 7dacb1cf20..f1c58d71d7 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -47,7 +47,7 @@ const enum messageStatus { } function useQuery() { - return new URLSearchParams(useLocation()); + return new URLSearchParams('test'); } From 01b2d1f6a7b6f5417a2a7af8fcb2e266b33fc6ec Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 14:50:08 -0400 Subject: [PATCH 16/63] test --- frontend/src/pages/chat/Chat.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index f1c58d71d7..d06d70689a 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -47,7 +47,7 @@ const enum messageStatus { } function useQuery() { - return new URLSearchParams('test'); + return new URLSearchParams(useLocation().search); } @@ -113,12 +113,12 @@ const Chat = () => { useEffect(() => { if (!appStateContext?.state.isLoading) { + //setLogo(ui?.chat_logo || ui?.logo || Contoso) setErrorMsg({ - title: 'Looks like we made it!', - subtitle: 'This is a test.' + title: 'test', + subtitle: 'test' }) toggleErrorDialog() - //setLogo(ui?.chat_logo || ui?.logo || Contoso) } }, [appStateContext?.state.isLoading]) From 0ee11dff012bf8880253a8998bd7f9b001b2333b Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 15:06:51 -0400 Subject: [PATCH 17/63] Try another way to do this --- frontend/src/pages/chat/Chat.tsx | 36 ++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index d06d70689a..a20f4e160f 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -88,6 +88,22 @@ const Chat = () => { const [ASSISTANT, TOOL, ERROR] = ['assistant', 'tool', 'error'] const NO_CONTENT_ERROR = 'No content in messages object.' + const query = useQuery(); + const [dialogVisible, setDialogVisible] = useState(true); + const [queryParams, setQueryParams] = useState(""); + + useEffect(() => { + const params = []; + query.forEach((value, key) => { + params.push(`${key}: ${value}`); + }); + setQueryParams(params.join("\n")); + }, [query]); + + const hideDialog = () => { + setDialogVisible(false); + }; + useEffect(() => { if ( appStateContext?.state.isCosmosDBAvailable?.status !== CosmosDBStatus.Working && @@ -113,12 +129,7 @@ const Chat = () => { useEffect(() => { if (!appStateContext?.state.isLoading) { - //setLogo(ui?.chat_logo || ui?.logo || Contoso) - setErrorMsg({ - title: 'test', - subtitle: 'test' - }) - toggleErrorDialog() + setLogo(ui?.chat_logo || ui?.logo || Contoso) } }, [appStateContext?.state.isLoading]) @@ -1029,6 +1040,19 @@ const Chat = () => { appStateContext?.state.isCosmosDBAvailable?.status !== CosmosDBStatus.NotConfigured && } )} +
) } From 91f1345157195275a5e363de659dc197ffe389f0 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 15:17:28 -0400 Subject: [PATCH 18/63] Try again --- frontend/src/pages/chat/Chat.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index a20f4e160f..b171703446 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -2,6 +2,7 @@ import { useRef, useState, useEffect, useContext, useLayoutEffect } from 'react' import { CommandBarButton, IconButton, Dialog, DialogType, Stack } from '@fluentui/react' import { SquareRegular, ShieldLockRegular, ErrorCircleRegular } from '@fluentui/react-icons' import { useLocation } from 'react-router-dom' +import { useQuery } from 'react-query' import ReactMarkdown from 'react-markdown' import remarkGfm from 'remark-gfm' @@ -47,10 +48,10 @@ const enum messageStatus { } function useQuery() { + console.log("URL Search Params: ", useLocation().search); return new URLSearchParams(useLocation().search); } - const Chat = () => { const appStateContext = useContext(AppStateContext) const ui = appStateContext?.state.frontendSettings?.ui @@ -98,6 +99,9 @@ const Chat = () => { params.push(`${key}: ${value}`); }); setQueryParams(params.join("\n")); + + console.log("Query Params: ", params); + console.log("Dialog Visible: ", dialogVisible); }, [query]); const hideDialog = () => { From 51bf33db9514580759846a65d01148824bd06cd4 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 15:21:21 -0400 Subject: [PATCH 19/63] test --- frontend/src/pages/chat/Chat.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index b171703446..c3bf6977ed 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -53,6 +53,7 @@ function useQuery() { } const Chat = () => { + console.log('testing') const appStateContext = useContext(AppStateContext) const ui = appStateContext?.state.frontendSettings?.ui const AUTH_ENABLED = appStateContext?.state.frontendSettings?.auth_enabled From 3a007445418f618665229754209502420d27c2b6 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 15:32:35 -0400 Subject: [PATCH 20/63] Testing again... --- frontend/src/pages/chat/Chat.tsx | 1010 +----------------------------- 1 file changed, 5 insertions(+), 1005 deletions(-) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index c3bf6977ed..14b027a9c6 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -54,1012 +54,12 @@ function useQuery() { const Chat = () => { console.log('testing') - const appStateContext = useContext(AppStateContext) - const ui = appStateContext?.state.frontendSettings?.ui - const AUTH_ENABLED = appStateContext?.state.frontendSettings?.auth_enabled - const chatMessageStreamEnd = useRef(null) - const [isLoading, setIsLoading] = useState(false) - const [showLoadingMessage, setShowLoadingMessage] = useState(false) - const [activeCitation, setActiveCitation] = useState() - const [isCitationPanelOpen, setIsCitationPanelOpen] = useState(false) - const [isIntentsPanelOpen, setIsIntentsPanelOpen] = useState(false) - const abortFuncs = useRef([] as AbortController[]) - const [showAuthMessage, setShowAuthMessage] = useState() - const [messages, setMessages] = useState([]) - const [execResults, setExecResults] = useState([]) - const [processMessages, setProcessMessages] = useState(messageStatus.NotRunning) - const [clearingChat, setClearingChat] = useState(false) - const [hideErrorDialog, { toggle: toggleErrorDialog }] = useBoolean(true) - const [errorMsg, setErrorMsg] = useState() - const [logo, setLogo] = useState('') - - const errorDialogContentProps = { - type: DialogType.close, - title: errorMsg?.title, - closeButtonAriaLabel: 'Close', - subText: errorMsg?.subtitle - } - - const modalProps = { - titleAriaId: 'labelId', - subtitleAriaId: 'subTextId', - isBlocking: true, - styles: { main: { maxWidth: 450 } } - } - - const [ASSISTANT, TOOL, ERROR] = ['assistant', 'tool', 'error'] - const NO_CONTENT_ERROR = 'No content in messages object.' - - const query = useQuery(); - const [dialogVisible, setDialogVisible] = useState(true); - const [queryParams, setQueryParams] = useState(""); - - useEffect(() => { - const params = []; - query.forEach((value, key) => { - params.push(`${key}: ${value}`); - }); - setQueryParams(params.join("\n")); - - console.log("Query Params: ", params); - console.log("Dialog Visible: ", dialogVisible); - }, [query]); - - const hideDialog = () => { - setDialogVisible(false); - }; - - useEffect(() => { - if ( - appStateContext?.state.isCosmosDBAvailable?.status !== CosmosDBStatus.Working && - appStateContext?.state.isCosmosDBAvailable?.status !== CosmosDBStatus.NotConfigured && - appStateContext?.state.chatHistoryLoadingState === ChatHistoryLoadingState.Fail && - hideErrorDialog - ) { - let subtitle = `${appStateContext.state.isCosmosDBAvailable.status}. Please contact the site administrator.` - setErrorMsg({ - title: 'Chat history is not enabled', - subtitle: subtitle - }) - toggleErrorDialog() - } - }, [appStateContext?.state.isCosmosDBAvailable]) - - const handleErrorDialogClose = () => { - toggleErrorDialog() - setTimeout(() => { - setErrorMsg(null) - }, 500) - } - - useEffect(() => { - if (!appStateContext?.state.isLoading) { - setLogo(ui?.chat_logo || ui?.logo || Contoso) - } - }, [appStateContext?.state.isLoading]) - - useEffect(() => { - setIsLoading(appStateContext?.state.chatHistoryLoadingState === ChatHistoryLoadingState.Loading) - }, [appStateContext?.state.chatHistoryLoadingState]) - - const getUserInfoList = async () => { - if (!AUTH_ENABLED) { - setShowAuthMessage(false) - return - } - const userInfoList = await getUserInfo() - if (userInfoList.length === 0 && window.location.hostname !== '127.0.0.1') { - setShowAuthMessage(true) - } else { - setShowAuthMessage(false) - } - } - - let assistantMessage = {} as ChatMessage - let toolMessage = {} as ChatMessage - let assistantContent = '' - - const processResultMessage = (resultMessage: ChatMessage, userMessage: ChatMessage, conversationId?: string) => { - if (resultMessage.content.includes('all_exec_results')) { - const parsedExecResults = JSON.parse(resultMessage.content) as AzureSqlServerExecResults - setExecResults(parsedExecResults.all_exec_results) - } - - if (resultMessage.role === ASSISTANT) { - assistantContent += resultMessage.content - assistantMessage = resultMessage - assistantMessage.content = assistantContent - - if (resultMessage.context) { - toolMessage = { - id: uuid(), - role: TOOL, - content: resultMessage.context, - date: new Date().toISOString() - } - } - } - - if (resultMessage.role === TOOL) toolMessage = resultMessage - - if (!conversationId) { - isEmpty(toolMessage) - ? setMessages([...messages, userMessage, assistantMessage]) - : setMessages([...messages, userMessage, toolMessage, assistantMessage]) - } else { - isEmpty(toolMessage) - ? setMessages([...messages, assistantMessage]) - : setMessages([...messages, toolMessage, assistantMessage]) - } - } - - const makeApiRequestWithoutCosmosDB = async (question: string, conversationId?: string) => { - setIsLoading(true) - setShowLoadingMessage(true) - const abortController = new AbortController() - abortFuncs.current.unshift(abortController) - - const userMessage: ChatMessage = { - id: uuid(), - role: 'user', - content: question, - date: new Date().toISOString() - } - - let conversation: Conversation | null | undefined - if (!conversationId) { - conversation = { - id: conversationId ?? uuid(), - title: question, - messages: [userMessage], - date: new Date().toISOString() - } - } else { - conversation = appStateContext?.state?.currentChat - if (!conversation) { - console.error('Conversation not found.') - setIsLoading(false) - setShowLoadingMessage(false) - abortFuncs.current = abortFuncs.current.filter(a => a !== abortController) - return - } else { - conversation.messages.push(userMessage) - } - } - - appStateContext?.dispatch({ type: 'UPDATE_CURRENT_CHAT', payload: conversation }) - setMessages(conversation.messages) - - const request: ConversationRequest = { - messages: [...conversation.messages.filter(answer => answer.role !== ERROR)] - } - - let result = {} as ChatResponse - try { - const response = await conversationApi(request, abortController.signal) - if (response?.body) { - const reader = response.body.getReader() - - let runningText = '' - while (true) { - setProcessMessages(messageStatus.Processing) - const { done, value } = await reader.read() - if (done) break - - var text = new TextDecoder('utf-8').decode(value) - const objects = text.split('\n') - objects.forEach(obj => { - try { - if (obj !== '' && obj !== '{}') { - runningText += obj - result = JSON.parse(runningText) - if (result.choices?.length > 0) { - result.choices[0].messages.forEach(msg => { - msg.id = result.id - msg.date = new Date().toISOString() - }) - if (result.choices[0].messages?.some(m => m.role === ASSISTANT)) { - setShowLoadingMessage(false) - } - result.choices[0].messages.forEach(resultObj => { - processResultMessage(resultObj, userMessage, conversationId) - }) - } else if (result.error) { - throw Error(result.error) - } - runningText = '' - } - } catch (e) { - if (!(e instanceof SyntaxError)) { - console.error(e) - throw e - } else { - console.log('Incomplete message. Continuing...') - } - } - }) - } - conversation.messages.push(toolMessage, assistantMessage) - appStateContext?.dispatch({ type: 'UPDATE_CURRENT_CHAT', payload: conversation }) - setMessages([...messages, toolMessage, assistantMessage]) - } - } catch (e) { - if (!abortController.signal.aborted) { - let errorMessage = - 'An error occurred. Please try again. If the problem persists, please contact the site administrator.' - if (result.error?.message) { - errorMessage = result.error.message - } else if (typeof result.error === 'string') { - errorMessage = result.error - } - - errorMessage = parseErrorMessage(errorMessage) - - let errorChatMsg: ChatMessage = { - id: uuid(), - role: ERROR, - content: errorMessage, - date: new Date().toISOString() - } - conversation.messages.push(errorChatMsg) - appStateContext?.dispatch({ type: 'UPDATE_CURRENT_CHAT', payload: conversation }) - setMessages([...messages, errorChatMsg]) - } else { - setMessages([...messages, userMessage]) - } - } finally { - setIsLoading(false) - setShowLoadingMessage(false) - abortFuncs.current = abortFuncs.current.filter(a => a !== abortController) - setProcessMessages(messageStatus.Done) - } - - return abortController.abort() - } - - const makeApiRequestWithCosmosDB = async (question: string, conversationId?: string) => { - setIsLoading(true) - setShowLoadingMessage(true) - const abortController = new AbortController() - abortFuncs.current.unshift(abortController) - - const userMessage: ChatMessage = { - id: uuid(), - role: 'user', - content: question, - date: new Date().toISOString() - } - - //api call params set here (generate) - let request: ConversationRequest - let conversation - if (conversationId) { - conversation = appStateContext?.state?.chatHistory?.find(conv => conv.id === conversationId) - if (!conversation) { - console.error('Conversation not found.') - setIsLoading(false) - setShowLoadingMessage(false) - abortFuncs.current = abortFuncs.current.filter(a => a !== abortController) - return - } else { - conversation.messages.push(userMessage) - request = { - messages: [...conversation.messages.filter(answer => answer.role !== ERROR)] - } - } - } else { - request = { - messages: [userMessage].filter(answer => answer.role !== ERROR) - } - setMessages(request.messages) - } - let result = {} as ChatResponse - var errorResponseMessage = 'Please try again. If the problem persists, please contact the site administrator.' - try { - const response = conversationId - ? await historyGenerate(request, abortController.signal, conversationId) - : await historyGenerate(request, abortController.signal) - if (!response?.ok) { - const responseJson = await response.json() - errorResponseMessage = - responseJson.error === undefined ? errorResponseMessage : parseErrorMessage(responseJson.error) - let errorChatMsg: ChatMessage = { - id: uuid(), - role: ERROR, - content: `There was an error generating a response. Chat history can't be saved at this time. ${errorResponseMessage}`, - date: new Date().toISOString() - } - let resultConversation - if (conversationId) { - resultConversation = appStateContext?.state?.chatHistory?.find(conv => conv.id === conversationId) - if (!resultConversation) { - console.error('Conversation not found.') - setIsLoading(false) - setShowLoadingMessage(false) - abortFuncs.current = abortFuncs.current.filter(a => a !== abortController) - return - } - resultConversation.messages.push(errorChatMsg) - } else { - setMessages([...messages, userMessage, errorChatMsg]) - setIsLoading(false) - setShowLoadingMessage(false) - abortFuncs.current = abortFuncs.current.filter(a => a !== abortController) - return - } - appStateContext?.dispatch({ type: 'UPDATE_CURRENT_CHAT', payload: resultConversation }) - setMessages([...resultConversation.messages]) - return - } - if (response?.body) { - const reader = response.body.getReader() - - let runningText = '' - while (true) { - setProcessMessages(messageStatus.Processing) - const { done, value } = await reader.read() - if (done) break - - var text = new TextDecoder('utf-8').decode(value) - const objects = text.split('\n') - objects.forEach(obj => { - try { - if (obj !== '' && obj !== '{}') { - runningText += obj - result = JSON.parse(runningText) - if (!result.choices?.[0]?.messages?.[0].content) { - errorResponseMessage = NO_CONTENT_ERROR - throw Error() - } - if (result.choices?.length > 0) { - result.choices[0].messages.forEach(msg => { - msg.id = result.id - msg.date = new Date().toISOString() - }) - if (result.choices[0].messages?.some(m => m.role === ASSISTANT)) { - setShowLoadingMessage(false) - } - result.choices[0].messages.forEach(resultObj => { - processResultMessage(resultObj, userMessage, conversationId) - }) - } - runningText = '' - } else if (result.error) { - throw Error(result.error) - } - } catch (e) { - if (!(e instanceof SyntaxError)) { - console.error(e) - throw e - } else { - console.log('Incomplete message. Continuing...') - } - } - }) - } - - let resultConversation - if (conversationId) { - resultConversation = appStateContext?.state?.chatHistory?.find(conv => conv.id === conversationId) - if (!resultConversation) { - console.error('Conversation not found.') - setIsLoading(false) - setShowLoadingMessage(false) - abortFuncs.current = abortFuncs.current.filter(a => a !== abortController) - return - } - isEmpty(toolMessage) - ? resultConversation.messages.push(assistantMessage) - : resultConversation.messages.push(toolMessage, assistantMessage) - } else { - resultConversation = { - id: result.history_metadata.conversation_id, - title: result.history_metadata.title, - messages: [userMessage], - date: result.history_metadata.date - } - isEmpty(toolMessage) - ? resultConversation.messages.push(assistantMessage) - : resultConversation.messages.push(toolMessage, assistantMessage) - } - if (!resultConversation) { - setIsLoading(false) - setShowLoadingMessage(false) - abortFuncs.current = abortFuncs.current.filter(a => a !== abortController) - return - } - appStateContext?.dispatch({ type: 'UPDATE_CURRENT_CHAT', payload: resultConversation }) - isEmpty(toolMessage) - ? setMessages([...messages, assistantMessage]) - : setMessages([...messages, toolMessage, assistantMessage]) - } - } catch (e) { - if (!abortController.signal.aborted) { - let errorMessage = `An error occurred. ${errorResponseMessage}` - if (result.error?.message) { - errorMessage = result.error.message - } else if (typeof result.error === 'string') { - errorMessage = result.error - } - - errorMessage = parseErrorMessage(errorMessage) - - let errorChatMsg: ChatMessage = { - id: uuid(), - role: ERROR, - content: errorMessage, - date: new Date().toISOString() - } - let resultConversation - if (conversationId) { - resultConversation = appStateContext?.state?.chatHistory?.find(conv => conv.id === conversationId) - if (!resultConversation) { - console.error('Conversation not found.') - setIsLoading(false) - setShowLoadingMessage(false) - abortFuncs.current = abortFuncs.current.filter(a => a !== abortController) - return - } - resultConversation.messages.push(errorChatMsg) - } else { - if (!result.history_metadata) { - console.error('Error retrieving data.', result) - let errorChatMsg: ChatMessage = { - id: uuid(), - role: ERROR, - content: errorMessage, - date: new Date().toISOString() - } - setMessages([...messages, userMessage, errorChatMsg]) - setIsLoading(false) - setShowLoadingMessage(false) - abortFuncs.current = abortFuncs.current.filter(a => a !== abortController) - return - } - resultConversation = { - id: result.history_metadata.conversation_id, - title: result.history_metadata.title, - messages: [userMessage], - date: result.history_metadata.date - } - resultConversation.messages.push(errorChatMsg) - } - if (!resultConversation) { - setIsLoading(false) - setShowLoadingMessage(false) - abortFuncs.current = abortFuncs.current.filter(a => a !== abortController) - return - } - appStateContext?.dispatch({ type: 'UPDATE_CURRENT_CHAT', payload: resultConversation }) - setMessages([...messages, errorChatMsg]) - } else { - setMessages([...messages, userMessage]) - } - } finally { - setIsLoading(false) - setShowLoadingMessage(false) - abortFuncs.current = abortFuncs.current.filter(a => a !== abortController) - setProcessMessages(messageStatus.Done) - } - return abortController.abort() - } - - const clearChat = async () => { - setClearingChat(true) - if (appStateContext?.state.currentChat?.id && appStateContext?.state.isCosmosDBAvailable.cosmosDB) { - let response = await historyClear(appStateContext?.state.currentChat.id) - if (!response.ok) { - setErrorMsg({ - title: 'Error clearing current chat', - subtitle: 'Please try again. If the problem persists, please contact the site administrator.' - }) - toggleErrorDialog() - } else { - appStateContext?.dispatch({ - type: 'DELETE_CURRENT_CHAT_MESSAGES', - payload: appStateContext?.state.currentChat.id - }) - appStateContext?.dispatch({ type: 'UPDATE_CHAT_HISTORY', payload: appStateContext?.state.currentChat }) - setActiveCitation(undefined) - setIsCitationPanelOpen(false) - setIsIntentsPanelOpen(false) - setMessages([]) - } - } - setClearingChat(false) - } - - const tryGetRaiPrettyError = (errorMessage: string) => { - try { - // Using a regex to extract the JSON part that contains "innererror" - const match = errorMessage.match(/'innererror': ({.*})\}\}/) - if (match) { - // Replacing single quotes with double quotes and converting Python-like booleans to JSON booleans - const fixedJson = match[1] - .replace(/'/g, '"') - .replace(/\bTrue\b/g, 'true') - .replace(/\bFalse\b/g, 'false') - const innerErrorJson = JSON.parse(fixedJson) - let reason = '' - // Check if jailbreak content filter is the reason of the error - const jailbreak = innerErrorJson.content_filter_result.jailbreak - if (jailbreak.filtered === true) { - reason = 'Jailbreak' - } - - // Returning the prettified error message - if (reason !== '') { - return ( - 'The prompt was filtered due to triggering Azure OpenAI’s content filtering system.\n' + - 'Reason: This prompt contains content flagged as ' + - reason + - '\n\n' + - 'Please modify your prompt and retry. Learn more: https://go.microsoft.com/fwlink/?linkid=2198766' - ) - } - } - } catch (e) { - console.error('Failed to parse the error:', e) - } - return errorMessage - } - - const parseErrorMessage = (errorMessage: string) => { - let errorCodeMessage = errorMessage.substring(0, errorMessage.indexOf('-') + 1) - const innerErrorCue = "{\\'error\\': {\\'message\\': " - if (errorMessage.includes(innerErrorCue)) { - try { - let innerErrorString = errorMessage.substring(errorMessage.indexOf(innerErrorCue)) - if (innerErrorString.endsWith("'}}")) { - innerErrorString = innerErrorString.substring(0, innerErrorString.length - 3) - } - innerErrorString = innerErrorString.replaceAll("\\'", "'") - let newErrorMessage = errorCodeMessage + ' ' + innerErrorString - errorMessage = newErrorMessage - } catch (e) { - console.error('Error parsing inner error message: ', e) - } - } - - return tryGetRaiPrettyError(errorMessage) - } - - const newChat = () => { - setProcessMessages(messageStatus.Processing) - setMessages([]) - setIsCitationPanelOpen(false) - setIsIntentsPanelOpen(false) - setActiveCitation(undefined) - appStateContext?.dispatch({ type: 'UPDATE_CURRENT_CHAT', payload: null }) - setProcessMessages(messageStatus.Done) - } - - const stopGenerating = () => { - abortFuncs.current.forEach(a => a.abort()) - setShowLoadingMessage(false) - setIsLoading(false) - } - - useEffect(() => { - if (appStateContext?.state.currentChat) { - setMessages(appStateContext.state.currentChat.messages) - } else { - setMessages([]) - } - }, [appStateContext?.state.currentChat]) - - useLayoutEffect(() => { - const saveToDB = async (messages: ChatMessage[], id: string) => { - const response = await historyUpdate(messages, id) - return response - } - - if (appStateContext && appStateContext.state.currentChat && processMessages === messageStatus.Done) { - if (appStateContext.state.isCosmosDBAvailable.cosmosDB) { - if (!appStateContext?.state.currentChat?.messages) { - console.error('Failure fetching current chat state.') - return - } - const noContentError = appStateContext.state.currentChat.messages.find(m => m.role === ERROR) - - if (!noContentError?.content.includes(NO_CONTENT_ERROR)) { - saveToDB(appStateContext.state.currentChat.messages, appStateContext.state.currentChat.id) - .then(res => { - if (!res.ok) { - let errorMessage = - "An error occurred. Answers can't be saved at this time. If the problem persists, please contact the site administrator." - let errorChatMsg: ChatMessage = { - id: uuid(), - role: ERROR, - content: errorMessage, - date: new Date().toISOString() - } - if (!appStateContext?.state.currentChat?.messages) { - let err: Error = { - ...new Error(), - message: 'Failure fetching current chat state.' - } - throw err - } - setMessages([...appStateContext?.state.currentChat?.messages, errorChatMsg]) - } - return res as Response - }) - .catch(err => { - console.error('Error: ', err) - let errRes: Response = { - ...new Response(), - ok: false, - status: 500 - } - return errRes - }) - } - } else { - } - appStateContext?.dispatch({ type: 'UPDATE_CHAT_HISTORY', payload: appStateContext.state.currentChat }) - setMessages(appStateContext.state.currentChat.messages) - setProcessMessages(messageStatus.NotRunning) - } - }, [processMessages]) - - useEffect(() => { - if (AUTH_ENABLED !== undefined) getUserInfoList() - }, [AUTH_ENABLED]) - - useLayoutEffect(() => { - chatMessageStreamEnd.current?.scrollIntoView({ behavior: 'smooth' }) - }, [showLoadingMessage, processMessages]) - - const onShowCitation = (citation: Citation) => { - setActiveCitation(citation) - setIsCitationPanelOpen(true) - } - - const onShowExecResult = () => { - setIsIntentsPanelOpen(true) - } - - const onViewSource = (citation: Citation) => { - if (citation.url && !citation.url.includes('blob.core')) { - window.open(citation.url, '_blank') - } - } - - const parseCitationFromMessage = (message: ChatMessage) => { - if (message?.role && message?.role === 'tool') { - try { - const toolMessage = JSON.parse(message.content) as ToolMessageContent - return toolMessage.citations - } catch { - return [] - } - } - return [] - } - - const parsePlotFromMessage = (message: ChatMessage) => { - if (message?.role && message?.role === "tool") { - try { - const execResults = JSON.parse(message.content) as AzureSqlServerExecResults; - const codeExecResult = execResults.all_exec_results.at(-1)?.code_exec_result; - if (codeExecResult === undefined) { - return null; - } - return codeExecResult; - } - catch { - return null; - } - // const execResults = JSON.parse(message.content) as AzureSqlServerExecResults; - // return execResults.all_exec_results.at(-1)?.code_exec_result; - } - return null; - } - - const disabledButton = () => { - return ( - isLoading || - (messages && messages.length === 0) || - clearingChat || - appStateContext?.state.chatHistoryLoadingState === ChatHistoryLoadingState.Loading - ) - } - - return ( -
- {showAuthMessage ? ( - - -

Authentication Not Configured

-

- This app does not have authentication configured. Please add an identity provider by finding your app in the{' '} - - Azure Portal - - and following{' '} - - these instructions - - . -

-

- Authentication configuration takes a few minutes to apply. -

-

- If you deployed in the last 10 minutes, please wait and reload the page after 10 minutes. -

-
- ) : ( - -
- {!messages || messages.length < 1 ? ( - - -

{ui?.chat_title}

-

{ui?.chat_description}

-
- ) : ( -
- {messages.map((answer, index) => ( - <> - {answer.role === 'user' ? ( -
-
{answer.content}
-
- ) : answer.role === 'assistant' ? ( -
- onShowCitation(c)} - onExectResultClicked={() => onShowExecResult()} - /> -
- ) : answer.role === ERROR ? ( -
- - - Error - - {answer.content} -
- ) : null} - - ))} - {showLoadingMessage && ( - <> -
- null} - onExectResultClicked={() => null} - /> -
- - )} -
-
- )} - - - {isLoading && messages.length > 0 && ( - (e.key === 'Enter' || e.key === ' ' ? stopGenerating() : null)}> - - )} - - {appStateContext?.state.isCosmosDBAvailable?.status !== CosmosDBStatus.NotConfigured && ( - - )} - - - - { - appStateContext?.state.isCosmosDBAvailable?.cosmosDB - ? makeApiRequestWithCosmosDB(question, id) - : makeApiRequestWithoutCosmosDB(question, id) - }} - conversationId={ - appStateContext?.state.currentChat?.id ? appStateContext?.state.currentChat?.id : undefined - } - /> - -
- {/* Citation Panel */} - {messages && messages.length > 0 && isCitationPanelOpen && activeCitation && ( - - - - Citations - - setIsCitationPanelOpen(false)} - /> - -
onViewSource(activeCitation)}> - {activeCitation.title} -
-
- -
-
- )} - {messages && messages.length > 0 && isIntentsPanelOpen && ( - - - - Intents - - setIsIntentsPanelOpen(false)} - /> - - - {execResults.map((execResult) => { - return ( - - <>Intent:

{execResult.intent}

- {execResult.search_query && <>Search Query: - - {execResult.search_query} - } - {execResult.search_result && <>Search Result:

{execResult.search_result}

} - {execResult.code_generated && <>Code Generated: - - {execResult.code_generated} - - } -
- ) - })} -
-
- )} - {appStateContext?.state.isChatHistoryOpen && - appStateContext?.state.isCosmosDBAvailable?.status !== CosmosDBStatus.NotConfigured && } - - )} - + return ( +
+

Chat Component Test

+

This is a test to ensure the component is being rendered correctly.

) -} + } export default Chat From 023c5c0702024f2fdda391f2833bdd7147976df3 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 15:48:01 -0400 Subject: [PATCH 21/63] Update build settings --- .github/workflows/check-static-files.yml | 1 + .github/workflows/docker-image-build.yml | 1 + .github/workflows/docker-image-publish.yml | 1 + .github/workflows/node.js.yml | 4 ++-- .github/workflows/python-app.yml | 4 ++-- .github/workflows/sample-app-github-cd.yml | 1 + 6 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/check-static-files.yml b/.github/workflows/check-static-files.yml index c45568ee85..0c688be28f 100644 --- a/.github/workflows/check-static-files.yml +++ b/.github/workflows/check-static-files.yml @@ -4,6 +4,7 @@ on: pull_request: branches: - main + - AddQueryStringForInitialPrompting jobs: changed_files: diff --git a/.github/workflows/docker-image-build.yml b/.github/workflows/docker-image-build.yml index 44f852dbd7..eb7b7691f6 100644 --- a/.github/workflows/docker-image-build.yml +++ b/.github/workflows/docker-image-build.yml @@ -4,6 +4,7 @@ on: pull_request: branches: - main + - AddQueryStringForInitialPrompting jobs: diff --git a/.github/workflows/docker-image-publish.yml b/.github/workflows/docker-image-publish.yml index 7a3ccdc1ba..4940b2c63e 100644 --- a/.github/workflows/docker-image-publish.yml +++ b/.github/workflows/docker-image-publish.yml @@ -4,6 +4,7 @@ on: push: branches: - main + - AddQueryStringForInitialPrompting jobs: diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index c261c90580..59a4d4cb96 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -5,9 +5,9 @@ name: Build Frontend on: push: - branches: [ "main" ] + branches: [ "main", "AddQueryStringForInitialPrompting" ] pull_request: - branches: [ "main" ] + branches: [ "main", "AddQueryStringForInitialPrompting"] jobs: diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 5895601d5d..a0d1197207 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -5,9 +5,9 @@ name: Python application on: push: - branches: [ "main" ] + branches: [ "main", "AddQueryStringForInitialPrompting" ] pull_request: - branches: [ "main" ] + branches: [ "main", "AddQueryStringForInitialPrompting" ] permissions: contents: read diff --git a/.github/workflows/sample-app-github-cd.yml b/.github/workflows/sample-app-github-cd.yml index 25c62ec876..48ba73ded6 100644 --- a/.github/workflows/sample-app-github-cd.yml +++ b/.github/workflows/sample-app-github-cd.yml @@ -8,6 +8,7 @@ on: push: branches: - main + - AddQueryStringForInitialPrompting workflow_dispatch: jobs: From e8ea948f1da6bec084908b51b7924d5211110d18 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 15:51:21 -0400 Subject: [PATCH 22/63] Try again, on the right track now. --- .github/workflows/docker-image-build.yml | 1 - .github/workflows/docker-image-publish.yml | 1 - .github/workflows/node.js.yml | 4 ++-- .github/workflows/python-app.yml | 4 ++-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docker-image-build.yml b/.github/workflows/docker-image-build.yml index eb7b7691f6..44f852dbd7 100644 --- a/.github/workflows/docker-image-build.yml +++ b/.github/workflows/docker-image-build.yml @@ -4,7 +4,6 @@ on: pull_request: branches: - main - - AddQueryStringForInitialPrompting jobs: diff --git a/.github/workflows/docker-image-publish.yml b/.github/workflows/docker-image-publish.yml index 4940b2c63e..7a3ccdc1ba 100644 --- a/.github/workflows/docker-image-publish.yml +++ b/.github/workflows/docker-image-publish.yml @@ -4,7 +4,6 @@ on: push: branches: - main - - AddQueryStringForInitialPrompting jobs: diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 59a4d4cb96..c261c90580 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -5,9 +5,9 @@ name: Build Frontend on: push: - branches: [ "main", "AddQueryStringForInitialPrompting" ] + branches: [ "main" ] pull_request: - branches: [ "main", "AddQueryStringForInitialPrompting"] + branches: [ "main" ] jobs: diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index a0d1197207..5895601d5d 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -5,9 +5,9 @@ name: Python application on: push: - branches: [ "main", "AddQueryStringForInitialPrompting" ] + branches: [ "main" ] pull_request: - branches: [ "main", "AddQueryStringForInitialPrompting" ] + branches: [ "main" ] permissions: contents: read From 310caaeb718cb5b1ba8f698e20c9ffdb46caab29 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 15:56:10 -0400 Subject: [PATCH 23/63] Try this --- .github/workflows/sample-app-github-cd.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/sample-app-github-cd.yml b/.github/workflows/sample-app-github-cd.yml index 48ba73ded6..d3f0d9f1a4 100644 --- a/.github/workflows/sample-app-github-cd.yml +++ b/.github/workflows/sample-app-github-cd.yml @@ -30,6 +30,9 @@ jobs: - name: Install dependencies run: pip install -r requirements.txt + + - name: Install react-query + run: npm install react-query @types/react-query # Optional: Add step to run tests here (PyTest, Django test suites, etc.) From 2f3f022b318f4e88c94c30bf05f84373cce6a1d8 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 16:01:01 -0400 Subject: [PATCH 24/63] Try again --- .github/workflows/docker-image-build.yml | 1 + .github/workflows/docker-image-publish.yml | 1 + .github/workflows/node.js.yml | 1 + .github/workflows/python-app.yml | 4 ++-- .github/workflows/sample-app-github-cd.yml | 5 +---- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docker-image-build.yml b/.github/workflows/docker-image-build.yml index 44f852dbd7..eb7b7691f6 100644 --- a/.github/workflows/docker-image-build.yml +++ b/.github/workflows/docker-image-build.yml @@ -4,6 +4,7 @@ on: pull_request: branches: - main + - AddQueryStringForInitialPrompting jobs: diff --git a/.github/workflows/docker-image-publish.yml b/.github/workflows/docker-image-publish.yml index 7a3ccdc1ba..4940b2c63e 100644 --- a/.github/workflows/docker-image-publish.yml +++ b/.github/workflows/docker-image-publish.yml @@ -4,6 +4,7 @@ on: push: branches: - main + - AddQueryStringForInitialPrompting jobs: diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index c261c90580..4ab22e92a2 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -32,3 +32,4 @@ jobs: - run: npm ci - run: NODE_OPTIONS=--max_old_space_size=8192 npm run build --if-present - run: npm run test --if-present + - run: npm install react-query @types/react-query diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 5895601d5d..a0d1197207 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -5,9 +5,9 @@ name: Python application on: push: - branches: [ "main" ] + branches: [ "main", "AddQueryStringForInitialPrompting" ] pull_request: - branches: [ "main" ] + branches: [ "main", "AddQueryStringForInitialPrompting" ] permissions: contents: read diff --git a/.github/workflows/sample-app-github-cd.yml b/.github/workflows/sample-app-github-cd.yml index d3f0d9f1a4..a8eb298469 100644 --- a/.github/workflows/sample-app-github-cd.yml +++ b/.github/workflows/sample-app-github-cd.yml @@ -30,10 +30,7 @@ jobs: - name: Install dependencies run: pip install -r requirements.txt - - - name: Install react-query - run: npm install react-query @types/react-query - + # Optional: Add step to run tests here (PyTest, Django test suites, etc.) - name: Zip artifact for deployment From fbc2b2a72cee486193f28cc43e283917ec32e82d Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 16:02:42 -0400 Subject: [PATCH 25/63] Another fix --- .github/workflows/node.js.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 4ab22e92a2..1db5a95442 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -5,9 +5,9 @@ name: Build Frontend on: push: - branches: [ "main" ] + branches: [ "main", "AddQueryStringForInitialPrompting" ] pull_request: - branches: [ "main" ] + branches: [ "main", "AddQueryStringForInitialPrompting" ] jobs: From 9b1b1324ecd5102c4d633b74420560eb9990235a Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 16:10:03 -0400 Subject: [PATCH 26/63] Try this --- .github/workflows/node.js.yml | 1 - .github/workflows/sample-app-github-cd.yml | 12 ++++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 1db5a95442..e6d6d8b884 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -32,4 +32,3 @@ jobs: - run: npm ci - run: NODE_OPTIONS=--max_old_space_size=8192 npm run build --if-present - run: npm run test --if-present - - run: npm install react-query @types/react-query diff --git a/.github/workflows/sample-app-github-cd.yml b/.github/workflows/sample-app-github-cd.yml index a8eb298469..eb5cab091b 100644 --- a/.github/workflows/sample-app-github-cd.yml +++ b/.github/workflows/sample-app-github-cd.yml @@ -29,10 +29,18 @@ jobs: source venv/bin/activate - name: Install dependencies - run: pip install -r requirements.txt - + run: pip install -r requirements.txt # Optional: Add step to run tests here (PyTest, Django test suites, etc.) + - name: Install npm dependencies + run: npm install + + - name: Install react-query + run: npm install react-query @types/react-query + + - name: Build project + run: npm run build + - name: Zip artifact for deployment run: zip release.zip ./* -r From 4592fd08e18a981a8d1cc3385e6643eb39100ef2 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 16:13:19 -0400 Subject: [PATCH 27/63] I think we got it now! --- .github/workflows/node.js.yml | 1 + .github/workflows/sample-app-github-cd.yml | 9 --------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index e6d6d8b884..09141434b4 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -30,5 +30,6 @@ jobs: cache: 'npm' cache-dependency-path: '**/package-lock.json' - run: npm ci + - run: npm install react-query @types/react-query - run: NODE_OPTIONS=--max_old_space_size=8192 npm run build --if-present - run: npm run test --if-present diff --git a/.github/workflows/sample-app-github-cd.yml b/.github/workflows/sample-app-github-cd.yml index eb5cab091b..aed03b6d67 100644 --- a/.github/workflows/sample-app-github-cd.yml +++ b/.github/workflows/sample-app-github-cd.yml @@ -32,15 +32,6 @@ jobs: run: pip install -r requirements.txt # Optional: Add step to run tests here (PyTest, Django test suites, etc.) - - name: Install npm dependencies - run: npm install - - - name: Install react-query - run: npm install react-query @types/react-query - - - name: Build project - run: npm run build - - name: Zip artifact for deployment run: zip release.zip ./* -r From 81059c3edc200c100ef0dfeb19b2acb1d6e7cc76 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 16:26:14 -0400 Subject: [PATCH 28/63] Another try --- .github/workflows/node.js.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 09141434b4..94c9fc56af 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -30,6 +30,8 @@ jobs: cache: 'npm' cache-dependency-path: '**/package-lock.json' - run: npm ci - - run: npm install react-query @types/react-query + - run: npm install react-query + - run: npm install mapbox-gl eslint-plugin-import@^2.25.2 + - run: npm audit fix - run: NODE_OPTIONS=--max_old_space_size=8192 npm run build --if-present - run: npm run test --if-present From a43b1fa257a1d047ae2da3aff9b0f6777f779f48 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 16:28:45 -0400 Subject: [PATCH 29/63] Fix --- frontend/src/pages/chat/Chat.tsx | 1015 +++++++++++++++++++++++++++++- 1 file changed, 1007 insertions(+), 8 deletions(-) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index 14b027a9c6..df2d10a35e 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -47,19 +47,1018 @@ const enum messageStatus { Done = 'Done' } -function useQuery() { - console.log("URL Search Params: ", useLocation().search); +function useQueryParams() { + console.log("URL Params: ", useLocation().search); return new URLSearchParams(useLocation().search); } const Chat = () => { - console.log('testing') - return ( -
-

Chat Component Test

-

This is a test to ensure the component is being rendered correctly.

+ const appStateContext = useContext(AppStateContext) + const ui = appStateContext?.state.frontendSettings?.ui + const AUTH_ENABLED = appStateContext?.state.frontendSettings?.auth_enabled + const chatMessageStreamEnd = useRef(null) + const [isLoading, setIsLoading] = useState(false) + const [showLoadingMessage, setShowLoadingMessage] = useState(false) + const [activeCitation, setActiveCitation] = useState() + const [isCitationPanelOpen, setIsCitationPanelOpen] = useState(false) + const [isIntentsPanelOpen, setIsIntentsPanelOpen] = useState(false) + const abortFuncs = useRef([] as AbortController[]) + const [showAuthMessage, setShowAuthMessage] = useState() + const [messages, setMessages] = useState([]) + const [execResults, setExecResults] = useState([]) + const [processMessages, setProcessMessages] = useState(messageStatus.NotRunning) + const [clearingChat, setClearingChat] = useState(false) + const [hideErrorDialog, { toggle: toggleErrorDialog }] = useBoolean(true) + const [errorMsg, setErrorMsg] = useState() + const [logo, setLogo] = useState('') + + const errorDialogContentProps = { + type: DialogType.close, + title: errorMsg?.title, + closeButtonAriaLabel: 'Close', + subText: errorMsg?.subtitle + } + + const modalProps = { + titleAriaId: 'labelId', + subtitleAriaId: 'subTextId', + isBlocking: true, + styles: { main: { maxWidth: 450 } } + } + + const [ASSISTANT, TOOL, ERROR] = ['assistant', 'tool', 'error'] + const NO_CONTENT_ERROR = 'No content in messages object.' + + const query = useQueryParams(); + const [dialogVisible, setDialogVisible] = useState(true); + const [queryParams, setQueryParams] = useState(""); + + useEffect(() => { + const params = []; + query.forEach((value, key) => { + params.push(`${key}: ${value}`); + }); + setQueryParams(params.join("\n")); + + console.log("Query Params: ", params); + console.log("Dialog Visible: ", dialogVisible); + }, [query]); + + const hideDialog = () => { + setDialogVisible(false); + }; + + useEffect(() => { + if ( + appStateContext?.state.isCosmosDBAvailable?.status !== CosmosDBStatus.Working && + appStateContext?.state.isCosmosDBAvailable?.status !== CosmosDBStatus.NotConfigured && + appStateContext?.state.chatHistoryLoadingState === ChatHistoryLoadingState.Fail && + hideErrorDialog + ) { + let subtitle = `${appStateContext.state.isCosmosDBAvailable.status}. Please contact the site administrator.` + setErrorMsg({ + title: 'Chat history is not enabled', + subtitle: subtitle + }) + toggleErrorDialog() + } + }, [appStateContext?.state.isCosmosDBAvailable]) + + const handleErrorDialogClose = () => { + toggleErrorDialog() + setTimeout(() => { + setErrorMsg(null) + }, 500) + } + + useEffect(() => { + if (!appStateContext?.state.isLoading) { + setLogo(ui?.chat_logo || ui?.logo || Contoso) + } + }, [appStateContext?.state.isLoading]) + + useEffect(() => { + setIsLoading(appStateContext?.state.chatHistoryLoadingState === ChatHistoryLoadingState.Loading) + }, [appStateContext?.state.chatHistoryLoadingState]) + + const getUserInfoList = async () => { + if (!AUTH_ENABLED) { + setShowAuthMessage(false) + return + } + const userInfoList = await getUserInfo() + if (userInfoList.length === 0 && window.location.hostname !== '127.0.0.1') { + setShowAuthMessage(true) + } else { + setShowAuthMessage(false) + } + } + + let assistantMessage = {} as ChatMessage + let toolMessage = {} as ChatMessage + let assistantContent = '' + + const processResultMessage = (resultMessage: ChatMessage, userMessage: ChatMessage, conversationId?: string) => { + if (resultMessage.content.includes('all_exec_results')) { + const parsedExecResults = JSON.parse(resultMessage.content) as AzureSqlServerExecResults + setExecResults(parsedExecResults.all_exec_results) + } + + if (resultMessage.role === ASSISTANT) { + assistantContent += resultMessage.content + assistantMessage = resultMessage + assistantMessage.content = assistantContent + + if (resultMessage.context) { + toolMessage = { + id: uuid(), + role: TOOL, + content: resultMessage.context, + date: new Date().toISOString() + } + } + } + + if (resultMessage.role === TOOL) toolMessage = resultMessage + + if (!conversationId) { + isEmpty(toolMessage) + ? setMessages([...messages, userMessage, assistantMessage]) + : setMessages([...messages, userMessage, toolMessage, assistantMessage]) + } else { + isEmpty(toolMessage) + ? setMessages([...messages, assistantMessage]) + : setMessages([...messages, toolMessage, assistantMessage]) + } + } + + const makeApiRequestWithoutCosmosDB = async (question: string, conversationId?: string) => { + setIsLoading(true) + setShowLoadingMessage(true) + const abortController = new AbortController() + abortFuncs.current.unshift(abortController) + + const userMessage: ChatMessage = { + id: uuid(), + role: 'user', + content: question, + date: new Date().toISOString() + } + + let conversation: Conversation | null | undefined + if (!conversationId) { + conversation = { + id: conversationId ?? uuid(), + title: question, + messages: [userMessage], + date: new Date().toISOString() + } + } else { + conversation = appStateContext?.state?.currentChat + if (!conversation) { + console.error('Conversation not found.') + setIsLoading(false) + setShowLoadingMessage(false) + abortFuncs.current = abortFuncs.current.filter(a => a !== abortController) + return + } else { + conversation.messages.push(userMessage) + } + } + + appStateContext?.dispatch({ type: 'UPDATE_CURRENT_CHAT', payload: conversation }) + setMessages(conversation.messages) + + const request: ConversationRequest = { + messages: [...conversation.messages.filter(answer => answer.role !== ERROR)] + } + + let result = {} as ChatResponse + try { + const response = await conversationApi(request, abortController.signal) + if (response?.body) { + const reader = response.body.getReader() + + let runningText = '' + while (true) { + setProcessMessages(messageStatus.Processing) + const { done, value } = await reader.read() + if (done) break + + var text = new TextDecoder('utf-8').decode(value) + const objects = text.split('\n') + objects.forEach(obj => { + try { + if (obj !== '' && obj !== '{}') { + runningText += obj + result = JSON.parse(runningText) + if (result.choices?.length > 0) { + result.choices[0].messages.forEach(msg => { + msg.id = result.id + msg.date = new Date().toISOString() + }) + if (result.choices[0].messages?.some(m => m.role === ASSISTANT)) { + setShowLoadingMessage(false) + } + result.choices[0].messages.forEach(resultObj => { + processResultMessage(resultObj, userMessage, conversationId) + }) + } else if (result.error) { + throw Error(result.error) + } + runningText = '' + } + } catch (e) { + if (!(e instanceof SyntaxError)) { + console.error(e) + throw e + } else { + console.log('Incomplete message. Continuing...') + } + } + }) + } + conversation.messages.push(toolMessage, assistantMessage) + appStateContext?.dispatch({ type: 'UPDATE_CURRENT_CHAT', payload: conversation }) + setMessages([...messages, toolMessage, assistantMessage]) + } + } catch (e) { + if (!abortController.signal.aborted) { + let errorMessage = + 'An error occurred. Please try again. If the problem persists, please contact the site administrator.' + if (result.error?.message) { + errorMessage = result.error.message + } else if (typeof result.error === 'string') { + errorMessage = result.error + } + + errorMessage = parseErrorMessage(errorMessage) + + let errorChatMsg: ChatMessage = { + id: uuid(), + role: ERROR, + content: errorMessage, + date: new Date().toISOString() + } + conversation.messages.push(errorChatMsg) + appStateContext?.dispatch({ type: 'UPDATE_CURRENT_CHAT', payload: conversation }) + setMessages([...messages, errorChatMsg]) + } else { + setMessages([...messages, userMessage]) + } + } finally { + setIsLoading(false) + setShowLoadingMessage(false) + abortFuncs.current = abortFuncs.current.filter(a => a !== abortController) + setProcessMessages(messageStatus.Done) + } + + return abortController.abort() + } + + const makeApiRequestWithCosmosDB = async (question: string, conversationId?: string) => { + setIsLoading(true) + setShowLoadingMessage(true) + const abortController = new AbortController() + abortFuncs.current.unshift(abortController) + + const userMessage: ChatMessage = { + id: uuid(), + role: 'user', + content: question, + date: new Date().toISOString() + } + + //api call params set here (generate) + let request: ConversationRequest + let conversation + if (conversationId) { + conversation = appStateContext?.state?.chatHistory?.find(conv => conv.id === conversationId) + if (!conversation) { + console.error('Conversation not found.') + setIsLoading(false) + setShowLoadingMessage(false) + abortFuncs.current = abortFuncs.current.filter(a => a !== abortController) + return + } else { + conversation.messages.push(userMessage) + request = { + messages: [...conversation.messages.filter(answer => answer.role !== ERROR)] + } + } + } else { + request = { + messages: [userMessage].filter(answer => answer.role !== ERROR) + } + setMessages(request.messages) + } + let result = {} as ChatResponse + var errorResponseMessage = 'Please try again. If the problem persists, please contact the site administrator.' + try { + const response = conversationId + ? await historyGenerate(request, abortController.signal, conversationId) + : await historyGenerate(request, abortController.signal) + if (!response?.ok) { + const responseJson = await response.json() + errorResponseMessage = + responseJson.error === undefined ? errorResponseMessage : parseErrorMessage(responseJson.error) + let errorChatMsg: ChatMessage = { + id: uuid(), + role: ERROR, + content: `There was an error generating a response. Chat history can't be saved at this time. ${errorResponseMessage}`, + date: new Date().toISOString() + } + let resultConversation + if (conversationId) { + resultConversation = appStateContext?.state?.chatHistory?.find(conv => conv.id === conversationId) + if (!resultConversation) { + console.error('Conversation not found.') + setIsLoading(false) + setShowLoadingMessage(false) + abortFuncs.current = abortFuncs.current.filter(a => a !== abortController) + return + } + resultConversation.messages.push(errorChatMsg) + } else { + setMessages([...messages, userMessage, errorChatMsg]) + setIsLoading(false) + setShowLoadingMessage(false) + abortFuncs.current = abortFuncs.current.filter(a => a !== abortController) + return + } + appStateContext?.dispatch({ type: 'UPDATE_CURRENT_CHAT', payload: resultConversation }) + setMessages([...resultConversation.messages]) + return + } + if (response?.body) { + const reader = response.body.getReader() + + let runningText = '' + while (true) { + setProcessMessages(messageStatus.Processing) + const { done, value } = await reader.read() + if (done) break + + var text = new TextDecoder('utf-8').decode(value) + const objects = text.split('\n') + objects.forEach(obj => { + try { + if (obj !== '' && obj !== '{}') { + runningText += obj + result = JSON.parse(runningText) + if (!result.choices?.[0]?.messages?.[0].content) { + errorResponseMessage = NO_CONTENT_ERROR + throw Error() + } + if (result.choices?.length > 0) { + result.choices[0].messages.forEach(msg => { + msg.id = result.id + msg.date = new Date().toISOString() + }) + if (result.choices[0].messages?.some(m => m.role === ASSISTANT)) { + setShowLoadingMessage(false) + } + result.choices[0].messages.forEach(resultObj => { + processResultMessage(resultObj, userMessage, conversationId) + }) + } + runningText = '' + } else if (result.error) { + throw Error(result.error) + } + } catch (e) { + if (!(e instanceof SyntaxError)) { + console.error(e) + throw e + } else { + console.log('Incomplete message. Continuing...') + } + } + }) + } + + let resultConversation + if (conversationId) { + resultConversation = appStateContext?.state?.chatHistory?.find(conv => conv.id === conversationId) + if (!resultConversation) { + console.error('Conversation not found.') + setIsLoading(false) + setShowLoadingMessage(false) + abortFuncs.current = abortFuncs.current.filter(a => a !== abortController) + return + } + isEmpty(toolMessage) + ? resultConversation.messages.push(assistantMessage) + : resultConversation.messages.push(toolMessage, assistantMessage) + } else { + resultConversation = { + id: result.history_metadata.conversation_id, + title: result.history_metadata.title, + messages: [userMessage], + date: result.history_metadata.date + } + isEmpty(toolMessage) + ? resultConversation.messages.push(assistantMessage) + : resultConversation.messages.push(toolMessage, assistantMessage) + } + if (!resultConversation) { + setIsLoading(false) + setShowLoadingMessage(false) + abortFuncs.current = abortFuncs.current.filter(a => a !== abortController) + return + } + appStateContext?.dispatch({ type: 'UPDATE_CURRENT_CHAT', payload: resultConversation }) + isEmpty(toolMessage) + ? setMessages([...messages, assistantMessage]) + : setMessages([...messages, toolMessage, assistantMessage]) + } + } catch (e) { + if (!abortController.signal.aborted) { + let errorMessage = `An error occurred. ${errorResponseMessage}` + if (result.error?.message) { + errorMessage = result.error.message + } else if (typeof result.error === 'string') { + errorMessage = result.error + } + + errorMessage = parseErrorMessage(errorMessage) + + let errorChatMsg: ChatMessage = { + id: uuid(), + role: ERROR, + content: errorMessage, + date: new Date().toISOString() + } + let resultConversation + if (conversationId) { + resultConversation = appStateContext?.state?.chatHistory?.find(conv => conv.id === conversationId) + if (!resultConversation) { + console.error('Conversation not found.') + setIsLoading(false) + setShowLoadingMessage(false) + abortFuncs.current = abortFuncs.current.filter(a => a !== abortController) + return + } + resultConversation.messages.push(errorChatMsg) + } else { + if (!result.history_metadata) { + console.error('Error retrieving data.', result) + let errorChatMsg: ChatMessage = { + id: uuid(), + role: ERROR, + content: errorMessage, + date: new Date().toISOString() + } + setMessages([...messages, userMessage, errorChatMsg]) + setIsLoading(false) + setShowLoadingMessage(false) + abortFuncs.current = abortFuncs.current.filter(a => a !== abortController) + return + } + resultConversation = { + id: result.history_metadata.conversation_id, + title: result.history_metadata.title, + messages: [userMessage], + date: result.history_metadata.date + } + resultConversation.messages.push(errorChatMsg) + } + if (!resultConversation) { + setIsLoading(false) + setShowLoadingMessage(false) + abortFuncs.current = abortFuncs.current.filter(a => a !== abortController) + return + } + appStateContext?.dispatch({ type: 'UPDATE_CURRENT_CHAT', payload: resultConversation }) + setMessages([...messages, errorChatMsg]) + } else { + setMessages([...messages, userMessage]) + } + } finally { + setIsLoading(false) + setShowLoadingMessage(false) + abortFuncs.current = abortFuncs.current.filter(a => a !== abortController) + setProcessMessages(messageStatus.Done) + } + return abortController.abort() + } + + const clearChat = async () => { + setClearingChat(true) + if (appStateContext?.state.currentChat?.id && appStateContext?.state.isCosmosDBAvailable.cosmosDB) { + let response = await historyClear(appStateContext?.state.currentChat.id) + if (!response.ok) { + setErrorMsg({ + title: 'Error clearing current chat', + subtitle: 'Please try again. If the problem persists, please contact the site administrator.' + }) + toggleErrorDialog() + } else { + appStateContext?.dispatch({ + type: 'DELETE_CURRENT_CHAT_MESSAGES', + payload: appStateContext?.state.currentChat.id + }) + appStateContext?.dispatch({ type: 'UPDATE_CHAT_HISTORY', payload: appStateContext?.state.currentChat }) + setActiveCitation(undefined) + setIsCitationPanelOpen(false) + setIsIntentsPanelOpen(false) + setMessages([]) + } + } + setClearingChat(false) + } + + const tryGetRaiPrettyError = (errorMessage: string) => { + try { + // Using a regex to extract the JSON part that contains "innererror" + const match = errorMessage.match(/'innererror': ({.*})\}\}/) + if (match) { + // Replacing single quotes with double quotes and converting Python-like booleans to JSON booleans + const fixedJson = match[1] + .replace(/'/g, '"') + .replace(/\bTrue\b/g, 'true') + .replace(/\bFalse\b/g, 'false') + const innerErrorJson = JSON.parse(fixedJson) + let reason = '' + // Check if jailbreak content filter is the reason of the error + const jailbreak = innerErrorJson.content_filter_result.jailbreak + if (jailbreak.filtered === true) { + reason = 'Jailbreak' + } + + // Returning the prettified error message + if (reason !== '') { + return ( + 'The prompt was filtered due to triggering Azure OpenAI’s content filtering system.\n' + + 'Reason: This prompt contains content flagged as ' + + reason + + '\n\n' + + 'Please modify your prompt and retry. Learn more: https://go.microsoft.com/fwlink/?linkid=2198766' + ) + } + } + } catch (e) { + console.error('Failed to parse the error:', e) + } + return errorMessage + } + + const parseErrorMessage = (errorMessage: string) => { + let errorCodeMessage = errorMessage.substring(0, errorMessage.indexOf('-') + 1) + const innerErrorCue = "{\\'error\\': {\\'message\\': " + if (errorMessage.includes(innerErrorCue)) { + try { + let innerErrorString = errorMessage.substring(errorMessage.indexOf(innerErrorCue)) + if (innerErrorString.endsWith("'}}")) { + innerErrorString = innerErrorString.substring(0, innerErrorString.length - 3) + } + innerErrorString = innerErrorString.replaceAll("\\'", "'") + let newErrorMessage = errorCodeMessage + ' ' + innerErrorString + errorMessage = newErrorMessage + } catch (e) { + console.error('Error parsing inner error message: ', e) + } + } + + return tryGetRaiPrettyError(errorMessage) + } + + const newChat = () => { + setProcessMessages(messageStatus.Processing) + setMessages([]) + setIsCitationPanelOpen(false) + setIsIntentsPanelOpen(false) + setActiveCitation(undefined) + appStateContext?.dispatch({ type: 'UPDATE_CURRENT_CHAT', payload: null }) + setProcessMessages(messageStatus.Done) + } + + const stopGenerating = () => { + abortFuncs.current.forEach(a => a.abort()) + setShowLoadingMessage(false) + setIsLoading(false) + } + + useEffect(() => { + if (appStateContext?.state.currentChat) { + setMessages(appStateContext.state.currentChat.messages) + } else { + setMessages([]) + } + }, [appStateContext?.state.currentChat]) + + useLayoutEffect(() => { + const saveToDB = async (messages: ChatMessage[], id: string) => { + const response = await historyUpdate(messages, id) + return response + } + + if (appStateContext && appStateContext.state.currentChat && processMessages === messageStatus.Done) { + if (appStateContext.state.isCosmosDBAvailable.cosmosDB) { + if (!appStateContext?.state.currentChat?.messages) { + console.error('Failure fetching current chat state.') + return + } + const noContentError = appStateContext.state.currentChat.messages.find(m => m.role === ERROR) + + if (!noContentError?.content.includes(NO_CONTENT_ERROR)) { + saveToDB(appStateContext.state.currentChat.messages, appStateContext.state.currentChat.id) + .then(res => { + if (!res.ok) { + let errorMessage = + "An error occurred. Answers can't be saved at this time. If the problem persists, please contact the site administrator." + let errorChatMsg: ChatMessage = { + id: uuid(), + role: ERROR, + content: errorMessage, + date: new Date().toISOString() + } + if (!appStateContext?.state.currentChat?.messages) { + let err: Error = { + ...new Error(), + message: 'Failure fetching current chat state.' + } + throw err + } + setMessages([...appStateContext?.state.currentChat?.messages, errorChatMsg]) + } + return res as Response + }) + .catch(err => { + console.error('Error: ', err) + let errRes: Response = { + ...new Response(), + ok: false, + status: 500 + } + return errRes + }) + } + } else { + } + appStateContext?.dispatch({ type: 'UPDATE_CHAT_HISTORY', payload: appStateContext.state.currentChat }) + setMessages(appStateContext.state.currentChat.messages) + setProcessMessages(messageStatus.NotRunning) + } + }, [processMessages]) + + useEffect(() => { + if (AUTH_ENABLED !== undefined) getUserInfoList() + }, [AUTH_ENABLED]) + + useLayoutEffect(() => { + chatMessageStreamEnd.current?.scrollIntoView({ behavior: 'smooth' }) + }, [showLoadingMessage, processMessages]) + + const onShowCitation = (citation: Citation) => { + setActiveCitation(citation) + setIsCitationPanelOpen(true) + } + + const onShowExecResult = () => { + setIsIntentsPanelOpen(true) + } + + const onViewSource = (citation: Citation) => { + if (citation.url && !citation.url.includes('blob.core')) { + window.open(citation.url, '_blank') + } + } + + const parseCitationFromMessage = (message: ChatMessage) => { + if (message?.role && message?.role === 'tool') { + try { + const toolMessage = JSON.parse(message.content) as ToolMessageContent + return toolMessage.citations + } catch { + return [] + } + } + return [] + } + + const parsePlotFromMessage = (message: ChatMessage) => { + if (message?.role && message?.role === "tool") { + try { + const execResults = JSON.parse(message.content) as AzureSqlServerExecResults; + const codeExecResult = execResults.all_exec_results.at(-1)?.code_exec_result; + if (codeExecResult === undefined) { + return null; + } + return codeExecResult; + } + catch { + return null; + } + // const execResults = JSON.parse(message.content) as AzureSqlServerExecResults; + // return execResults.all_exec_results.at(-1)?.code_exec_result; + } + return null; + } + + const disabledButton = () => { + return ( + isLoading || + (messages && messages.length === 0) || + clearingChat || + appStateContext?.state.chatHistoryLoadingState === ChatHistoryLoadingState.Loading + ) + } + + return ( +
+ {showAuthMessage ? ( + + +

Authentication Not Configured

+

+ This app does not have authentication configured. Please add an identity provider by finding your app in the{' '} + + Azure Portal + + and following{' '} + + these instructions + + . +

+

+ Authentication configuration takes a few minutes to apply. +

+

+ If you deployed in the last 10 minutes, please wait and reload the page after 10 minutes. +

+
+ ) : ( + +
+ {!messages || messages.length < 1 ? ( + + +

{ui?.chat_title}

+

{ui?.chat_description}

+
+ ) : ( +
+ {messages.map((answer, index) => ( + <> + {answer.role === 'user' ? ( +
+
{answer.content}
+
+ ) : answer.role === 'assistant' ? ( +
+ onShowCitation(c)} + onExectResultClicked={() => onShowExecResult()} + /> +
+ ) : answer.role === ERROR ? ( +
+ + + Error + + {answer.content} +
+ ) : null} + + ))} + {showLoadingMessage && ( + <> +
+ null} + onExectResultClicked={() => null} + /> +
+ + )} +
+
+ )} + + + {isLoading && messages.length > 0 && ( + (e.key === 'Enter' || e.key === ' ' ? stopGenerating() : null)}> + + )} + + {appStateContext?.state.isCosmosDBAvailable?.status !== CosmosDBStatus.NotConfigured && ( + + )} + + + + { + appStateContext?.state.isCosmosDBAvailable?.cosmosDB + ? makeApiRequestWithCosmosDB(question, id) + : makeApiRequestWithoutCosmosDB(question, id) + }} + conversationId={ + appStateContext?.state.currentChat?.id ? appStateContext?.state.currentChat?.id : undefined + } + /> + +
+ {/* Citation Panel */} + {messages && messages.length > 0 && isCitationPanelOpen && activeCitation && ( + + + + Citations + + setIsCitationPanelOpen(false)} + /> + +
onViewSource(activeCitation)}> + {activeCitation.title} +
+
+ +
+
+ )} + {messages && messages.length > 0 && isIntentsPanelOpen && ( + + + + Intents + + setIsIntentsPanelOpen(false)} + /> + + + {execResults.map((execResult) => { + return ( + + <>Intent:

{execResult.intent}

+ {execResult.search_query && <>Search Query: + + {execResult.search_query} + } + {execResult.search_result && <>Search Result:

{execResult.search_result}

} + {execResult.code_generated && <>Code Generated: + + {execResult.code_generated} + + } +
+ ) + })} +
+
+ )} + {appStateContext?.state.isChatHistoryOpen && + appStateContext?.state.isCosmosDBAvailable?.status !== CosmosDBStatus.NotConfigured && } + + )} +
) - } +} export default Chat From 80f5cff78ad86cdfee1f66d60c34908ee7e25b24 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 16:34:26 -0400 Subject: [PATCH 30/63] Try again --- .github/workflows/node.js.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 94c9fc56af..a2bd3ab5c5 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -30,8 +30,8 @@ jobs: cache: 'npm' cache-dependency-path: '**/package-lock.json' - run: npm ci - - run: npm install react-query - - run: npm install mapbox-gl eslint-plugin-import@^2.25.2 + - run: npm install react-query mapbox-gl eslint-plugin-import@^2.25.2 - run: npm audit fix + - run: npm audit fix --force # Force fix remaining vulnerabilities if possible - run: NODE_OPTIONS=--max_old_space_size=8192 npm run build --if-present - run: npm run test --if-present From 199706e468a9b24124d1bed20c6f3bf8c3871ad4 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 16:39:56 -0400 Subject: [PATCH 31/63] Try again --- frontend/src/pages/chat/Chat.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index df2d10a35e..c84dfa2725 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -94,7 +94,7 @@ const Chat = () => { const [queryParams, setQueryParams] = useState(""); useEffect(() => { - const params = []; + const params = string[]; query.forEach((value, key) => { params.push(`${key}: ${value}`); }); From a81fbb2d0693e3abb6eedaae2a92197c23c91622 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 16:42:25 -0400 Subject: [PATCH 32/63] Try --- frontend/src/pages/chat/Chat.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index c84dfa2725..6767c4792a 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -94,7 +94,7 @@ const Chat = () => { const [queryParams, setQueryParams] = useState(""); useEffect(() => { - const params = string[]; + const params = Any[]; query.forEach((value, key) => { params.push(`${key}: ${value}`); }); From 5dd446fa42085ade3275d8362f6860956eb83fb0 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 16:43:58 -0400 Subject: [PATCH 33/63] Try again --- frontend/src/pages/chat/Chat.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index 6767c4792a..086ad0b1df 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -94,7 +94,7 @@ const Chat = () => { const [queryParams, setQueryParams] = useState(""); useEffect(() => { - const params = Any[]; + const params: string[] = []; query.forEach((value, key) => { params.push(`${key}: ${value}`); }); From 72675141931f9495c45a69f61e9fc85a8bb8f01e Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 16:45:39 -0400 Subject: [PATCH 34/63] Try --- frontend/src/pages/chat/Chat.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index 086ad0b1df..c1a59764a7 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -1053,9 +1053,6 @@ const Chat = () => { subText: queryParams }} > - - -
) From 71185e5ddd9e6050af66dee393e36556cbf7686a Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 17:01:49 -0400 Subject: [PATCH 35/63] Try again --- .github/workflows/node.js.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index a2bd3ab5c5..edfd047b18 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -30,7 +30,7 @@ jobs: cache: 'npm' cache-dependency-path: '**/package-lock.json' - run: npm ci - - run: npm install react-query mapbox-gl eslint-plugin-import@^2.25.2 + - run: npm install react-query @types/react-query mapbox-gl eslint-plugin-import@^2.25.2 - run: npm audit fix - run: npm audit fix --force # Force fix remaining vulnerabilities if possible - run: NODE_OPTIONS=--max_old_space_size=8192 npm run build --if-present From f8a19e20bec4b7f4981b25b72d20be736699105b Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 17:08:06 -0400 Subject: [PATCH 36/63] Try again --- frontend/package-lock.json | 6 ++++-- frontend/src/pages/chat/Chat.tsx | 2 +- frontend/tsconfig.json | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 60a3b70dd2..824e263cf2 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -24,7 +24,8 @@ "react-uuid": "^2.0.0", "rehype-raw": "^6.1.1", "remark-gfm": "^3.0.1", - "remark-supersub": "^1.0.0" + "remark-supersub": "^1.0.0", + "react-query": "^3.0.0" }, "devDependencies": { "@eslint/eslintrc": "^3.0.2", @@ -61,7 +62,8 @@ "ts-jest": "^29.1.2", "ts-node": "^10.9.2", "typescript": "^4.9.5", - "vite": "^4.1.5" + "vite": "^4.1.5", + "@types/react-query": "^3.0.0" } }, "node_modules/@aashutoshrathi/word-wrap": { diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index c1a59764a7..6427c9e8f0 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -2,7 +2,7 @@ import { useRef, useState, useEffect, useContext, useLayoutEffect } from 'react' import { CommandBarButton, IconButton, Dialog, DialogType, Stack } from '@fluentui/react' import { SquareRegular, ShieldLockRegular, ErrorCircleRegular } from '@fluentui/react-icons' import { useLocation } from 'react-router-dom' -import { useQuery } from 'react-query' +import { QueryClient, QueryClientProvider } from 'react-query' import ReactMarkdown from 'react-markdown' import remarkGfm from 'remark-gfm' diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index 4cddbe62bb..46ab1f1f10 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -15,7 +15,7 @@ "isolatedModules": true, "noEmit": true, "jsx": "react-jsx", - "types": ["vite/client", "jest", "mocha"], + "types": ["vite/client", "jest", "mocha", "react-query"], "noUnusedLocals": false }, "include": ["src"], From 84b5a542dd23d7d0598bc11014e31c8d8d139009 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 17:11:25 -0400 Subject: [PATCH 37/63] Try fix --- frontend/package-lock.json | 6 ++---- frontend/package.json | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 824e263cf2..60a3b70dd2 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -24,8 +24,7 @@ "react-uuid": "^2.0.0", "rehype-raw": "^6.1.1", "remark-gfm": "^3.0.1", - "remark-supersub": "^1.0.0", - "react-query": "^3.0.0" + "remark-supersub": "^1.0.0" }, "devDependencies": { "@eslint/eslintrc": "^3.0.2", @@ -62,8 +61,7 @@ "ts-jest": "^29.1.2", "ts-node": "^10.9.2", "typescript": "^4.9.5", - "vite": "^4.1.5", - "@types/react-query": "^3.0.0" + "vite": "^4.1.5" } }, "node_modules/@aashutoshrathi/word-wrap": { diff --git a/frontend/package.json b/frontend/package.json index adf63e3bc9..f299cc243f 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -26,6 +26,7 @@ "react-dom": "^18.2.0", "react-markdown": "^7.0.1", "react-plotly.js": "^2.6.0", + "react-query": "^3.0.0", "react-router-dom": "^6.8.1", "react-syntax-highlighter": "^15.5.0", "react-uuid": "^2.0.0", @@ -45,6 +46,7 @@ "@types/react": "^18.0.27", "@types/react-dom": "^18.0.10", "@types/react-plotly.js": "^2.6.3", + "@types/react-query": "^3.0.0", "@types/react-syntax-highlighter": "^15.5.11", "@typescript-eslint/eslint-plugin": "^6.21.0", "@typescript-eslint/parser": "^6.21.0", From 181f1c5bdf38ce521255d76c52955d83225ef149 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 17:13:29 -0400 Subject: [PATCH 38/63] Fix --- frontend/package-lock.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 60a3b70dd2..ccc61b55e0 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -19,6 +19,7 @@ "react-dom": "^18.2.0", "react-markdown": "^7.0.1", "react-plotly.js": "^2.6.0", + "react-query": "^3.0.0", "react-router-dom": "^6.8.1", "react-syntax-highlighter": "^15.5.0", "react-uuid": "^2.0.0", @@ -38,6 +39,7 @@ "@types/react": "^18.0.27", "@types/react-dom": "^18.0.10", "@types/react-plotly.js": "^2.6.3", + "@types/react-query": "^3.0.0", "@types/react-syntax-highlighter": "^15.5.11", "@typescript-eslint/eslint-plugin": "^6.21.0", "@typescript-eslint/parser": "^6.21.0", From acbf8d62de948fc8e98541e6ef26a1ef167da1be Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 17:16:37 -0400 Subject: [PATCH 39/63] Try again --- .github/workflows/node.js.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index edfd047b18..3688182082 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -30,7 +30,6 @@ jobs: cache: 'npm' cache-dependency-path: '**/package-lock.json' - run: npm ci - - run: npm install react-query @types/react-query mapbox-gl eslint-plugin-import@^2.25.2 - run: npm audit fix - run: npm audit fix --force # Force fix remaining vulnerabilities if possible - run: NODE_OPTIONS=--max_old_space_size=8192 npm run build --if-present From ff82849395cbb50d2896e30ab0a0b6a35976ea91 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 17:18:26 -0400 Subject: [PATCH 40/63] Fix --- frontend/package-lock.json | 1 - frontend/package.json | 1 - 2 files changed, 2 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index ccc61b55e0..ba1bb3bf39 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -39,7 +39,6 @@ "@types/react": "^18.0.27", "@types/react-dom": "^18.0.10", "@types/react-plotly.js": "^2.6.3", - "@types/react-query": "^3.0.0", "@types/react-syntax-highlighter": "^15.5.11", "@typescript-eslint/eslint-plugin": "^6.21.0", "@typescript-eslint/parser": "^6.21.0", diff --git a/frontend/package.json b/frontend/package.json index f299cc243f..663a858cee 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -46,7 +46,6 @@ "@types/react": "^18.0.27", "@types/react-dom": "^18.0.10", "@types/react-plotly.js": "^2.6.3", - "@types/react-query": "^3.0.0", "@types/react-syntax-highlighter": "^15.5.11", "@typescript-eslint/eslint-plugin": "^6.21.0", "@typescript-eslint/parser": "^6.21.0", From 710afeabda71eef4e617f85bbd052f3c1d2d8a65 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 17:19:01 -0400 Subject: [PATCH 41/63] Fix --- .github/workflows/node.js.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 3688182082..a6be2d2a76 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -30,6 +30,7 @@ jobs: cache: 'npm' cache-dependency-path: '**/package-lock.json' - run: npm ci + - run: npm install mapbox-gl eslint-plugin-import@^2.25.2 - run: npm audit fix - run: npm audit fix --force # Force fix remaining vulnerabilities if possible - run: NODE_OPTIONS=--max_old_space_size=8192 npm run build --if-present From 293f0c924fcc70797cd730fe16529dd8675decd5 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 17:25:23 -0400 Subject: [PATCH 42/63] Argh --- .github/workflows/node.js.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index a6be2d2a76..ebec28891d 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -30,7 +30,7 @@ jobs: cache: 'npm' cache-dependency-path: '**/package-lock.json' - run: npm ci - - run: npm install mapbox-gl eslint-plugin-import@^2.25.2 + - run: npm install react-query mapbox-gl eslint-plugin-import@^2.25.2 - run: npm audit fix - run: npm audit fix --force # Force fix remaining vulnerabilities if possible - run: NODE_OPTIONS=--max_old_space_size=8192 npm run build --if-present From 45d9317001223f359d8b1849a75749c98d41aee9 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 17:29:16 -0400 Subject: [PATCH 43/63] Give me one more try, baby just one. more. try... --- .github/workflows/node.js.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index ebec28891d..758b3c1607 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -29,8 +29,18 @@ jobs: node-version: ${{ matrix.node-version }} cache: 'npm' cache-dependency-path: '**/package-lock.json' + + + - name: Remove node_modules and package-lock.json + run: | + rm -rf node_modules + rm -f package-lock.json + + - name: Install dependencies and generate package-lock.json + run: npm install + - run: npm ci - - run: npm install react-query mapbox-gl eslint-plugin-import@^2.25.2 + - run: npm audit fix - run: npm audit fix --force # Force fix remaining vulnerabilities if possible - run: NODE_OPTIONS=--max_old_space_size=8192 npm run build --if-present From 3e37659d5e48495800e147acd45286585ae6a326 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 17:33:16 -0400 Subject: [PATCH 44/63] Again --- .github/workflows/node.js.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 758b3c1607..6ea6a9ca84 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -40,7 +40,7 @@ jobs: run: npm install - run: npm ci - + - run: npm install react-query mapbox-gl eslint-plugin-import@^2.25.2 - run: npm audit fix - run: npm audit fix --force # Force fix remaining vulnerabilities if possible - run: NODE_OPTIONS=--max_old_space_size=8192 npm run build --if-present From e0d8e6df3877e90ccf20311ef925b75d82a33195 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 17:38:17 -0400 Subject: [PATCH 45/63] Try this --- WebApp.Dockerfile | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/WebApp.Dockerfile b/WebApp.Dockerfile index d902410534..63aa469dca 100644 --- a/WebApp.Dockerfile +++ b/WebApp.Dockerfile @@ -4,10 +4,21 @@ RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app WORKDIR /home/node/app COPY ./frontend/package*.json ./ USER node -RUN npm ci + +# Remove node_modules and package-lock.json +RUN rm -rf node_modules && rm -f package-lock.json + +# Install dependencies and generate package-lock.json +RUN npm install + COPY --chown=node:node ./frontend/ ./frontend COPY --chown=node:node ./static/ ./static WORKDIR /home/node/app/frontend + +# Verify dependencies are installed correctly +RUN npm ci + +# Build the project RUN NODE_OPTIONS=--max_old_space_size=8192 npm run build FROM python:3.11-alpine From 9fb892bfceab28f113ae2fc32f8dcfafb4b238bf Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 17:43:07 -0400 Subject: [PATCH 46/63] Try --- .github/workflows/node.js.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 6ea6a9ca84..6b2b8e344c 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -40,7 +40,6 @@ jobs: run: npm install - run: npm ci - - run: npm install react-query mapbox-gl eslint-plugin-import@^2.25.2 - run: npm audit fix - run: npm audit fix --force # Force fix remaining vulnerabilities if possible - run: NODE_OPTIONS=--max_old_space_size=8192 npm run build --if-present From 431a2ff2202833eba6354bd033ddd0896204ba6b Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 17:49:47 -0400 Subject: [PATCH 47/63] Remove build of Python app that isn't needed for our change... --- .github/workflows/python-app.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index a0d1197207..5895601d5d 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -5,9 +5,9 @@ name: Python application on: push: - branches: [ "main", "AddQueryStringForInitialPrompting" ] + branches: [ "main" ] pull_request: - branches: [ "main", "AddQueryStringForInitialPrompting" ] + branches: [ "main" ] permissions: contents: read From ceef987d1e1025e8a74cbdde58f4bd98bcb4a9b7 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 17:55:10 -0400 Subject: [PATCH 48/63] Remove branch from Python app build and deploy --- .github/workflows/sample-app-github-cd.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/sample-app-github-cd.yml b/.github/workflows/sample-app-github-cd.yml index aed03b6d67..d4f1fee74a 100644 --- a/.github/workflows/sample-app-github-cd.yml +++ b/.github/workflows/sample-app-github-cd.yml @@ -8,7 +8,6 @@ on: push: branches: - main - - AddQueryStringForInitialPrompting workflow_dispatch: jobs: @@ -60,7 +59,6 @@ jobs: - name: Unzip artifact for deployment run: unzip release.zip - - name: Login to Azure uses: azure/login@v1 From 0f328bc3dfdffb4a769f505e6fb094085232944e Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 17:59:51 -0400 Subject: [PATCH 49/63] Try --- .github/workflows/python-app.yml | 4 ++-- .github/workflows/sample-app-github-cd.yml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 5895601d5d..a0d1197207 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -5,9 +5,9 @@ name: Python application on: push: - branches: [ "main" ] + branches: [ "main", "AddQueryStringForInitialPrompting" ] pull_request: - branches: [ "main" ] + branches: [ "main", "AddQueryStringForInitialPrompting" ] permissions: contents: read diff --git a/.github/workflows/sample-app-github-cd.yml b/.github/workflows/sample-app-github-cd.yml index d4f1fee74a..b85cf3482d 100644 --- a/.github/workflows/sample-app-github-cd.yml +++ b/.github/workflows/sample-app-github-cd.yml @@ -8,6 +8,7 @@ on: push: branches: - main + - AddQueryStringForInitialPrompting workflow_dispatch: jobs: From 56e1cae28fc87179fd8e1b2224b48576cd5a7415 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 18:03:42 -0400 Subject: [PATCH 50/63] Try again --- .github/workflows/node.js.yml | 5 +---- WebApp.Dockerfile | 3 --- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 6b2b8e344c..cd949719bf 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -38,9 +38,6 @@ jobs: - name: Install dependencies and generate package-lock.json run: npm install - - - run: npm ci - - run: npm audit fix - - run: npm audit fix --force # Force fix remaining vulnerabilities if possible + - run: NODE_OPTIONS=--max_old_space_size=8192 npm run build --if-present - run: npm run test --if-present diff --git a/WebApp.Dockerfile b/WebApp.Dockerfile index 63aa469dca..ab1a001871 100644 --- a/WebApp.Dockerfile +++ b/WebApp.Dockerfile @@ -15,9 +15,6 @@ COPY --chown=node:node ./frontend/ ./frontend COPY --chown=node:node ./static/ ./static WORKDIR /home/node/app/frontend -# Verify dependencies are installed correctly -RUN npm ci - # Build the project RUN NODE_OPTIONS=--max_old_space_size=8192 npm run build From 62d53fcadf091e51c8b0409905da723c9b7f2cf3 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 18:14:07 -0400 Subject: [PATCH 51/63] Exclude Python-app --- .github/workflows/python-app.yml | 4 ++-- .github/workflows/sample-app-github-cd.yml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index a0d1197207..5895601d5d 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -5,9 +5,9 @@ name: Python application on: push: - branches: [ "main", "AddQueryStringForInitialPrompting" ] + branches: [ "main" ] pull_request: - branches: [ "main", "AddQueryStringForInitialPrompting" ] + branches: [ "main" ] permissions: contents: read diff --git a/.github/workflows/sample-app-github-cd.yml b/.github/workflows/sample-app-github-cd.yml index b85cf3482d..149f127afc 100644 --- a/.github/workflows/sample-app-github-cd.yml +++ b/.github/workflows/sample-app-github-cd.yml @@ -46,6 +46,7 @@ jobs: deploy: runs-on: ubuntu-latest needs: build + if: github.ref == 'refs/heads/main' # Only run on main branch environment: name: 'Production' url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} From acc1667de485de957a3b613d83d5a7ab8eb586d1 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 18:19:47 -0400 Subject: [PATCH 52/63] Try again --- .github/workflows/python-app.yml | 50 -------------------------------- 1 file changed, 50 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 5895601d5d..45955cea72 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -13,56 +13,6 @@ permissions: contents: read jobs: - test_linux: - runs-on: - - ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Set up Python 3.11 - uses: actions/setup-python@v3 - with: - python-version: "3.11" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements-dev.txt - - name: Test with pytest - env: - AZURE_OPENAI_ENDPOINT: ${{ secrets.AZUREOPENAIENDPOINT }} - AZURE_OPENAI_MODEL: ${{ secrets.AZUREOPENAIMODEL }} - AZURE_OPENAI_KEY: ${{ secrets.AZUREOPENAIKEY }} - AZURE_OPENAI_EMBEDDING_NAME: ${{ secrets.AZUREOPENAIEMBEDDINGNAME }} - AZURE_COSMOSDB_ACCOUNT: ${{ secrets.AZURECOSMOSDBACCOUNT }} - AZURE_COSMOSDB_DATABASE: ${{ secrets.AZURECOSMOSDBDATABASE }} - AZURE_COSMOSDB_CONVERSATIONS_CONTAINER: ${{ secrets.AZURECOSMOSDBCONVERSATIONSCONTAINER }} - AZURE_COSMOSDB_ACCOUNT_KEY: ${{ secrets.AZURECOSMOSDBACCOUNTKEY }} - AZURE_SEARCH_SERVICE: ${{ secrets.AZURESEARCHSERVICE }} - AZURE_SEARCH_INDEX: ${{ secrets.AZURESEARCHINDEX }} - AZURE_SEARCH_KEY: ${{ secrets.AZURESEARCHKEY }} - AZURE_SEARCH_QUERY: ${{ secrets.AZURESEARCHQUERY }} - ELASTICSEARCH_EMBEDDING_MODEL_ID: ${{ secrets.ELASTICSEARCHEMBEDDINGMODELID }} - ELASTICSEARCH_ENCODED_API_KEY: ${{ secrets.ELASTICSEARCHENCODEDAPIKEY }} - ELASTICSEARCH_ENDPOINT: ${{ secrets.ELASTICSEARCHENDPOINT }} - ELASTICSEARCH_INDEX: ${{ secrets.ELASTICSEARCHINDEX }} - ELASTICSEARCH_QUERY: ${{ secrets.ELASTICSEARCHQUERY }} - run: | - export PYTHONPATH=$(pwd) - coverage run -m pytest -v --show-capture=stdout - coverage report -m --include=app.py,backend/*,tests/* - coverage xml - - - name: Code Coverage Report - uses: irongut/CodeCoverageSummary@v1.3.0 - with: - filename: coverage.xml - badge: true - fail_below_min: true - format: markdown - hide_branch_rate: false - hide_complexity: true - indicators: true - output: both - thresholds: '50 80' test_windows: runs-on: From 9ab6034635a4c3cd2b4095fd79e15cc3a434c96c Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 18:34:28 -0400 Subject: [PATCH 53/63] Try again --- .github/workflows/python-app.yml | 141 +++++++++++++++++++++++++------ frontend/src/pages/chat/Chat.tsx | 1 + 2 files changed, 117 insertions(+), 25 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 45955cea72..728b2af31f 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -1,33 +1,124 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python - -name: Python application +name: Build and Test Python App on: push: - branches: [ "main" ] + branches: + - main + - AddQueryStringForInitialPrompting pull_request: - branches: [ "main" ] - -permissions: - contents: read + branches: + - main + - AddQueryStringForInitialPrompting + workflow_dispatch: jobs: - test_windows: - runs-on: - - windows-latest + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Python version + uses: actions/setup-python@v1 + with: + python-version: '3.11' + + - name: Create and start virtual environment + run: | + python -m venv venv + venv\Scripts\Activate + + - name: Install dependencies + run: pip install -r requirements.txt + + - name: Run tests + run: | + export PYTHONPATH=$(pwd) + pytest + + test_linux: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Python 3.11 + uses: actions/setup-python@v3 + with: + python-version: "3.11" + + - name: Create and start virtual environment + run: | + python -m venv venv + source venv/bin/activate + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements-dev.txt + + - name: Test with pytest + env: + AZURE_OPENAI_ENDPOINT: ${{ secrets.AZUREOPENAIENDPOINT }} + AZURE_OPENAI_MODEL: ${{ secrets.AZUREOPENAIMODEL }} + AZURE_OPENAI_KEY: ${{ secrets.AZUREOPENAIKEY }} + AZURE_OPENAI_EMBEDDING_NAME: ${{ secrets.AZUREOPENAIEMBEDDINGNAME }} + AZURE_COSMOSDB_ACCOUNT: ${{ secrets.AZURECOSMOSDBACCOUNT }} + AZURE_COSMOSDB_DATABASE: ${{ secrets.AZURECOSMOSDBDATABASE }} + AZURE_COSMOSDB_CONVERSATIONS_CONTAINER: ${{ secrets.AZURECOSMOSDBCONTAINER }} + AZURE_COSMOSDB_ACCOUNT_KEY: ${{ secrets.AZURECOSMOSDBACCOUNTKEY }} + AZURE_SEARCH_SERVICE: ${{ secrets.AZURESEARCHSERVICE }} + AZURE_SEARCH_INDEX: ${{ secrets.AZURESEARCHINDEX }} + AZURE_SEARCH_KEY: ${{ secrets.AZURESEARCHKEY }} + AZURE_SEARCH_QUERY: ${{ secrets.AZURESEARCHQUERY }} + ELASTICSEARCH_EMBEDDING_MODEL_ID: ${{ secrets.ELASTICSEARCHEMBEDDINGMODELID }} + ELASTICSEARCH_ENCODED_API_KEY: ${{ secrets.ELASTICSEARCHENCODEDAPIKEY }} + ELASTICSEARCH_ENDPOINT: ${{ secrets.ELASTICSEARCHENDPOINT }} + ELASTICSEARCH_INDEX: ${{ secrets.ELASTICSEARCHINDEX }} + ELASTICSEARCH_QUERY: ${{ secrets.ELASTICSEARCHQUERY }} + run: | + export PYTHONPATH=$(pwd) + coverage run -m pytest -v --show-capture=stdout + coverage report -m --include=app.py,backend/*,tests/* + coverage xml + + - name: Code Coverage Report + uses: irongut/CodeCoverageSummary@v1.3.0 + with: + filename: coverage.xml + badge: true + fail_below_min: true + format: markdown + hide_branch_rate: false + hide_complexity: true + indicators: true + output: both + thresholds: '50 80' + + deploy: + runs-on: ubuntu-latest + needs: [test_windows, test_linux] + if: github.ref == 'refs/heads/main' steps: - - uses: actions/checkout@v3 - - name: Set up Python 3.11 - uses: actions/setup-python@v3 - with: - python-version: "3.11" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements-dev.txt - - name: Test with pytest - run: | - $env:PYTHONPATH=$pwd - pytest -v --show-capture=stdout -k "not integration" + - name: Checkout code + uses: actions/checkout@v3 + + - name: Download artifact from build job + uses: actions/download-artifact@v3 + with: + name: python-app + + - name: Unzip artifact for deployment + run: unzip release.zip + + - name: Login to Azure + uses: azure/login@v1 + with: + client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID }} + tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID }} + subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID }} + + - name: 'Deploy to Azure Web App' + uses: azure/webapps-deploy@v2 + id: deploy-to-webapp + with: + app-name: 'sample-app-github-cd' + slot-name: 'Production' diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index 6427c9e8f0..2f2d7e7739 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -97,6 +97,7 @@ const Chat = () => { const params: string[] = []; query.forEach((value, key) => { params.push(`${key}: ${value}`); + console.log(`${key}: ${value}`); }); setQueryParams(params.join("\n")); From eef75beeaf9d72cc410f8418fa75c8bdf0df11da Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 18:35:29 -0400 Subject: [PATCH 54/63] Fix --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 728b2af31f..044a97c19f 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -96,7 +96,7 @@ jobs: deploy: runs-on: ubuntu-latest needs: [test_windows, test_linux] - if: github.ref == 'refs/heads/main' + steps: - name: Checkout code uses: actions/checkout@v3 From 91b15e38521180d2ac9e289c628d9a72ef1d87a5 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 18:41:03 -0400 Subject: [PATCH 55/63] Try again --- .github/workflows/python-app.yml | 187 ++++++++++++------------------- 1 file changed, 73 insertions(+), 114 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 044a97c19f..a0d1197207 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -1,124 +1,83 @@ -name: Build and Test Python App +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python application on: push: - branches: - - main - - AddQueryStringForInitialPrompting + branches: [ "main", "AddQueryStringForInitialPrompting" ] pull_request: - branches: - - main - - AddQueryStringForInitialPrompting - workflow_dispatch: - -jobs: - test_windows: - runs-on: windows-latest - steps: - - uses: actions/checkout@v3 + branches: [ "main", "AddQueryStringForInitialPrompting" ] - - name: Set up Python version - uses: actions/setup-python@v1 - with: - python-version: '3.11' - - - name: Create and start virtual environment - run: | - python -m venv venv - venv\Scripts\Activate - - - name: Install dependencies - run: pip install -r requirements.txt - - - name: Run tests - run: | - export PYTHONPATH=$(pwd) - pytest +permissions: + contents: read +jobs: test_linux: - runs-on: ubuntu-latest + runs-on: + - ubuntu-latest steps: - - uses: actions/checkout@v3 - - - name: Set up Python 3.11 - uses: actions/setup-python@v3 - with: - python-version: "3.11" - - - name: Create and start virtual environment - run: | - python -m venv venv - source venv/bin/activate - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements-dev.txt - - - name: Test with pytest - env: - AZURE_OPENAI_ENDPOINT: ${{ secrets.AZUREOPENAIENDPOINT }} - AZURE_OPENAI_MODEL: ${{ secrets.AZUREOPENAIMODEL }} - AZURE_OPENAI_KEY: ${{ secrets.AZUREOPENAIKEY }} - AZURE_OPENAI_EMBEDDING_NAME: ${{ secrets.AZUREOPENAIEMBEDDINGNAME }} - AZURE_COSMOSDB_ACCOUNT: ${{ secrets.AZURECOSMOSDBACCOUNT }} - AZURE_COSMOSDB_DATABASE: ${{ secrets.AZURECOSMOSDBDATABASE }} - AZURE_COSMOSDB_CONVERSATIONS_CONTAINER: ${{ secrets.AZURECOSMOSDBCONTAINER }} - AZURE_COSMOSDB_ACCOUNT_KEY: ${{ secrets.AZURECOSMOSDBACCOUNTKEY }} - AZURE_SEARCH_SERVICE: ${{ secrets.AZURESEARCHSERVICE }} - AZURE_SEARCH_INDEX: ${{ secrets.AZURESEARCHINDEX }} - AZURE_SEARCH_KEY: ${{ secrets.AZURESEARCHKEY }} - AZURE_SEARCH_QUERY: ${{ secrets.AZURESEARCHQUERY }} - ELASTICSEARCH_EMBEDDING_MODEL_ID: ${{ secrets.ELASTICSEARCHEMBEDDINGMODELID }} - ELASTICSEARCH_ENCODED_API_KEY: ${{ secrets.ELASTICSEARCHENCODEDAPIKEY }} - ELASTICSEARCH_ENDPOINT: ${{ secrets.ELASTICSEARCHENDPOINT }} - ELASTICSEARCH_INDEX: ${{ secrets.ELASTICSEARCHINDEX }} - ELASTICSEARCH_QUERY: ${{ secrets.ELASTICSEARCHQUERY }} - run: | - export PYTHONPATH=$(pwd) - coverage run -m pytest -v --show-capture=stdout - coverage report -m --include=app.py,backend/*,tests/* - coverage xml - - - name: Code Coverage Report - uses: irongut/CodeCoverageSummary@v1.3.0 - with: - filename: coverage.xml - badge: true - fail_below_min: true - format: markdown - hide_branch_rate: false - hide_complexity: true - indicators: true - output: both - thresholds: '50 80' - - deploy: - runs-on: ubuntu-latest - needs: [test_windows, test_linux] + - uses: actions/checkout@v3 + - name: Set up Python 3.11 + uses: actions/setup-python@v3 + with: + python-version: "3.11" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements-dev.txt + - name: Test with pytest + env: + AZURE_OPENAI_ENDPOINT: ${{ secrets.AZUREOPENAIENDPOINT }} + AZURE_OPENAI_MODEL: ${{ secrets.AZUREOPENAIMODEL }} + AZURE_OPENAI_KEY: ${{ secrets.AZUREOPENAIKEY }} + AZURE_OPENAI_EMBEDDING_NAME: ${{ secrets.AZUREOPENAIEMBEDDINGNAME }} + AZURE_COSMOSDB_ACCOUNT: ${{ secrets.AZURECOSMOSDBACCOUNT }} + AZURE_COSMOSDB_DATABASE: ${{ secrets.AZURECOSMOSDBDATABASE }} + AZURE_COSMOSDB_CONVERSATIONS_CONTAINER: ${{ secrets.AZURECOSMOSDBCONVERSATIONSCONTAINER }} + AZURE_COSMOSDB_ACCOUNT_KEY: ${{ secrets.AZURECOSMOSDBACCOUNTKEY }} + AZURE_SEARCH_SERVICE: ${{ secrets.AZURESEARCHSERVICE }} + AZURE_SEARCH_INDEX: ${{ secrets.AZURESEARCHINDEX }} + AZURE_SEARCH_KEY: ${{ secrets.AZURESEARCHKEY }} + AZURE_SEARCH_QUERY: ${{ secrets.AZURESEARCHQUERY }} + ELASTICSEARCH_EMBEDDING_MODEL_ID: ${{ secrets.ELASTICSEARCHEMBEDDINGMODELID }} + ELASTICSEARCH_ENCODED_API_KEY: ${{ secrets.ELASTICSEARCHENCODEDAPIKEY }} + ELASTICSEARCH_ENDPOINT: ${{ secrets.ELASTICSEARCHENDPOINT }} + ELASTICSEARCH_INDEX: ${{ secrets.ELASTICSEARCHINDEX }} + ELASTICSEARCH_QUERY: ${{ secrets.ELASTICSEARCHQUERY }} + run: | + export PYTHONPATH=$(pwd) + coverage run -m pytest -v --show-capture=stdout + coverage report -m --include=app.py,backend/*,tests/* + coverage xml + + - name: Code Coverage Report + uses: irongut/CodeCoverageSummary@v1.3.0 + with: + filename: coverage.xml + badge: true + fail_below_min: true + format: markdown + hide_branch_rate: false + hide_complexity: true + indicators: true + output: both + thresholds: '50 80' + test_windows: + runs-on: + - windows-latest steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Download artifact from build job - uses: actions/download-artifact@v3 - with: - name: python-app - - - name: Unzip artifact for deployment - run: unzip release.zip - - - name: Login to Azure - uses: azure/login@v1 - with: - client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID }} - tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID }} - subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID }} - - - name: 'Deploy to Azure Web App' - uses: azure/webapps-deploy@v2 - id: deploy-to-webapp - with: - app-name: 'sample-app-github-cd' - slot-name: 'Production' + - uses: actions/checkout@v3 + - name: Set up Python 3.11 + uses: actions/setup-python@v3 + with: + python-version: "3.11" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements-dev.txt + - name: Test with pytest + run: | + $env:PYTHONPATH=$pwd + pytest -v --show-capture=stdout -k "not integration" From cd305c40565d5cb818f6815fb8ca089663522ca9 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 18:52:43 -0400 Subject: [PATCH 56/63] Try --- .github/workflows/python-app.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index a0d1197207..e84aae3a5f 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -22,6 +22,12 @@ jobs: uses: actions/setup-python@v3 with: python-version: "3.11" + + - name: Create and start virtual environment + run: | + python -m venv venv + source venv/bin/activate + - name: Install dependencies run: | python -m pip install --upgrade pip @@ -32,6 +38,7 @@ jobs: AZURE_OPENAI_MODEL: ${{ secrets.AZUREOPENAIMODEL }} AZURE_OPENAI_KEY: ${{ secrets.AZUREOPENAIKEY }} AZURE_OPENAI_EMBEDDING_NAME: ${{ secrets.AZUREOPENAIEMBEDDINGNAME }} + AZURE_OPENAI_TEMPERATURE: ${{ secrets.AZUREOPENAITEMPERATURE }} AZURE_COSMOSDB_ACCOUNT: ${{ secrets.AZURECOSMOSDBACCOUNT }} AZURE_COSMOSDB_DATABASE: ${{ secrets.AZURECOSMOSDBDATABASE }} AZURE_COSMOSDB_CONVERSATIONS_CONTAINER: ${{ secrets.AZURECOSMOSDBCONVERSATIONSCONTAINER }} @@ -73,6 +80,12 @@ jobs: uses: actions/setup-python@v3 with: python-version: "3.11" + + - name: Create and start virtual environment + run: | + python -m venv venv + venv\Scripts\Activate + - name: Install dependencies run: | python -m pip install --upgrade pip From 07065992e2922c3181d246a5818f82b8c7c5383e Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 18:59:06 -0400 Subject: [PATCH 57/63] Try --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index e84aae3a5f..fd54ff5edd 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -38,7 +38,7 @@ jobs: AZURE_OPENAI_MODEL: ${{ secrets.AZUREOPENAIMODEL }} AZURE_OPENAI_KEY: ${{ secrets.AZUREOPENAIKEY }} AZURE_OPENAI_EMBEDDING_NAME: ${{ secrets.AZUREOPENAIEMBEDDINGNAME }} - AZURE_OPENAI_TEMPERATURE: ${{ secrets.AZUREOPENAITEMPERATURE }} + AZURE_OPENAI_TEMPERATURE: 0 AZURE_COSMOSDB_ACCOUNT: ${{ secrets.AZURECOSMOSDBACCOUNT }} AZURE_COSMOSDB_DATABASE: ${{ secrets.AZURECOSMOSDBDATABASE }} AZURE_COSMOSDB_CONVERSATIONS_CONTAINER: ${{ secrets.AZURECOSMOSDBCONVERSATIONSCONTAINER }} From c47fff20e9c45cff47c800caf96b743ff4d8f627 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 19:14:26 -0400 Subject: [PATCH 58/63] Try again --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index fd54ff5edd..e84aae3a5f 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -38,7 +38,7 @@ jobs: AZURE_OPENAI_MODEL: ${{ secrets.AZUREOPENAIMODEL }} AZURE_OPENAI_KEY: ${{ secrets.AZUREOPENAIKEY }} AZURE_OPENAI_EMBEDDING_NAME: ${{ secrets.AZUREOPENAIEMBEDDINGNAME }} - AZURE_OPENAI_TEMPERATURE: 0 + AZURE_OPENAI_TEMPERATURE: ${{ secrets.AZUREOPENAITEMPERATURE }} AZURE_COSMOSDB_ACCOUNT: ${{ secrets.AZURECOSMOSDBACCOUNT }} AZURE_COSMOSDB_DATABASE: ${{ secrets.AZURECOSMOSDBDATABASE }} AZURE_COSMOSDB_CONVERSATIONS_CONTAINER: ${{ secrets.AZURECOSMOSDBCONVERSATIONSCONTAINER }} From cc263cfd4238397c1484c8220ac323e1ec0878ca Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 19:20:40 -0400 Subject: [PATCH 59/63] Try again --- .github/workflows/python-app.yml | 96 -------------------------------- 1 file changed, 96 deletions(-) delete mode 100644 .github/workflows/python-app.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml deleted file mode 100644 index e84aae3a5f..0000000000 --- a/.github/workflows/python-app.yml +++ /dev/null @@ -1,96 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python - -name: Python application - -on: - push: - branches: [ "main", "AddQueryStringForInitialPrompting" ] - pull_request: - branches: [ "main", "AddQueryStringForInitialPrompting" ] - -permissions: - contents: read - -jobs: - test_linux: - runs-on: - - ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Set up Python 3.11 - uses: actions/setup-python@v3 - with: - python-version: "3.11" - - - name: Create and start virtual environment - run: | - python -m venv venv - source venv/bin/activate - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements-dev.txt - - name: Test with pytest - env: - AZURE_OPENAI_ENDPOINT: ${{ secrets.AZUREOPENAIENDPOINT }} - AZURE_OPENAI_MODEL: ${{ secrets.AZUREOPENAIMODEL }} - AZURE_OPENAI_KEY: ${{ secrets.AZUREOPENAIKEY }} - AZURE_OPENAI_EMBEDDING_NAME: ${{ secrets.AZUREOPENAIEMBEDDINGNAME }} - AZURE_OPENAI_TEMPERATURE: ${{ secrets.AZUREOPENAITEMPERATURE }} - AZURE_COSMOSDB_ACCOUNT: ${{ secrets.AZURECOSMOSDBACCOUNT }} - AZURE_COSMOSDB_DATABASE: ${{ secrets.AZURECOSMOSDBDATABASE }} - AZURE_COSMOSDB_CONVERSATIONS_CONTAINER: ${{ secrets.AZURECOSMOSDBCONVERSATIONSCONTAINER }} - AZURE_COSMOSDB_ACCOUNT_KEY: ${{ secrets.AZURECOSMOSDBACCOUNTKEY }} - AZURE_SEARCH_SERVICE: ${{ secrets.AZURESEARCHSERVICE }} - AZURE_SEARCH_INDEX: ${{ secrets.AZURESEARCHINDEX }} - AZURE_SEARCH_KEY: ${{ secrets.AZURESEARCHKEY }} - AZURE_SEARCH_QUERY: ${{ secrets.AZURESEARCHQUERY }} - ELASTICSEARCH_EMBEDDING_MODEL_ID: ${{ secrets.ELASTICSEARCHEMBEDDINGMODELID }} - ELASTICSEARCH_ENCODED_API_KEY: ${{ secrets.ELASTICSEARCHENCODEDAPIKEY }} - ELASTICSEARCH_ENDPOINT: ${{ secrets.ELASTICSEARCHENDPOINT }} - ELASTICSEARCH_INDEX: ${{ secrets.ELASTICSEARCHINDEX }} - ELASTICSEARCH_QUERY: ${{ secrets.ELASTICSEARCHQUERY }} - run: | - export PYTHONPATH=$(pwd) - coverage run -m pytest -v --show-capture=stdout - coverage report -m --include=app.py,backend/*,tests/* - coverage xml - - - name: Code Coverage Report - uses: irongut/CodeCoverageSummary@v1.3.0 - with: - filename: coverage.xml - badge: true - fail_below_min: true - format: markdown - hide_branch_rate: false - hide_complexity: true - indicators: true - output: both - thresholds: '50 80' - - test_windows: - runs-on: - - windows-latest - steps: - - uses: actions/checkout@v3 - - name: Set up Python 3.11 - uses: actions/setup-python@v3 - with: - python-version: "3.11" - - - name: Create and start virtual environment - run: | - python -m venv venv - venv\Scripts\Activate - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements-dev.txt - - name: Test with pytest - run: | - $env:PYTHONPATH=$pwd - pytest -v --show-capture=stdout -k "not integration" From 6a43c28b431b584b9b428291c5e01d7721056bba Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 19:27:30 -0400 Subject: [PATCH 60/63] Fix --- .github/workflows/sample-app-github-cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sample-app-github-cd.yml b/.github/workflows/sample-app-github-cd.yml index 149f127afc..863ef80083 100644 --- a/.github/workflows/sample-app-github-cd.yml +++ b/.github/workflows/sample-app-github-cd.yml @@ -46,7 +46,7 @@ jobs: deploy: runs-on: ubuntu-latest needs: build - if: github.ref == 'refs/heads/main' # Only run on main branch + environment: name: 'Production' url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} From 085d0b032d7385ed364d1a9b5f2aa77311f1ef1a Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 19:37:13 -0400 Subject: [PATCH 61/63] Dramatic test --- frontend/src/pages/chat/Chat.tsx | 288 +------------------------------ 1 file changed, 1 insertion(+), 287 deletions(-) diff --git a/frontend/src/pages/chat/Chat.tsx b/frontend/src/pages/chat/Chat.tsx index 2f2d7e7739..8a454c4bc0 100644 --- a/frontend/src/pages/chat/Chat.tsx +++ b/frontend/src/pages/chat/Chat.tsx @@ -768,293 +768,7 @@ const Chat = () => { return (
- {showAuthMessage ? ( - - -

Authentication Not Configured

-

- This app does not have authentication configured. Please add an identity provider by finding your app in the{' '} - - Azure Portal - - and following{' '} - - these instructions - - . -

-

- Authentication configuration takes a few minutes to apply. -

-

- If you deployed in the last 10 minutes, please wait and reload the page after 10 minutes. -

-
- ) : ( - -
- {!messages || messages.length < 1 ? ( - - -

{ui?.chat_title}

-

{ui?.chat_description}

-
- ) : ( -
- {messages.map((answer, index) => ( - <> - {answer.role === 'user' ? ( -
-
{answer.content}
-
- ) : answer.role === 'assistant' ? ( -
- onShowCitation(c)} - onExectResultClicked={() => onShowExecResult()} - /> -
- ) : answer.role === ERROR ? ( -
- - - Error - - {answer.content} -
- ) : null} - - ))} - {showLoadingMessage && ( - <> -
- null} - onExectResultClicked={() => null} - /> -
- - )} -
-
- )} - - - {isLoading && messages.length > 0 && ( - (e.key === 'Enter' || e.key === ' ' ? stopGenerating() : null)}> - - )} - - {appStateContext?.state.isCosmosDBAvailable?.status !== CosmosDBStatus.NotConfigured && ( - - )} - - - - { - appStateContext?.state.isCosmosDBAvailable?.cosmosDB - ? makeApiRequestWithCosmosDB(question, id) - : makeApiRequestWithoutCosmosDB(question, id) - }} - conversationId={ - appStateContext?.state.currentChat?.id ? appStateContext?.state.currentChat?.id : undefined - } - /> - -
- {/* Citation Panel */} - {messages && messages.length > 0 && isCitationPanelOpen && activeCitation && ( - - - - Citations - - setIsCitationPanelOpen(false)} - /> - -
onViewSource(activeCitation)}> - {activeCitation.title} -
-
- -
-
- )} - {messages && messages.length > 0 && isIntentsPanelOpen && ( - - - - Intents - - setIsIntentsPanelOpen(false)} - /> - - - {execResults.map((execResult) => { - return ( - - <>Intent:

{execResult.intent}

- {execResult.search_query && <>Search Query: - - {execResult.search_query} - } - {execResult.search_result && <>Search Result:

{execResult.search_result}

} - {execResult.code_generated && <>Code Generated: - - {execResult.code_generated} - - } -
- ) - })} -
-
- )} - {appStateContext?.state.isChatHistoryOpen && - appStateContext?.state.isCosmosDBAvailable?.status !== CosmosDBStatus.NotConfigured && } - - )} - + This is a test.
) } From 9096434c2b77cb41e7152d0ed5fe4c1103de1e01 Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 20:06:55 -0400 Subject: [PATCH 62/63] Try --- .github/workflows/python-app.yml | 83 ++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 .github/workflows/python-app.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000000..3ae34e3aa7 --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,83 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python application + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + test_linux: + runs-on: + - ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.11 + uses: actions/setup-python@v3 + with: + python-version: "3.11" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements-dev.txt + - name: Test with pytest + env: + AZURE_OPENAI_ENDPOINT: ${{ secrets.AZUREOPENAIENDPOINT }} + AZURE_OPENAI_MODEL: ${{ secrets.AZUREOPENAIMODEL }} + AZURE_OPENAI_KEY: ${{ secrets.AZUREOPENAIKEY }} + AZURE_OPENAI_EMBEDDING_NAME: ${{ secrets.AZUREOPENAIEMBEDDINGNAME }} + AZURE_COSMOSDB_ACCOUNT: ${{ secrets.AZURECOSMOSDBACCOUNT }} + AZURE_COSMOSDB_DATABASE: ${{ secrets.AZURECOSMOSDBDATABASE }} + AZURE_COSMOSDB_CONVERSATIONS_CONTAINER: ${{ secrets.AZURECOSMOSDBCONVERSATIONSCONTAINER }} + AZURE_COSMOSDB_ACCOUNT_KEY: ${{ secrets.AZURECOSMOSDBACCOUNTKEY }} + AZURE_SEARCH_SERVICE: ${{ secrets.AZURESEARCHSERVICE }} + AZURE_SEARCH_INDEX: ${{ secrets.AZURESEARCHINDEX }} + AZURE_SEARCH_KEY: ${{ secrets.AZURESEARCHKEY }} + AZURE_SEARCH_QUERY: ${{ secrets.AZURESEARCHQUERY }} + ELASTICSEARCH_EMBEDDING_MODEL_ID: ${{ secrets.ELASTICSEARCHEMBEDDINGMODELID }} + ELASTICSEARCH_ENCODED_API_KEY: ${{ secrets.ELASTICSEARCHENCODEDAPIKEY }} + ELASTICSEARCH_ENDPOINT: ${{ secrets.ELASTICSEARCHENDPOINT }} + ELASTICSEARCH_INDEX: ${{ secrets.ELASTICSEARCHINDEX }} + ELASTICSEARCH_QUERY: ${{ secrets.ELASTICSEARCHQUERY }} + run: | + export PYTHONPATH=$(pwd) + coverage run -m pytest -v --show-capture=stdout + coverage report -m --include=app.py,backend/*,tests/* + coverage xml + + - name: Code Coverage Report + uses: irongut/CodeCoverageSummary@v1.3.0 + with: + filename: coverage.xml + badge: true + fail_below_min: true + format: markdown + hide_branch_rate: false + hide_complexity: true + indicators: true + output: both + thresholds: '50 80' + + test_windows: + runs-on: + - windows-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.11 + uses: actions/setup-python@v3 + with: + python-version: "3.11" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements-dev.txt + - name: Test with pytest + run: | + $env:PYTHONPATH=$pwd + pytest -v --show-capture=stdout -k "not integration" \ No newline at end of file From 91fdedc7a5c3af13ba617ae142880f57b85f222c Mon Sep 17 00:00:00 2001 From: Jon Burchel Date: Mon, 22 Jul 2024 20:16:31 -0400 Subject: [PATCH 63/63] Remove tests again --- .github/workflows/python-app.yml | 83 -------------------------------- 1 file changed, 83 deletions(-) delete mode 100644 .github/workflows/python-app.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml deleted file mode 100644 index 3ae34e3aa7..0000000000 --- a/.github/workflows/python-app.yml +++ /dev/null @@ -1,83 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python - -name: Python application - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -permissions: - contents: read - -jobs: - test_linux: - runs-on: - - ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Set up Python 3.11 - uses: actions/setup-python@v3 - with: - python-version: "3.11" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements-dev.txt - - name: Test with pytest - env: - AZURE_OPENAI_ENDPOINT: ${{ secrets.AZUREOPENAIENDPOINT }} - AZURE_OPENAI_MODEL: ${{ secrets.AZUREOPENAIMODEL }} - AZURE_OPENAI_KEY: ${{ secrets.AZUREOPENAIKEY }} - AZURE_OPENAI_EMBEDDING_NAME: ${{ secrets.AZUREOPENAIEMBEDDINGNAME }} - AZURE_COSMOSDB_ACCOUNT: ${{ secrets.AZURECOSMOSDBACCOUNT }} - AZURE_COSMOSDB_DATABASE: ${{ secrets.AZURECOSMOSDBDATABASE }} - AZURE_COSMOSDB_CONVERSATIONS_CONTAINER: ${{ secrets.AZURECOSMOSDBCONVERSATIONSCONTAINER }} - AZURE_COSMOSDB_ACCOUNT_KEY: ${{ secrets.AZURECOSMOSDBACCOUNTKEY }} - AZURE_SEARCH_SERVICE: ${{ secrets.AZURESEARCHSERVICE }} - AZURE_SEARCH_INDEX: ${{ secrets.AZURESEARCHINDEX }} - AZURE_SEARCH_KEY: ${{ secrets.AZURESEARCHKEY }} - AZURE_SEARCH_QUERY: ${{ secrets.AZURESEARCHQUERY }} - ELASTICSEARCH_EMBEDDING_MODEL_ID: ${{ secrets.ELASTICSEARCHEMBEDDINGMODELID }} - ELASTICSEARCH_ENCODED_API_KEY: ${{ secrets.ELASTICSEARCHENCODEDAPIKEY }} - ELASTICSEARCH_ENDPOINT: ${{ secrets.ELASTICSEARCHENDPOINT }} - ELASTICSEARCH_INDEX: ${{ secrets.ELASTICSEARCHINDEX }} - ELASTICSEARCH_QUERY: ${{ secrets.ELASTICSEARCHQUERY }} - run: | - export PYTHONPATH=$(pwd) - coverage run -m pytest -v --show-capture=stdout - coverage report -m --include=app.py,backend/*,tests/* - coverage xml - - - name: Code Coverage Report - uses: irongut/CodeCoverageSummary@v1.3.0 - with: - filename: coverage.xml - badge: true - fail_below_min: true - format: markdown - hide_branch_rate: false - hide_complexity: true - indicators: true - output: both - thresholds: '50 80' - - test_windows: - runs-on: - - windows-latest - steps: - - uses: actions/checkout@v3 - - name: Set up Python 3.11 - uses: actions/setup-python@v3 - with: - python-version: "3.11" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements-dev.txt - - name: Test with pytest - run: | - $env:PYTHONPATH=$pwd - pytest -v --show-capture=stdout -k "not integration" \ No newline at end of file