From bd963df502987ccfde7220ce19e97a20da0853a5 Mon Sep 17 00:00:00 2001 From: Ayyub I Date: Tue, 14 Nov 2023 22:31:33 -0600 Subject: [PATCH] modified names of citation keys before updating supabase --- .../googlecloud/functions/getanswer/main.py | 11 +++++++++- packages/web/components/NewQuery.tsx | 20 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/googlecloud/functions/getanswer/main.py b/packages/googlecloud/functions/getanswer/main.py index 4cf7041a..324f377b 100644 --- a/packages/googlecloud/functions/getanswer/main.py +++ b/packages/googlecloud/functions/getanswer/main.py @@ -25,9 +25,18 @@ def update_supabase(responses, citations, card_id): + transformed_citations = [] + for citation in citations: + transformed_citations.append({ + "source_title": citation.get("Title"), + "source_name": citation.get("Name"), + "source_publish_date": citation.get("Published"), + "source_url": citation.get("URL") + }) + try: supabase.table("cards").update( - {"responses": responses, "citations": citations} + {"responses": responses, "citations": transformed_citations} ).eq("id", card_id).execute() logging.info("Data successfully updated in Supabase") except Exception as e: diff --git a/packages/web/components/NewQuery.tsx b/packages/web/components/NewQuery.tsx index 99adb185..dd37eef4 100644 --- a/packages/web/components/NewQuery.tsx +++ b/packages/web/components/NewQuery.tsx @@ -61,6 +61,21 @@ export default function NewQuery() { } }; + const fetchUpdatedCard = async (cardId: string) => { + const { data, error } = await supabase + .from('cards') + .select('*') + .eq('id', cardId) + .single(); + + if (error) { + console.error('Error fetching updated card:', error); + } else if (data) { + setCard(data); + } +}; + + const sendQueryToFunction = async (newCard: ICard) => { // Start processing question const answerResp = await fetch(apiEndpoint, { @@ -91,6 +106,11 @@ export default function NewQuery() { card = card as ICard; setQuery(""); setIsProcessing(false); + if (newCard.id) { + await fetchUpdatedCard(newCard.id); + } else { + console.error('Card ID is undefined'); + } }; useEffect(() => {